SGGL_SHJ/SGGL/BLL/HJGL/PreDesign/ProductionSchedulingPlanSer...

127 lines
5.8 KiB
C#
Raw Normal View History

2025-06-04 22:46:21 +08:00
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
/// <summary>
/// 排产计划
/// </summary>
public class ProductionSchedulingPlanService
{
/// <summary>
/// 根据主键获取排产计划
/// </summary>
/// <param name="productionSchedulingPlanId"></param>
/// <returns></returns>
public static Model.HJGL_ProductionSchedulingPlan GetProductionSchedulingPlanById(string productionSchedulingPlanId)
{
return Funs.DB.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProductionSchedulingPlanId == productionSchedulingPlanId);
}
2025-06-09 17:20:34 +08:00
public static Model.HJGL_ProductionSchedulingPlan GetProductionSchedulingPlan(string loginProjectId, string flowingSection, string unitWorkId, string material, string caliber)
2025-06-04 22:46:21 +08:00
{
2025-06-09 17:20:34 +08:00
return Funs.DB.HJGL_ProductionSchedulingPlan.FirstOrDefault(e => e.ProjectId == loginProjectId && e.FlowNum == flowingSection && e.PipelineId == unitWorkId && e.Caliber == caliber);
2025-06-04 22:46:21 +08:00
}
2025-06-09 17:20:34 +08:00
/// <summary>
/// 增加排产计划
/// </summary>
/// <param name="plan"></param>
public static void AddProductionSchedulingPlan(Model.HJGL_ProductionSchedulingPlan plan)
2025-06-04 22:46:21 +08:00
{
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;
2025-06-09 17:20:34 +08:00
newPlan.CompletedCount = plan.CompletedCount;
newPlan.CompletedRate = plan.CompletedRate;
newPlan.TotalCompletedRate = plan.TotalCompletedRate;
2025-06-04 22:46:21 +08:00
db.HJGL_ProductionSchedulingPlan.InsertOnSubmit(newPlan);
db.SubmitChanges();
}
/// <summary>
/// 修改排产计划
/// </summary>
/// <param name="plan"></param>
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;
2025-06-09 17:20:34 +08:00
newPlan.CompletedCount = plan.CompletedCount;
newPlan.CompletedRate = plan.CompletedRate;
newPlan.TotalCompletedRate = plan.TotalCompletedRate;
2025-06-04 22:46:21 +08:00
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();
}
}
}
/// <summary>
/// 根据主键删除排产计划
/// </summary>
/// <param name="productionSchedulingPlanId"></param>
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();
}
}
}
}