using FineUIPro; using Model; using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace BLL { public static class TwInoutplandetailRelationService { #region 获取列表 /// /// 记录数 /// public static int Count { get; set; } public static IQueryable GetTw_InOutPlanDetail_RelationByModle(Model.Tw_InOutPlanDetail_Relation table) { var q = from x in Funs.DB.Tw_InOutPlanDetail_Relation where (string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) && (string.IsNullOrEmpty(table.PipelineId) || x.PipelineId.Contains(table.PipelineId)) && (string.IsNullOrEmpty(table.InOutPlanMasterId) || x.InOutPlanMasterId.Contains(table.InOutPlanMasterId)) && (string.IsNullOrEmpty(table.MaterialCode) || x.MaterialCode.Contains(table.MaterialCode)) && (string.IsNullOrEmpty(table.PrefabricatedComponents) || x.PrefabricatedComponents.Contains(table.PrefabricatedComponents)) select x ; return q; } /// /// 获取分页列表 /// /// /// /// public static IEnumerable GetListData(Model.Tw_InOutPlanDetail_Relation table, Grid grid1) { var q = GetTw_InOutPlanDetail_RelationByModle(table); Count = q.Count(); if (Count == 0) { return null; } q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize); // q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in q join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId join mat in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals mat.MaterialCode into mm from mat in mm.DefaultIfEmpty() orderby x.PipelineId, x.PrefabricatedComponents select new { x.Id, x.PipelineId, y.PipelineCode, x.InOutPlanMasterId, x.MaterialCode, Code = mat.Code, mat.HeatNo, mat.BatchNo, x.PrefabricatedComponents, x.Number, mat.MaterialName, mat.MaterialDef }; } #endregion public static Model.Tw_InOutPlanDetail_Relation GetById(string Id) { return Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == Id); } public static Model.Tw_InOutPlanDetail_Relation GetByPipelineId(string pipelineId, string warehouseId) { int typeInt = (int)TwConst.TypeInt.散件出库; var q = from x in Funs.DB.Tw_InOutPlanDetail_Relation join y in Funs.DB.Tw_InOutPlanMaster on x.InOutPlanMasterId equals y.Id where x.PipelineId == pipelineId && y.WarehouseId == warehouseId && y.TypeInt != typeInt select x; return q.FirstOrDefault(); } public static void Add(Model.Tw_InOutPlanDetail_Relation newtable) { Model.Tw_InOutPlanDetail_Relation table = new Model.Tw_InOutPlanDetail_Relation { Id = newtable.Id, PipelineId = newtable.PipelineId, InOutPlanMasterId = newtable.InOutPlanMasterId, MaterialCode = newtable.MaterialCode, PrefabricatedComponents = newtable.PrefabricatedComponents, Number = newtable.Number, // 领料出库由焊接任务单焊口驱动,关联明细需要保存焊口ID用于后续追溯。 WeldJointId = newtable.WeldJointId, }; Funs.DB.Tw_InOutPlanDetail_Relation.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 批量添加计划明细 /// /// /// public static void AddList(IEnumerable list, string inoutPlanMasterId) { foreach (var item in list) { item.Id = SQLHelper.GetNewID(); item.InOutPlanMasterId = inoutPlanMasterId; Add(item); } } public static void Update(Model.Tw_InOutPlanDetail_Relation newtable) { Model.Tw_InOutPlanDetail_Relation table = Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == newtable.Id); if (table != null) { table.Id = newtable.Id; table.PipelineId = newtable.PipelineId; table.InOutPlanMasterId = newtable.InOutPlanMasterId; table.MaterialCode = newtable.MaterialCode; table.PrefabricatedComponents = newtable.PrefabricatedComponents; table.Number = newtable.Number; // 更新关联明细时同步维护焊口ID,避免出库申请修改后丢失焊口归属。 table.WeldJointId = newtable.WeldJointId; Funs.DB.SubmitChanges(); } } public static void DeleteById(string Id) { Model.Tw_InOutPlanDetail_Relation table = Funs.DB.Tw_InOutPlanDetail_Relation.FirstOrDefault(x => x.Id == Id); if (table != null) { Funs.DB.Tw_InOutPlanDetail_Relation.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } public static void DeleteByInOutPlanMasterId(string inoutPlanMasterId) { var list = Funs.DB.Tw_InOutPlanDetail_Relation.Where(x => x.InOutPlanMasterId == inoutPlanMasterId); if (list != null) { Funs.DB.Tw_InOutPlanDetail_Relation.DeleteAllOnSubmit(list); Funs.DB.SubmitChanges(); } } public static IEnumerable GetPrintListByOutputMasterIds(List outputMasterIds) { var q = from x in Funs.DB.Tw_InOutPlanDetail_Relation join y in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode join plan in Funs.DB.Tw_InOutPlanMaster on x.InOutPlanMasterId equals plan.Id join master in Funs.DB.Tw_OutputMaster on plan.Id equals master.InOutPlanMasterId join pipe in Funs.DB.HJGL_Pipeline on x.PipelineId equals pipe.PipelineId where outputMasterIds.Contains(master.Id) orderby master.CusBillCode select new { 出库单编号 = master.CusBillCode, 管线号 = pipe.PipelineCode, 预制组件号 = x.PrefabricatedComponents, 材料主编码 = x.MaterialCode, 材料编码 = y.Code, 炉号 = y.HeatNo, 批号 = y.BatchNo, 材料名称 = y.MaterialName, 材料描述 = y.MaterialDef, 单位 = y.MaterialUnit, 所需量 = x.Number, }; return q; } } }