using Model; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI.WebControls; 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); } /// /// 获取预制散件 /// /// 单位工程Id /// 管线Id /// public static IEnumerable GetPipelinePrefabricatedComponent(string unitworkId, string pipelineId) { var query = from pipe in Funs.DB.HJGL_PipeLineMat join lib in Funs.DB.HJGL_MaterialCodeLib on pipe.MaterialCode equals lib.MaterialCode into libJoin from libItem in libJoin.DefaultIfEmpty() join line in Funs.DB.HJGL_Pipeline on pipe.PipelineId equals line.PipelineId into lineJoin from lineItem in lineJoin.DefaultIfEmpty() where lineItem != null && lineItem.UnitWorkId == unitworkId && lineItem.PipeArea == "1" && (pipe.PrefabricatedComponents == null || pipe.PrefabricatedComponents == "") select new PipelinePrefabricatedComponentsItem { Id = pipe.PipeLineMatId, MaterialCode = libItem.MaterialCode, MaterialName = libItem.MaterialName, MaterialUnit = libItem.MaterialUnit, MaterialSpec = libItem.MaterialSpec, MaterialMade = libItem.MaterialMade, MaterialDef = libItem.MaterialDef, Number = pipe.Number, PrefabricatedComponents = pipe.PrefabricatedComponents, PipelineId = lineItem.PipelineId, }; if (!string.IsNullOrEmpty(pipelineId)) { query = query.Where(x => x.PipelineId == pipelineId); } query = query.OrderBy(x => x.PrefabricatedComponents); return query.ToList(); } /// /// 获取预制散件 /// /// 管线Id /// public static IEnumerable GetPipelinePrefabricatedComponent(string pipelineId) { var query = from pipe in Funs.DB.HJGL_PipeLineMat join lib in Funs.DB.HJGL_MaterialCodeLib on pipe.MaterialCode equals lib.MaterialCode into libJoin from libItem in libJoin.DefaultIfEmpty() join line in Funs.DB.HJGL_Pipeline on pipe.PipelineId equals line.PipelineId into lineJoin from lineItem in lineJoin.DefaultIfEmpty() where lineItem != null && lineItem.PipeArea == "1" && (pipe.PrefabricatedComponents == null || pipe.PrefabricatedComponents == "") select new PipelinePrefabricatedComponentsItem { Id = pipe.PipeLineMatId, MaterialCode = libItem.MaterialCode, MaterialName = libItem.MaterialName, MaterialUnit = libItem.MaterialUnit, MaterialSpec = libItem.MaterialSpec, MaterialMade = libItem.MaterialMade, MaterialDef = libItem.MaterialDef, Number = pipe.Number, PrefabricatedComponents = pipe.PrefabricatedComponents, PipelineId = lineItem.PipelineId, }; if (!string.IsNullOrEmpty(pipelineId)) { query = query.Where(x => x.PipelineId == pipelineId); } query = query.OrderBy(x => x.PrefabricatedComponents); var inoutplandetail = (from x in Funs.DB.HJGL_PackagingManageDetail where x.PipelineId == pipelineId && (x.PipelineComponentId == null || x.PipelineComponentId == "") select x).ToList(); var queryList = query.ToList(); // 优化 Linq 过滤条件 var result = (from x in queryList join y in inoutplandetail on x.MaterialCode equals y.MaterialCode into yy from y in yy.DefaultIfEmpty() where y == null select x).ToList(); return result; } /// /// 获取打印实体 /// /// /// /// /// 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(); // 按照传入的 PipelineId 顺序排序 result = result.OrderBy(x => Array.IndexOf(PipelineId, 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 orderby y.PipelineCode,x.PipelineComponentCode 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); } } } }