using FineUIPro; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace BLL { public static class TwInOutplandetailService { #region 获取列表 /// /// 记录数 /// public static int Count { get; set; } public static IQueryable GetByModle(Model.Tw_InOutDetailOutput table) { var q = from x in Funs.DB.Tw_InOutPlanDetail join y in Funs.DB.HJGL_Pipeline_Component on x.PipelineComponentId equals y.PipelineComponentId into yy from y in yy.DefaultIfEmpty() join mat in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals mat.MaterialCode into mm from mat in mm.DefaultIfEmpty() join master in Funs.DB.Tw_InOutPlanMaster on x.InOutPlanMasterId equals master.Id into masters from master in masters.DefaultIfEmpty() join stock in Funs.DB.Tw_MaterialStock on new { x.MaterialCode, master.WarehouseCode } equals new { MaterialCode = stock.PipeLineMatCode, stock.WarehouseCode } into st from stock in st.DefaultIfEmpty() where (string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) && (string.IsNullOrEmpty(table.InOutPlanMasterId) || x.InOutPlanMasterId.Contains(table.InOutPlanMasterId)) && (string.IsNullOrEmpty(table.PipelineComponentId) || x.PipelineComponentId.Contains(table.PipelineComponentId)) && (string.IsNullOrEmpty(table.MaterialCode) || x.MaterialCode.Contains(table.MaterialCode)) orderby x.SortIndex select new Model.Tw_InOutDetailOutput { Id = x.Id, InOutPlanMasterId = x.InOutPlanMasterId, PipelineComponentId = x.PipelineComponentId, MaterialCode = x.MaterialCode, PlanNum = x.PlanNum, ActNum = x.ActNum, PipelineComponentCode = y.PipelineComponentCode, MaterialName = mat.MaterialName, MaterialDef= mat.MaterialDef, StockNum = stock.StockNum ?? 0, } ; return q; } /// /// 获取分页列表 /// /// /// /// public static IEnumerable GetListData(Model.Tw_InOutDetailOutput table, Grid grid1) { var q = GetByModle(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 select x; } #endregion public static Model.Tw_InOutPlanDetail GetById(string Id) { return Funs.DB.Tw_InOutPlanDetail.FirstOrDefault(x => x.Id == Id); } public static void Add(Model.Tw_InOutPlanDetail newtable) { if (string.IsNullOrEmpty(newtable.Id)) { newtable.Id = SQLHelper.GetNewID(); } Model.Tw_InOutPlanDetail table = new Model.Tw_InOutPlanDetail { Id = newtable.Id, InOutPlanMasterId = newtable.InOutPlanMasterId, PipelineComponentId = newtable.PipelineComponentId, MaterialCode = newtable.MaterialCode, PlanNum = newtable.PlanNum, ActNum = newtable.ActNum, SortIndex = newtable.SortIndex }; Funs.DB.Tw_InOutPlanDetail.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 批量添加计划明细 /// /// /// public static void AddList(IEnumerable list, string inoutPlanMasterId) { int sortIndex = 1; foreach (var item in list) { item.Id= SQLHelper.GetNewID(); item.SortIndex= sortIndex; item.InOutPlanMasterId = inoutPlanMasterId; Add(item); sortIndex++; } } public static void Update(Model.Tw_InOutPlanDetail newtable) { Model.Tw_InOutPlanDetail table = Funs.DB.Tw_InOutPlanDetail.FirstOrDefault(x => x.Id == newtable.Id); if (table != null) { table.Id = newtable.Id; table.InOutPlanMasterId = newtable.InOutPlanMasterId; table.PipelineComponentId = newtable.PipelineComponentId; table.MaterialCode = newtable.MaterialCode; table.PlanNum = newtable.PlanNum; table.ActNum = newtable.ActNum; table.SortIndex= newtable.SortIndex; Funs.DB.SubmitChanges(); } } public static void DeleteById(string Id) { Model.Tw_InOutPlanDetail table = Funs.DB.Tw_InOutPlanDetail.FirstOrDefault(x => x.Id == Id); if (table != null) { Funs.DB.Tw_InOutPlanDetail.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } public static void DeleteByInOutPlanMasterId (string inoutPlanMasterId) { var list = Funs.DB.Tw_InOutPlanDetail.Where(x => x.InOutPlanMasterId == inoutPlanMasterId); if (list != null) { Funs.DB.Tw_InOutPlanDetail.DeleteAllOnSubmit(list); Funs.DB.SubmitChanges(); } } public static void GenInOutPlanDetailByInoutPlanMasterId(string inOutPlanMasterId) { var list = Funs.DB.Tw_InOutPlanDetail_Relation.Where(x => x.InOutPlanMasterId == inOutPlanMasterId).ToList(); var outMateriaList = from x in list group x by x.MaterialCode into g select new { g.Key, planNum = g.Sum(x => x.Number) ?? 0 }; TwInOutplandetailService.DeleteByInOutPlanMasterId(inOutPlanMasterId); foreach (var item in outMateriaList) { Model.Tw_InOutPlanDetail detail = new Model.Tw_InOutPlanDetail { Id = Guid.NewGuid().ToString(), InOutPlanMasterId = inOutPlanMasterId, MaterialCode = item.Key, PlanNum = item.planNum, }; TwInOutplandetailService.Add(detail); } } } }