using Model;
using System.Collections.Generic;
using System.Linq;
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 unitWorkId, string material, string caliber)
{
return Funs.DB.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProjectId == loginProjectId && e.FlowNum == flowingSection && e.PipelineId == unitWorkId && e.Material == material && e.Caliber == caliber);
}
///
/// 根据单位工程、流水段获取排产计划信息
///
///
///
///
///
public static List GetProductionSchedulingPlanByFlowingSection(string loginProjectId, string flowingSection, string unitWorkId)
{
return (from x in Funs.DB.HJGL_ProductionSchedulingPlan where x.ProjectId == loginProjectId && x.FlowNum == flowingSection && x.PipelineId == unitWorkId select x).ToList();
}
///
/// 根据单位工程获取排产计划信息
///
///
///
///
public static List GetProductionSchedulingPlanByUnitWorkId(string loginProjectId, string unitWorkId)
{
return (from x in Funs.DB.HJGL_ProductionSchedulingPlan where x.ProjectId == loginProjectId && x.PipelineId == unitWorkId select x).ToList();
}
///
/// 增加排产计划
///
///
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;
newPlan.CompletedCount = plan.CompletedCount;
newPlan.CompletedRate = plan.CompletedRate;
newPlan.TotalCompletedRate = plan.TotalCompletedRate;
newPlan.OnDayCompleteDyne = plan.OnDayCompleteDyne;
newPlan.NextDayCompleteDyne = plan.NextDayCompleteDyne;
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;
newPlan.CompletedCount = plan.CompletedCount;
newPlan.CompletedRate = plan.CompletedRate;
newPlan.TotalCompletedRate = plan.TotalCompletedRate;
newPlan.OnDayCompleteDyne = plan.OnDayCompleteDyne;
newPlan.NextDayCompleteDyne = plan.NextDayCompleteDyne;
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();
}
}
///
/// 根据单位工程删除排产计划
///
///
///
public static void DeleteProductionSchedulingPlanByUnitWork(string projectId, string unitWorkName)
{
SGGLDB db = Funs.DB;
var q = (from x in db.HJGL_ProductionSchedulingPlan where x.ProjectId == projectId && x.MainItemName == unitWorkName select x).ToList();
if (q.Count > 0)
{
db.HJGL_ProductionSchedulingPlan.DeleteAllOnSubmit(q);
db.SubmitChanges();
}
}
///
/// 根据单位工程、流水号删除排产计划
///
///
///
///
public static void DeleteProductionSchedulingPlanByUnitWorkIdAndFlowNum(string projectId, string unitWorkName, string flowNum)
{
SGGLDB db = Funs.DB;
var q = (from x in db.HJGL_ProductionSchedulingPlan where x.ProjectId == projectId && x.MainItemName == unitWorkName && x.FlowNum == flowNum select x).ToList();
if (q.Count > 0)
{
db.HJGL_ProductionSchedulingPlan.DeleteAllOnSubmit(q);
db.SubmitChanges();
}
}
}
}