diff --git a/.vs/SGGL_SeDin/v17/.wsuo b/.vs/SGGL_SeDin/v17/.wsuo index fb4f7890..b4dc2591 100644 Binary files a/.vs/SGGL_SeDin/v17/.wsuo and b/.vs/SGGL_SeDin/v17/.wsuo differ diff --git a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineMatIn.aspx.cs b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineMatIn.aspx.cs index acfad345..f91a1b9b 100644 --- a/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineMatIn.aspx.cs +++ b/SGGL/FineUIPro.Web/HJGL/WeldingManage/PipelineMatIn.aspx.cs @@ -1,4 +1,5 @@ using BLL; +using MiniExcelLibs; using Model; using System; using System.Collections.Generic; @@ -325,6 +326,123 @@ namespace FineUIPro.Web.HJGL.WeldingManage responeData.message = errorInfos; } + return responeData; + } + private Model.ResponeData AddDatasetToSQL(List pds, int count) + { + Model.ResponeData responeData = new Model.ResponeData(); + List result = new List(); + + if (count < 4) + { + responeData.code = 0; + responeData.message = "导入Excel格式错误!Excel只有" + count.ToString().Trim() + "列"; + return responeData; + } + if (pds.Count > 0 && pds != null) + { + + for (int i = 0; i < pds.Count; i++) + { + HJGL_PipeLineMat item = new HJGL_PipeLineMat(); + + #region 数据验证和赋值 + + + string unitworkId = string.Empty; + unitworkId = Request.Params["UnitWorkId"]; + string PipeArea = string.Empty;//管线划分 1工厂预制 2现场施工 + + if (pds[i].A != null && !string.IsNullOrEmpty(pds[i].A.ToString())) + { + string pipelineCode = pds[i].A.ToString(); + var pipeline = from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == unitworkId && x.PipelineCode == pipelineCode select x; + if (pipeline.Count() > 0) + { + item.PipelineId = pipeline.First().PipelineId; + PipeArea = pipeline.First().PipeArea; + } + else + { + result.Add("不存在此管线号-" + pds[i].A.ToString()); + + } + + } + else + { + result.Add((i + 2) + "Line, [管线号] 不能为空
"); + } + + + if (pds[i].C != null && !string.IsNullOrEmpty(pds[i].C.ToString())) + { + string materialCode = pds[i].C.ToString(); + var lib = from x in Funs.DB.HJGL_MaterialCodeLib where x.MaterialCode == materialCode select x; + if (lib.Count() > 0) + { + item.MaterialCode = pds[i].C.ToString(); + } + else + { + result.Add("不存在此材料编码-" + pds[i].C.ToString()); + + } + + } + else + { + result.Add((i + 2) + "Line, [材料编码] 不能为空
"); + } + + if (pds[i].D != null && !string.IsNullOrEmpty(pds[i].D.ToString())) + { + try + { + var number = Funs.GetNewDecimal(pds[i].D.ToString()); + item.Number = number; + } + catch (Exception) + { + result.Add("第" + (i + 2).ToString() + "行," + "数量格式输入有误
"); + } + + } + else + { + result.Add((i + 2) + "Line, [数量] 不能为空
"); + } + + if (PipeArea == "1") + { + if (pds[i].B != null && !string.IsNullOrEmpty(pds[i].B.ToString())) + { + item.PrefabricatedComponents = pds[i].B.ToString(); + + } + else + { + result.Add((i + 2) + "Line, [预制组件] 不能为空
"); + } + } + var model = matList.Where(x => x.PipelineId == item.PipelineId && x.MaterialCode == item.MaterialCode && x.PrefabricatedComponents == item.PrefabricatedComponents); + if (model.Count() == 0) + { + matList.Add(item); + + } + + #endregion + } + + } + else + { + responeData.code = 0; + responeData.message = "导入数据为空!"; + } + + return responeData; } #endregion @@ -344,7 +462,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage return; } string IsXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower(); - if (IsXls != ".xls" && IsXls != ".xlsx") + if (IsXls != ".xlsx") { ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning); return; @@ -365,26 +483,14 @@ namespace FineUIPro.Web.HJGL.WeldingManage //文件上传服务器后的名称 string fileName = rootPath + initPath + this.hdFileName.Text; //读取Excel - DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true); - - //验证Excel读取是否有误 - if (!string.IsNullOrEmpty(errorInfos)) - { - Alert alert = new Alert - { - Message = errorInfos, - Target = Target.Self - }; - alert.Show(); - //ShowNotify(errorInfos, MessageBoxIcon.Warning); - return; - } - var reposedata= AddDatasetToSQL(ds.Tables[0], 4); + var ds = MiniExcel.Query(fileName).ToList(); + var columns = MiniExcel.GetColumns(fileName); + var cnt = columns.Count; + var reposedata = AddDatasetToSQL(ds, cnt); if (reposedata.code == 1) { State = (int)ButtonState.Import; ShowNotify("审核完成请点击导入"); - } else { @@ -394,7 +500,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage Target = Target.Self }; alert.Show(); - //ShowNotify(reposedata.message); + //ShowNotify(reposedata.message); } } #region 导入