using System; using System.Collections; using System.Collections.Generic; using System.Linq; using EmitMapper; using FineUIPro; using MiniExcelLibs; using MiniExcelLibs.Attributes; using Model; namespace BLL { public static class PHTGL_QuantityService { public static PHTGL_Quantity GetPHTGL_QuantityById(string Id) { return Funs.DB.PHTGL_Quantity.FirstOrDefault(x => x.Id == Id); } public static void AddPHTGL_Quantity(PHTGL_Quantity newtable) { var table = new PHTGL_Quantity { Id = newtable.Id, Major = newtable.Major, SubProject = newtable.SubProject, SubItemProject = newtable.SubItemProject, ProjectCode = newtable.ProjectCode, ProjectName = newtable.ProjectName, ProjectDescription = newtable.ProjectDescription, UnitOfMeasurement = newtable.UnitOfMeasurement, Quantity = newtable.Quantity, TotalCostFixedComprehensiveUnitPrice = newtable.TotalCostFixedComprehensiveUnitPrice, MainMaterialCost = newtable.MainMaterialCost, TotalPrice = newtable.TotalPrice, CalculationRule = newtable.CalculationRule, WorkContent = newtable.WorkContent, Remarks = newtable.Remarks, IsTemplate = newtable.IsTemplate, ParentId = newtable.ParentId }; Funs.DB.PHTGL_Quantity.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } /// /// 通过模板增加实体 /// /// /// public static void AddPHTGL_QuantityByTemModel(PHTGL_Quantity newtable, string parentId) { var table = new PHTGL_Quantity { Id = SQLHelper.GetNewID(), Major = newtable.Major, SubProject = newtable.SubProject, SubItemProject = newtable.SubItemProject, ProjectCode = newtable.ProjectCode, ProjectName = newtable.ProjectName, ProjectDescription = newtable.ProjectDescription, UnitOfMeasurement = newtable.UnitOfMeasurement, Quantity = newtable.Quantity, TotalCostFixedComprehensiveUnitPrice = newtable.TotalCostFixedComprehensiveUnitPrice, MainMaterialCost = newtable.MainMaterialCost, TotalPrice = newtable.TotalPrice, CalculationRule = newtable.CalculationRule, WorkContent = newtable.WorkContent, Remarks = newtable.Remarks, IsTemplate = false, ParentId = parentId }; Funs.DB.PHTGL_Quantity.InsertOnSubmit(table); Funs.DB.SubmitChanges(); } public static void UpdatePHTGL_Quantity(PHTGL_Quantity newtable) { var table = Funs.DB.PHTGL_Quantity.FirstOrDefault(x => x.Id == newtable.Id); if (table != null) { table.Id = newtable.Id; table.Major = newtable.Major; table.SubProject = newtable.SubProject; table.SubItemProject = newtable.SubItemProject; table.ProjectCode = newtable.ProjectCode; table.ProjectName = newtable.ProjectName; table.ProjectDescription = newtable.ProjectDescription; table.UnitOfMeasurement = newtable.UnitOfMeasurement; table.Quantity = newtable.Quantity; table.TotalCostFixedComprehensiveUnitPrice = newtable.TotalCostFixedComprehensiveUnitPrice; table.MainMaterialCost = newtable.MainMaterialCost; table.TotalPrice = newtable.TotalPrice; table.CalculationRule = newtable.CalculationRule; table.WorkContent = newtable.WorkContent; table.Remarks = newtable.Remarks; table.IsTemplate = newtable.IsTemplate; table.ParentId = newtable.ParentId; Funs.DB.SubmitChanges(); } } public static void DeletePHTGL_QuantityById(string Id) { var table = Funs.DB.PHTGL_Quantity.FirstOrDefault(x => x.Id == Id); if (table != null) { Funs.DB.PHTGL_Quantity.DeleteOnSubmit(table); Funs.DB.SubmitChanges(); } } public static void DeletePHTGL_QuantityByParentId(string parentId) { var table = Funs.DB.PHTGL_Quantity.Where(x => x.ParentId == parentId); if (table.Any()) { Funs.DB.PHTGL_Quantity.DeleteAllOnSubmit(table); Funs.DB.SubmitChanges(); } } /// /// 导入数据 /// /// 数据文件地址 /// 专业类型 /// public static ResponeData ImportData(string path, string majortype) { var responeData = new ResponeData(); List rows; try { rows = MiniExcel.Query(path).ToList(); } catch (Exception e) { responeData.code = 0; responeData.message = "模板错误"; return responeData; } var mapper = ObjectMapperManager.DefaultInstance.GetMapper, List>(); var modeList = mapper.Map(rows); if (modeList.Count == 0) { responeData.code = 0; responeData.message = "没有数据"; return responeData; } foreach (var item in modeList) { item.Major = GetMajorItems().Where(x => x.Text == majortype).Select(x => x.Value).FirstOrDefault() ?? ""; if (string.IsNullOrEmpty(item.Major)) break; var queryPhtglQuantity = new PHTGL_Quantity { Major = item.Major, SubProject = item.SubProject, SubItemProject = item.SubItemProject, ProjectCode = item.ProjectCode, IsTemplate = true }; var resultModel = GetPHTGL_QuantityByModle(queryPhtglQuantity); if (resultModel.Any()) { item.Id = resultModel[0].Id; UpdatePHTGL_Quantity(item); } else { item.Id = SQLHelper.GetNewID(); item.IsTemplate = true; AddPHTGL_Quantity(item); } } return responeData; } public static ResponeData ImportData(string path, string majortype, string mainProjectQuantityId) { var responeData = new ResponeData(); List rows; try { rows = MiniExcel.Query(path).ToList(); } catch (Exception e) { responeData.code = 0; responeData.message = "模板错误"; return responeData; } var mapper = ObjectMapperManager.DefaultInstance.GetMapper, List>(); var modeList = mapper.Map(rows); if (modeList.Count == 0) { responeData.code = 0; responeData.message = "没有数据"; return responeData; } foreach (var item in modeList) { if (!string.IsNullOrEmpty(majortype)) { item.Major = GetMajorItems().Where(x => x.Text == majortype).Select(x => x.Value).FirstOrDefault() ?? ""; } if (string.IsNullOrEmpty(item.Major)) break; var queryPhtglQuantity = new PHTGL_Quantity { Major = item.Major, SubProject = item.SubProject, SubItemProject = item.SubItemProject, ProjectCode = item.ProjectCode, }; if (string.IsNullOrEmpty(mainProjectQuantityId)) { queryPhtglQuantity.IsTemplate = true; item.IsTemplate = true; } else { queryPhtglQuantity.IsTemplate = false; queryPhtglQuantity.ParentId = mainProjectQuantityId; item.ParentId = mainProjectQuantityId; item.IsTemplate = false; } var resultModel = GetPHTGL_QuantityByModle(queryPhtglQuantity); if (resultModel.Any()) { item.Id = resultModel[0].Id; UpdatePHTGL_Quantity(item); } else { item.Id = SQLHelper.GetNewID(); AddPHTGL_Quantity(item); } } return responeData; } public static ListItem[] GetMajorItems() { var list = new ListItem[10]; list[0] = new ListItem("0", "土建工程"); list[1] = new ListItem("1", "钢结构预制工程"); list[2] = new ListItem("2", "工艺管道安装工程"); list[3] = new ListItem("3", "工艺设备安装工程"); list[4] = new ListItem("4", "非标设备现场制作安装工程"); list[5] = new ListItem("5", "电仪安装工程"); list[6] = new ListItem("6", "水暖安装工程"); list[7] = new ListItem("7", "防腐绝热工程"); list[8] = new ListItem("8", "无损检测工程"); list[9] = new ListItem("9", "消防工程"); return list; } #region 获取列表 /// /// 记录数 /// public static int count { get; set; } public static List GetPHTGL_QuantityByModle(PHTGL_Quantity table) { var q = from x in Funs.DB.PHTGL_Quantity where (string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) && (string.IsNullOrEmpty(table.Major) || x.Major.Contains(table.Major)) && (string.IsNullOrEmpty(table.SubProject) || x.SubProject.Contains(table.SubProject)) && (string.IsNullOrEmpty(table.SubItemProject) || x.SubItemProject.Contains(table.SubItemProject)) && (string.IsNullOrEmpty(table.ProjectCode) || x.ProjectCode.Contains(table.ProjectCode)) && (string.IsNullOrEmpty(table.ProjectName) || x.ProjectName.Contains(table.ProjectName)) && (string.IsNullOrEmpty(table.ProjectDescription) || x.ProjectDescription.Contains(table.ProjectDescription)) && (string.IsNullOrEmpty(table.UnitOfMeasurement) || x.UnitOfMeasurement.Contains(table.UnitOfMeasurement)) && (string.IsNullOrEmpty(table.Quantity) || x.Quantity.Contains(table.Quantity)) && (string.IsNullOrEmpty(table.TotalCostFixedComprehensiveUnitPrice) || x.TotalCostFixedComprehensiveUnitPrice.Contains(table.TotalCostFixedComprehensiveUnitPrice)) && (string.IsNullOrEmpty(table.MainMaterialCost) || x.MainMaterialCost.Contains(table.MainMaterialCost)) && (string.IsNullOrEmpty(table.TotalPrice) || x.TotalPrice.Contains(table.TotalPrice)) && (string.IsNullOrEmpty(table.CalculationRule) || x.CalculationRule.Contains(table.CalculationRule)) && (string.IsNullOrEmpty(table.WorkContent) || x.WorkContent.Contains(table.WorkContent)) && (string.IsNullOrEmpty(table.Remarks) || x.Remarks.Contains(table.Remarks)) && x.IsTemplate == table.IsTemplate && (string.IsNullOrEmpty(table.ParentId) || x.ParentId.Contains(table.ParentId)) select x ; return q.ToList(); } /// 获取分页列表 /// /// 页码 /// 每页数量 /// public static IEnumerable getListData(PHTGL_Quantity table, Grid Grid1) { var q = GetPHTGL_QuantityByModle(table); count = q.Count(); if (count == 0) return null; q = q.Skip(Grid1.PageSize * Grid1.PageIndex).Take(Grid1.PageSize).ToList(); // q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize); return from x in q select new { x.Id, x.Major, x.SubProject, x.SubItemProject, x.ProjectCode, x.ProjectName, x.ProjectDescription, x.UnitOfMeasurement, x.Quantity, x.TotalCostFixedComprehensiveUnitPrice, x.MainMaterialCost, x.TotalPrice, x.CalculationRule, x.WorkContent, x.Remarks, x.IsTemplate, x.ParentId }; } #endregion } public class PHTGL_QuantityDtoIn { [ExcelColumnIndex("A")] public string Major { get; set; } [ExcelColumnIndex("B")] public string SubProject { get; set; } [ExcelColumnIndex("C")] public string SubItemProject { get; set; } [ExcelColumnIndex("D")] public string ProjectCode { get; set; } [ExcelColumnIndex("E")] public string ProjectName { get; set; } [ExcelColumnIndex("F")] public string ProjectDescription { get; set; } [ExcelColumnIndex("G")] public string UnitOfMeasurement { get; set; } [ExcelColumnIndex("H")] public string Quantity { get; set; } [ExcelColumnIndex("I")] public string TotalCostFixedComprehensiveUnitPrice { get; set; } [ExcelColumnIndex("J")] public string MainMaterialCost { get; set; } [ExcelColumnIndex("K")] public string TotalPrice { get; set; } [ExcelColumnIndex("L")] public string CalculationRule { get; set; } [ExcelColumnIndex("M")] public string WorkContent { get; set; } [ExcelColumnIndex("N")] public string Remarks { get; set; } } }