using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI.WebControls; using Model; using NPOI.SS.Formula.Functions; namespace BLL { public class HJGL_PipelineComponentService { /// /// 待整改 /// public static int StatePenRec = -2; /// /// 已整改 /// public static int StateRec = -1; /// /// 未验收 /// public static int State0 = 0; /// /// 已验收 /// public static int State1 = 1; /// /// 已装箱 /// public static int State2 = 2; /// /// 获取状态名称 /// /// public static ListItem[] GetState() { ListItem[] list = new ListItem[5]; list[0] = new ListItem("未验收", State0.ToString()); list[1] = new ListItem("已验收", State1.ToString()); list[2] = new ListItem("已出库", State2.ToString()); list[3] = new ListItem("待整改", StatePenRec.ToString()); list[4] = new ListItem("已整改", StateRec.ToString()); return list; } /// /// 生产状态 /// /// public static ListItem[] GetProductionState() { ListItem[] list = new ListItem[3]; list[0] = new ListItem("未开始", "0"); list[1] = new ListItem("已开始", "1"); list[2] = new ListItem("已完成", "2"); return list; } /// /// 根据ID获取组件信息 /// /// /// public static Model.HJGL_Pipeline_Component GetPipelineComponentById(string pipelineComponentId) { return Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipelineComponentId); } public static Model.HJGL_Pipeline_Component GetPipelineComponentByCodeandpipelineId(string pipelineComponentCode, string pipelineId) { var q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId); return q; } /// /// 根据材料信息id获取组件信息 /// /// /// public static Model.HJGL_Pipeline_Component GetPipelineComponentByMatId(string pipeLineMatId) { return Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipeLineMatId == pipeLineMatId); } /// /// 获取打印实体 /// /// /// /// /// public static IEnumerable GetPrintModelByPipelineComponentIds( string[] PipelineComponentId, string[] PipelineId, bool IsCheckPrint) { var db = Funs.DB; var query = from com in db.HJGL_Pipeline_Component join mat in db.HJGL_PipeLineMat on com.PipeLineMatId equals mat.PipeLineMatId into matJoin from mat in matJoin.DefaultIfEmpty() join pipe in db.HJGL_Pipeline on com.PipelineId equals pipe.PipelineId into pipeJoin from pipe in pipeJoin.DefaultIfEmpty() join punit in db.Base_Unit on com.PreUnit equals punit.UnitId into punitJoin from punit in punitJoin.DefaultIfEmpty() join aunit in db.Base_Unit on com.AssembleUnit equals aunit.UnitId into aunitJoin from aunit in aunitJoin.DefaultIfEmpty() join unitwork in db.WBS_UnitWork on pipe.UnitWorkId equals unitwork.UnitWorkId into unitworkJoin from unitwork in unitworkJoin.DefaultIfEmpty() join mater in db.Base_Material on pipe.MaterialId equals mater.MaterialId into materJoin from mater in materJoin.DefaultIfEmpty() where com.QRCode != "" orderby com.PipelineComponentCode,com.PipelineId select new PipelineComponentPrintDto { PipelineComponentId = com.PipelineComponentId, PipelineComponentCode = com.PipelineComponentCode, BoxNumber = com.BoxNumber, UnitWorkName = unitwork.UnitWorkName, PipelineId = com.PipelineId, PreUnit = punit.UnitName, AssembleUnit = aunit.UnitName, PrefabricatedComponents = mat.PrefabricatedComponents, QRCode = com.QRCode, State = com.State, PlanStartDate = string.Format("yyyy-MM-dd", pipe.PlanStartDate), PipelineCode = pipe.PipelineCode, FlowingSection = pipe.FlowingSection, QRCode2 = "PrePipeline$" + com.PipelineComponentId, MaterialCode = mater.MaterialCode, IsPrint = com.IsPrint }; var result = query.ToList(); if (PipelineComponentId!=null &&PipelineComponentId.Length > 0) { result = result.Where(x => PipelineComponentId.Contains(x.PipelineComponentId.ToString())).ToList(); } if (PipelineId != null && PipelineId.Length > 0) { result = result.Where(x => PipelineId.Contains(x.PipelineId.ToString())).ToList(); } //if (IsCheckPrint != null & IsCheckPrint ==true) //{ // result = result.Where(x => x.IsPrint==false||x.IsPrint==null).ToList(); //} return result; } /// /// 判断管线组件Code是否存在 /// /// /// /// public static bool IsExistPipelineComponentCode(string pipelineComponentCode, string pipelineId, string pipelineComponentId) { Model.SGGLDB db = Funs.DB; Model.HJGL_Pipeline_Component q = null; if (!string.IsNullOrEmpty(pipelineComponentId)) { q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId && x.PipelineComponentId != pipelineComponentId); } else { q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId); } if (q != null) { return true; } else { return false; } } /// /// 根据管线材料id同步组件 /// public static void SyncPipelineComponentByMatId(string pipeLineMatId) { var model_mat = BLL.PipelineMatService.GetPipeLineMat(pipeLineMatId); var PipelineId = model_mat.PipelineId; var PipeArea = BLL.PipelineService.GetPipelineByPipelineId(PipelineId).PipeArea; if (PipeArea=="1" &&!string.IsNullOrEmpty(model_mat.PrefabricatedComponents)) { // var model = GetPipelineComponentByMatId(pipeLineMatId); var model = GetPipelineComponentByCodeandpipelineId(model_mat.PrefabricatedComponents,PipelineId); if (model!=null) { model.PipelineId = PipelineId; model.PipelineComponentCode = model_mat.PrefabricatedComponents; model.DrawingName = model_mat.PrefabricatedComponents.Substring(0, model_mat.PrefabricatedComponents.LastIndexOf('-')).Replace("\"", ""); model.State = State0; model.ProductionState = 0; UpdatePipelineComponent(model); } else { model=new Model.HJGL_Pipeline_Component(); model.PipelineComponentId = SQLHelper.GetNewID(); model.PipelineId = PipelineId; model.PipelineComponentCode = model_mat.PrefabricatedComponents; model.DrawingName = model_mat.PrefabricatedComponents?.Substring(0, model_mat.PrefabricatedComponents.LastIndexOf('-')).Replace("\"", ""); model.State = State0; model.ProductionState = 0; model.IsPrint = false; AddPipelineComponent(model); } } } /// /// 添加作业管线 /// /// public static void AddPipelineComponent(Model.HJGL_Pipeline_Component pipeline) { Model.SGGLDB db = Funs.DB; Model.HJGL_Pipeline_Component newPipeline = new Model.HJGL_Pipeline_Component(); pipeline.IsPrint = false; newPipeline.PipelineComponentId = pipeline.PipelineComponentId; newPipeline.PipelineId = pipeline.PipelineId; newPipeline.PreUnit = pipeline.PreUnit; newPipeline.PipelineComponentCode = pipeline.PipelineComponentCode; newPipeline.BoxNumber = pipeline.BoxNumber; newPipeline.AssembleUnit = pipeline.AssembleUnit; newPipeline.PipeLineMatId = pipeline.PipeLineMatId; newPipeline.State= pipeline.State; newPipeline.QRCode= pipeline.QRCode; newPipeline.PlanStartDate = pipeline.PlanStartDate; newPipeline.PlanEndDate = pipeline.PlanEndDate; newPipeline.ActStartDate = pipeline.ActStartDate; newPipeline.ActEndDate = pipeline.ActEndDate; newPipeline.DrawingName = pipeline.DrawingName; newPipeline.ReceiveMan= pipeline.ReceiveMan; newPipeline.ReceiveDate= pipeline.ReceiveDate; newPipeline.ProductionState= pipeline.ProductionState; newPipeline.IsPrint= pipeline.IsPrint; newPipeline.Remark = pipeline.Remark; db.HJGL_Pipeline_Component.InsertOnSubmit(newPipeline); db.SubmitChanges(); } /// /// 修改作业管线 /// /// public static void UpdatePipelineComponent(Model.HJGL_Pipeline_Component pipeline) { Model.SGGLDB db = Funs.DB; Model.HJGL_Pipeline_Component newPipeline = db.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipeline.PipelineComponentId); if (newPipeline != null) { newPipeline.PipelineId = pipeline.PipelineId; newPipeline.PreUnit = pipeline.PreUnit; newPipeline.PipelineComponentCode = pipeline.PipelineComponentCode; newPipeline.BoxNumber = pipeline.BoxNumber; newPipeline.AssembleUnit = pipeline.AssembleUnit; newPipeline.PipeLineMatId = pipeline.PipeLineMatId; newPipeline.State = pipeline.State; newPipeline.QRCode = pipeline.QRCode; newPipeline.PlanStartDate = pipeline.PlanStartDate; newPipeline.PlanEndDate = pipeline.PlanEndDate; newPipeline.ActStartDate = pipeline.ActStartDate; newPipeline.ActEndDate = pipeline.ActEndDate; newPipeline.DrawingName = pipeline.DrawingName; newPipeline.ReceiveMan = pipeline.ReceiveMan; newPipeline.ReceiveDate = pipeline.ReceiveDate; newPipeline.ProductionState = pipeline.ProductionState; newPipeline.IsPrint=pipeline.IsPrint; newPipeline.Remark = pipeline.Remark; db.SubmitChanges(); } } /// /// 修改出库状态 /// /// /// public static void UpdateOutState(string pipelineComponentId,string BoxNumber) { var q=GetPipelineComponentById(pipelineComponentId); if (q.State==State1) { q.State = State2; q.BoxNumber=BoxNumber; UpdatePipelineComponent(q); } } /// /// 修改打印状态 /// /// public static void UpdateIsPrint(string[] PipelineComponentId) { var componentsToUpdate = Funs.DB.HJGL_Pipeline_Component .Where(c => PipelineComponentId.Contains(c.PipelineComponentId)); foreach (var component in componentsToUpdate) { component.IsPrint = true; } Funs.DB.SubmitChanges(); } /// /// 修改生产状态 /// /// /// public static void UpdateProductionState(string pipelineComponentId, int state, DateTime TaskDate) { var q = GetPipelineComponentById(pipelineComponentId); if (q!=null) { q.ProductionState = state; if (state==2) { q.ActEndDate = TaskDate; } else if(state==1) { if (q.ActStartDate ==null) { q.ActStartDate = TaskDate; } else { if (DateTime.Compare(TaskDate,q.ActStartDate.Value) < 0) { q.ActStartDate = TaskDate; } } } UpdatePipelineComponent(q); } } /// /// 根据作业管线Id删除一个作业管线信息 /// /// public static void DeletePipelineComponent(string pipelineComponentId) { Model.SGGLDB db = Funs.DB; Model.HJGL_Pipeline_Component pipeline = db.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipelineComponentId); if (pipeline != null) { db.HJGL_Pipeline_Component.DeleteOnSubmit(pipeline); db.SubmitChanges(); } } /// /// 根据管线材料id删除对应组件 /// /// public static void DeletePipelineComponentByMatId(string pipeLineMatId) { Model.SGGLDB db = Funs.DB; var mdoel = db.HJGL_Pipeline_Component.Where(e => e.PipeLineMatId == pipeLineMatId); if (mdoel != null) { db.HJGL_Pipeline_Component.DeleteAllOnSubmit(mdoel); db.SubmitChanges(); } } /// /// 根据管线id删除组件 /// /// public static void DeletePipelineComponentBypipelineId(string pipelineId) { Model.SGGLDB db = Funs.DB; var mdoel = db.HJGL_Pipeline_Component.Where(e => e.PipelineId == pipelineId); if (mdoel != null) { db.HJGL_Pipeline_Component.DeleteAllOnSubmit(mdoel); db.SubmitChanges(); } } /// /// 获取已经验收的预制组件 /// /// /// /// /// public static List GetAcceptedPipelineComponent(string projectId, string pipelineCode, string pipelineComponentCode,string flowingSection) { Model.SGGLDB db = Funs.DB; var q = (from x in db.HJGL_Pipeline_Component join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId where y.ProjectId.Contains(projectId) && x.State.Equals(State1) && (string.IsNullOrEmpty(pipelineCode) || y.PipelineCode.Contains(pipelineCode)) && (string.IsNullOrEmpty(pipelineComponentCode) || x.PipelineComponentCode.Contains(pipelineComponentCode)) && (string.IsNullOrEmpty(flowingSection) || y.FlowingSection.Contains(flowingSection)) select x).ToList(); return q; } public static List GetComponentByPipelineId(string PipelineId) { Model.SGGLDB db = Funs.DB; var q = (from x in db.HJGL_Pipeline_Component where x.PipelineId == PipelineId select x).OrderBy(x=>x.PlanStartDate).ToList(); return q; } ///// ///// 管线下拉框 ///// ///// 下拉框名字 ///// 是否显示请选择 //public static void InitPipelineDownList(FineUIPro.DropDownList dropName,string projectid, string pipelineCode, // string pipelineComponentCode, bool isShowPlease) //{ // dropName.DataValueField = "PipelineComponentId"; // dropName.DataTextField = "PipelineComponentCode"; // dropName.DataSource = GetAcceptedPipelineComponent(projectid, pipelineCode, pipelineComponentCode); // dropName.DataBind(); // if (isShowPlease) // { // Funs.FineUIPleaseSelect(dropName); // } //} public static void InitMainItemDownList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "Value"; dropName.DataTextField = "Text"; dropName.DataSource = GetState(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static void InitMainItemDownProductionStateList(FineUIPro.DropDownList dropName, bool isShowPlease) { dropName.DataValueField = "Value"; dropName.DataTextField = "Text"; dropName.DataSource = GetProductionState(); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } } public class PipelineComponentPrintDto { public string PipelineComponentId { get; set; } public string PipelineComponentCode { get; set; } public string BoxNumber { get; set; } public string UnitWorkName { get; set; } public string PipelineId { get; set; } public string PreUnit { get; set; } public string AssembleUnit { get; set; } public string PrefabricatedComponents { get; set; } public string QRCode { get; set; } public int? State { get; set; } public string PlanStartDate { get; set; } public string PipelineCode { get; set; } public string FlowingSection { get; set; } public string QRCode2 { get; set; } public string MaterialCode { get; set; } public bool? IsPrint { get; set; } } }