using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace BLL { /// /// 材料到货登记及验收记录 /// public class HJGL_EMaterialRegistService { public static Model.SGGLDB db = Funs.DB; /// /// 记录数 /// private static int count { get; set; } /// /// 定义变量 /// private static IQueryable qq = from x in db.HJGL_EMaterialRegist orderby x.EMaterialRegistCode select x; /// /// 分页查询列表 /// /// /// /// /// public static IEnumerable GetListData(string projectId, int startRowIndex, int maximumRows) { IQueryable q = qq; if (!string.IsNullOrEmpty(projectId)) { q = q.Where(e => e.ProjectId == projectId); } count = q.Count(); if (count == 0) { return new object[] { "" }; } return from x in q.Skip(startRowIndex).Take(maximumRows) select new { x.EMaterialRegistId, x.EMaterialRegistCode, x.EMaterialRegistDate, x.DeliveryMan, CompileMan = (from y in db.Sys_User where y.UserId == x.CompileMan select y.UserName).First(), x.CompileDate, x.UnitName, ProjectName = (from y in db.Base_Project where y.ProjectId == x.ProjectId select y.ProjectName).First() }; } /// /// 分页查询数 /// /// /// public static int GetListCount(string projectId) { return count; } /// /// 材料到货登记及验收记录明细分页列表 /// /// /// public static IEnumerable GetEMaterialRegistItemList(string eMaterialRegistId) { return from x in Funs.DB.HJGL_EMaterialRegistItem where x.EMaterialRegistId == eMaterialRegistId select new { x.EMaterialRegistItemId, x.EMaterialRegistId, MatName = (from y in Funs.DB.Base_Consumables where y.ConsumablesId == x.WMT_ID select y.ConsumablesName).First(), x.SpecificationsModel, x.UnitName, x.MaterialCount, x.ItemCode, x.Testrecords, x.Models }; } /// /// 根据材料到货登记及验收记录Id获取材料到货登记及验收记录信息 /// /// /// public static Model.HJGL_EMaterialRegist GetEMaterialRegistByID(string eMaterialRegistId) { Model.SGGLDB db = Funs.DB; var eMaterialRegist = db.HJGL_EMaterialRegist.FirstOrDefault(e => e.EMaterialRegistId == eMaterialRegistId); return eMaterialRegist; } /// /// 根据材料到货登记及验收记录Id获取明细信息 /// /// /// public static List GetEMaterialRegistItemByRegistId(string eMaterialRegistId) { return (from x in Funs.DB.HJGL_EMaterialRegistItem where x.EMaterialRegistId == eMaterialRegistId select x).ToList(); } /// /// /// /// public static List GetRegistItem() { return (from x in Funs.DB.HJGL_EMaterialRegistItem select x).ToList(); } /// /// 添加材料到货登记及验收记录 /// /// public static void AddEMaterialRegist(Model.HJGL_EMaterialRegist eMaterialRegist) { Model.SGGLDB db = Funs.DB; Model.HJGL_EMaterialRegist newEMaterialRegist = new Model.HJGL_EMaterialRegist(); newEMaterialRegist.EMaterialRegistId = eMaterialRegist.EMaterialRegistId; newEMaterialRegist.EMaterialRegistCode = eMaterialRegist.EMaterialRegistCode; newEMaterialRegist.EMaterialRegistDate = eMaterialRegist.EMaterialRegistDate; newEMaterialRegist.DeliveryMan = eMaterialRegist.DeliveryMan; newEMaterialRegist.UnitName = eMaterialRegist.UnitName; newEMaterialRegist.CompileMan = eMaterialRegist.CompileMan; newEMaterialRegist.CompileDate = eMaterialRegist.CompileDate; newEMaterialRegist.ProjectId = eMaterialRegist.ProjectId; newEMaterialRegist.SystemCode = eMaterialRegist.SystemCode; newEMaterialRegist.PartACode = eMaterialRegist.PartACode; newEMaterialRegist.Condition = eMaterialRegist.Condition; newEMaterialRegist.Name = eMaterialRegist.Name; newEMaterialRegist.SpecificationsModel = eMaterialRegist.SpecificationsModel; newEMaterialRegist.Standard = eMaterialRegist.Standard; newEMaterialRegist.Material = eMaterialRegist.Material; newEMaterialRegist.SpecialInstructions = eMaterialRegist.SpecialInstructions; newEMaterialRegist.Unit = eMaterialRegist.Unit; newEMaterialRegist.Amount = eMaterialRegist.Amount; newEMaterialRegist.FourLocation = eMaterialRegist.FourLocation; newEMaterialRegist.Manufacturer = eMaterialRegist.Manufacturer; newEMaterialRegist.DesignUnit = eMaterialRegist.DesignUnit; newEMaterialRegist.RealArriveAmount = eMaterialRegist.RealArriveAmount; newEMaterialRegist.OutProve = eMaterialRegist.OutProve; newEMaterialRegist.OutPrices = eMaterialRegist.OutPrices; newEMaterialRegist.Supply = eMaterialRegist.Supply; newEMaterialRegist.WMT_ID = eMaterialRegist.WMT_ID; db.HJGL_EMaterialRegist.InsertOnSubmit(newEMaterialRegist); db.SubmitChanges(); } /// /// 修改材料到货登记及验收记录 /// /// public static void UpdateEMaterialRegist(Model.HJGL_EMaterialRegist eMaterialRegist) { Model.SGGLDB db = Funs.DB; Model.HJGL_EMaterialRegist newEMaterialRegist = db.HJGL_EMaterialRegist.First(e => e.EMaterialRegistId == eMaterialRegist.EMaterialRegistId); newEMaterialRegist.EMaterialRegistCode = eMaterialRegist.EMaterialRegistCode; newEMaterialRegist.EMaterialRegistDate = eMaterialRegist.EMaterialRegistDate; newEMaterialRegist.DeliveryMan = eMaterialRegist.DeliveryMan; newEMaterialRegist.UnitName = eMaterialRegist.UnitName; newEMaterialRegist.CompileMan = eMaterialRegist.CompileMan; newEMaterialRegist.CompileDate = eMaterialRegist.CompileDate; newEMaterialRegist.ProjectId = eMaterialRegist.ProjectId; newEMaterialRegist.SystemCode = eMaterialRegist.SystemCode; newEMaterialRegist.PartACode = eMaterialRegist.PartACode; newEMaterialRegist.Condition = eMaterialRegist.Condition; newEMaterialRegist.Name = eMaterialRegist.Name; newEMaterialRegist.SpecificationsModel = eMaterialRegist.SpecificationsModel; newEMaterialRegist.Standard = eMaterialRegist.Standard; newEMaterialRegist.Material = eMaterialRegist.Material; newEMaterialRegist.SpecialInstructions = eMaterialRegist.SpecialInstructions; newEMaterialRegist.Unit = eMaterialRegist.Unit; newEMaterialRegist.Amount = eMaterialRegist.Amount; newEMaterialRegist.FourLocation = eMaterialRegist.FourLocation; newEMaterialRegist.Manufacturer = eMaterialRegist.Manufacturer; newEMaterialRegist.DesignUnit = eMaterialRegist.DesignUnit; newEMaterialRegist.RealArriveAmount = eMaterialRegist.RealArriveAmount; newEMaterialRegist.OutProve = eMaterialRegist.OutProve; newEMaterialRegist.OutPrices = eMaterialRegist.OutPrices; newEMaterialRegist.Supply = eMaterialRegist.Supply; newEMaterialRegist.WMT_ID = eMaterialRegist.WMT_ID; db.SubmitChanges(); } /// /// 删除材料到货登记及验收记录 /// /// public static void DeleteEMaterialRegist(string eMaterialRegistId) { Model.SGGLDB db = Funs.DB; Model.HJGL_EMaterialRegist eMaterialRegist = db.HJGL_EMaterialRegist.First(e => e.EMaterialRegistId == eMaterialRegistId); db.HJGL_EMaterialRegist.DeleteOnSubmit(eMaterialRegist); db.SubmitChanges(); } /// /// 添加材料到货登记及验收记录明细 /// /// public static void AddEMaterialRegistItem(Model.HJGL_EMaterialRegistItem item) { Model.SGGLDB db = Funs.DB; Model.HJGL_EMaterialRegistItem newItem = new Model.HJGL_EMaterialRegistItem(); newItem.EMaterialRegistItemId = item.EMaterialRegistItemId; newItem.EMaterialRegistId = item.EMaterialRegistId; newItem.WMT_ID = item.WMT_ID; newItem.SpecificationsModel = item.SpecificationsModel; newItem.UnitName = item.UnitName; newItem.MaterialCount = item.MaterialCount; newItem.ItemCode = item.ItemCode; newItem.Testrecords = item.Testrecords; newItem.Models = item.Models; db.HJGL_EMaterialRegistItem.InsertOnSubmit(newItem); db.SubmitChanges(); } /// /// 根据材料到货登记及验收记录Id删除所有相关明细 /// /// public static void DeleteEMaterialRegistItem(string projectId,string unitId, string eMaterialRegistId) { Model.SGGLDB db = Funs.DB; var deleteItem = from x in db.HJGL_EMaterialRegistItem where x.EMaterialRegistId == eMaterialRegistId select x; /// 取到货明细 库存减去明细值 if (deleteItem.Count() > 0) { foreach (var ditem in deleteItem) { int count = 0; if (ditem.MaterialCount.HasValue) { count = count - ditem.MaterialCount.Value; } if (count < 0) { BLL.HJGL_EMInventoryRecordsService.UpdateEMInventoryRecords(projectId,unitId, ditem.WMT_ID, ditem.Models, ditem.SpecificationsModel, count); } } db.HJGL_EMaterialRegistItem.DeleteAllOnSubmit(deleteItem); db.SubmitChanges(); } } /// /// 获取打印列表 /// /// /// /// public static IEnumerable GetListDataPrint(string eMaterialRegistId) { return from x in db.HJGL_EMaterialRegistItem join y in db.HJGL_EMaterialRegist on x.EMaterialRegistId equals y.EMaterialRegistId where y.EMaterialRegistId == eMaterialRegistId orderby y.EMaterialRegistCode select new { x.EMaterialRegistItemId, x.EMaterialRegistId, MatName = (from m in db.Base_Consumables where m.ConsumablesId == x.WMT_ID select m.ConsumablesName).First(), x.SpecificationsModel, x.UnitName, x.MaterialCount, x.ItemCode, x.Testrecords, x.Models }; } } }