using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
///
/// 排产计划
///
public class ProductionSchedulingPlanService
{
///
/// 根据主键获取排产计划
///
///
///
public static Model.HJGL_ProductionSchedulingPlan GetProductionSchedulingPlanById(string productionSchedulingPlanId)
{
return Funs.DB.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProductionSchedulingPlanId == productionSchedulingPlanId);
}
public static Model.HJGL_ProductionSchedulingPlan GetProductionSchedulingPlan(string loginProjectId, string flowingSection, string unitWorkName, string material, string caliber)
{
return Funs.DB.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProjectId == loginProjectId && e.FlowNum == flowingSection && e.MainItemName == unitWorkName && e.Caliber == caliber);
}
///
/// 增加排产计划
///
///
public static void AddProductionSchedulingPlan(Model.HJGL_ProductionSchedulingPlan plan)
{
SGGLDB db = Funs.DB;
Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan();
newPlan.ProductionSchedulingPlanId = plan.ProductionSchedulingPlanId;
newPlan.ProjectId = plan.ProjectId;
newPlan.PipelineId = plan.PipelineId;
newPlan.FlowNum = plan.FlowNum;
newPlan.MainItemName = plan.MainItemName;
newPlan.Material = plan.Material;
newPlan.Caliber = plan.Caliber;
newPlan.Dain = plan.Dain;
newPlan.TotalDyne = plan.TotalDyne;
newPlan.TotalPriority = plan.TotalPriority;
newPlan.PriorityTotalDyne = plan.PriorityTotalDyne;
newPlan.PlanStartDate = plan.PlanStartDate;
newPlan.PlanEndDate = plan.PlanEndDate;
newPlan.Days = plan.Days;
newPlan.AvgDailyWorkload = plan.Days;
db.HJGL_ProductionSchedulingPlan.InsertOnSubmit(newPlan);
db.SubmitChanges();
}
///
/// 修改排产计划
///
///
public static void UpdateProductionSchedulingPlan(Model.HJGL_ProductionSchedulingPlan plan)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_ProductionSchedulingPlan newPlan = db.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProductionSchedulingPlanId == plan.ProductionSchedulingPlanId);
if (newPlan != null)
{
newPlan.PipelineId = plan.PipelineId;
newPlan.FlowNum = plan.FlowNum;
newPlan.MainItemName = plan.MainItemName;
newPlan.Material = plan.Material;
newPlan.Caliber = plan.Caliber;
newPlan.Dain = plan.Dain;
newPlan.TotalDyne = plan.TotalDyne;
newPlan.TotalPriority = plan.TotalPriority;
newPlan.PriorityTotalDyne = plan.PriorityTotalDyne;
newPlan.PlanStartDate = plan.PlanStartDate;
newPlan.PlanEndDate = plan.PlanEndDate;
newPlan.Days = plan.Days;
newPlan.AvgDailyWorkload = plan.AvgDailyWorkload;
try
{
db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
}
catch (System.Data.Linq.ChangeConflictException ex)
{
foreach (System.Data.Linq.ObjectChangeConflict occ in db.ChangeConflicts)
{
//以下是解决冲突的三种方法,选一种即可
// 使用当前数据库中的值,覆盖Linq缓存中实体对象的值
occ.Resolve(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
// 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
// 只更新实体对象中改变的字段的值,其他的保留不变
occ.Resolve(System.Data.Linq.RefreshMode.KeepChanges);
}
// 这个地方要注意,Catch方法中,我们前面只是指明了怎样来解决冲突,这个地方还需要再次提交更新,这样的话,值 //才会提交到数据库。
db.SubmitChanges();
}
}
}
///
/// 根据主键删除排产计划
///
///
public static void DeleteProductionSchedulingPlanById(string productionSchedulingPlanId)
{
SGGLDB db = Funs.DB;
Model.HJGL_ProductionSchedulingPlan plan = db.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProductionSchedulingPlanId == productionSchedulingPlanId);
if (plan != null)
{
db.HJGL_ProductionSchedulingPlan.DeleteOnSubmit(plan);
db.SubmitChanges();
}
}
}
}