public ActionResult SubmitInput() { StringBuilder errorMsg = new StringBuilder(); // 错误信息 try { //HttpPostedFileBase fostFile = Request.Files["Filedata"]; //Stream streamfile = fostFile.InputStream; //string exName = Path.GetExtension(fostFile.FileName); //得到扩展名 var fostFile = Request.Files; Stream streamfile = fostFile[0].InputStream; string exName = Path.GetExtension(fostFile[0].FileName); //得到扩展名 Dictionary <string, string> cellheader = new Dictionary <string, string> { { "ComponentName", "构件名称" }, { "LargePattern", "大样图" }, { "MaterialCode", "原材料编号" }, { "MaterialName", "原材料名称" }, { "SpecificationModel", "规格" }, { "MeasurementUnitText", "计量单位" }, { "MeasurementUnitZl", "单位重量" }, { "ItemUseNum", "单件用量" }, { "Number", "件数" }, { "WeightSmallPlan", "重量小计" }, { "SkillRequirement", "技术要求" }, { "ProcessingTechnologyName", "加工工艺" }, { "Remark", "备注" }, }; var dataList = ExcelHelper.ExcelToEntityList <TbWorkOrderDetail>(cellheader, streamfile, exName, out errorMsg); List <TbWorkOrderDetail> list1 = new List <TbWorkOrderDetail>(); if (dataList.Count > 0) { list1.AddRange(dataList); for (int i = 0; i < dataList.Count; i++) { //去掉Excel中的空白行 if (dataList[i].ComponentName == null && dataList[i].LargePattern == null && dataList[i].SpecificationModel == null && dataList[i].ProcessingTechnologyName == null && dataList[i].Number == 0 && dataList[i].ItemUseNum == 0 && dataList[i].MeasurementUnitZl == 0) { list1.Remove(dataList[i]); } } } var retList = new List <TbWorkOrderDetail>(); TbRawMaterialMonthDemandPlanLogic _rawMonthDemPlanLogic = new TbRawMaterialMonthDemandPlanLogic(); //所有原材料档案 var rawAllMaterials = Repository <TbRawMaterialArchives> .GetAll().ToList(); //单位 var unit = Repository <TbSysDictionaryData> .Query(p => p.FDictionaryCode == "Unit"); var index = 1; foreach (var item in list1) { index++; if (string.IsNullOrWhiteSpace(item.ComponentName)) { errorMsg.AppendFormat("第{0}行构件名称不能为空!</br>", index); continue; } if (string.IsNullOrWhiteSpace(item.LargePattern)) { errorMsg.AppendFormat("第{0}行大样图不能为空!</br>", index); continue; } if (string.IsNullOrWhiteSpace(item.SpecificationModel)) { errorMsg.AppendFormat("第{0}行规格不能为空!</br>", index); continue; } else { //判断原材料是否存在 var rawMaterial = rawAllMaterials.Where(p => p.SpecificationModel == item.SpecificationModel).FirstOrDefault(); if (rawMaterial != null) { item.MaterialName = rawMaterial.MaterialName; item.MaterialCode = rawMaterial.MaterialCode; item.SpecificationModel = rawMaterial.SpecificationModel; item.MeasurementUnit = rawMaterial.MeasurementUnit; //if (item.MeasurementUnitZl != rawMaterial.MeasurementUnitZl) //{ // errorMsg.AppendFormat("第{0}行规格的原材料的单位重量不正确!</br>", index); // continue; //} //原材料单位 var rawUnit = unit.FirstOrDefault(p => p.DictionaryCode == rawMaterial.MeasurementUnit); item.MeasurementUnitText = rawUnit.DictionaryText; } else { errorMsg.AppendFormat("第{0}行规格的原材料不存在!</br>", index); continue; } } if (string.IsNullOrWhiteSpace(item.MeasurementUnitZl.ToString())) { errorMsg.AppendFormat("第{0}行规格的原材料的单位重量不能为空!</br>", index); continue; } else { if (item.MeasurementUnitZl <= 0) { errorMsg.AppendFormat("第{0}行规格的原材料的单位重量不正确!</br>", index); continue; } } //单件用量 if (string.IsNullOrWhiteSpace(item.ItemUseNum.ToString())) { errorMsg.AppendFormat("第{0}行单件用量不能为空!</br>", index); continue; } else { if (item.ItemUseNum <= 0) { errorMsg.AppendFormat("第{0}行单件用量必须大于0!</br>", index); continue; } } //件数 if (string.IsNullOrWhiteSpace(item.Number.ToString())) { errorMsg.AppendFormat("第{0}行件数不能为空!</br>", index); continue; } else { if (item.Number <= 0) { errorMsg.AppendFormat("第{0}行件数必须大于0!</br>", index); continue; } } //重量小计 if (string.IsNullOrWhiteSpace(item.WeightSmallPlan.ToString())) { errorMsg.AppendFormat("第{0}行重量小计不能为空!</br>", index); continue; } else { //判断重量小计是否正确 if (item.WeightSmallPlan <= 0) { errorMsg.AppendFormat("第{0}行重量小计不正确!</br>", index); continue; } else { if (item.WeightSmallPlan != (item.MeasurementUnitZl * item.Number * item.ItemUseNum)) { errorMsg.AppendFormat("第{0}行重量小计不正确!</br>", index); continue; } } } #region 加工工艺 if (string.IsNullOrWhiteSpace(item.ProcessingTechnologyName)) { errorMsg.AppendFormat("第{0}行加工工艺不能为空!</br>", index); continue; } else { var pt = Repository <TbProcessingTechnology> .First(p => p.ProcessingTechnologyName == item.ProcessingTechnologyName && p.PID != 0); if (pt != null) { item.ProcessingTechnologyName = pt.ProcessingTechnologyName; item.ProcessingTechnology = pt.ID; } else { errorMsg.AppendFormat("第{0}行加工工艺在系统中不存在!</br>", index); continue; } } #endregion item.ComponentName = item.ComponentName.Replace(" ", ""); item.LargePattern = item.LargePattern.Replace(" ", ""); item.MaterialCode = item.MaterialCode.Replace(" ", ""); item.MaterialName = item.MaterialName.Replace(" ", ""); item.MeasurementUnitZl = Convert.ToDecimal(item.MeasurementUnitZl.ToString().Replace(" ", "")); item.ItemUseNum = Convert.ToDecimal(item.ItemUseNum.ToString().Replace(" ", "")); item.Number = Convert.ToInt32(item.Number.ToString().Replace(" ", "")); item.WeightSmallPlan = Convert.ToDecimal(item.WeightSmallPlan.ToString("f5").Replace(" ", "")); item.DaetailWorkStrat = "未加工"; item.RevokeStart = "正常"; item.PackNumber = 0; item.PackageNumber = 0; retList.Add(item); } if (errorMsg.Length > 0) { return(JsonMsg(false, retList, errorMsg.ToString())); } else { return(JsonMsg(true, retList)); } } catch (Exception ex) { return(JsonMsg(false, ex.ToString())); } }
public ActionResult SubmitInput() { TbRawMaterialMonthDemandPlanLogic _rawMonthDemPlanLogic = new TbRawMaterialMonthDemandPlanLogic(); StringBuilder errorMsg = new StringBuilder(); // 错误信息 try { //HttpPostedFileBase fostFile = Request.Files["Filedata"]; //Stream streamfile = fostFile.InputStream; //string exName = Path.GetExtension(fostFile.FileName); //得到扩展名 var fostFile = Request.Files; Stream streamfile = fostFile[0].InputStream; string exName = Path.GetExtension(fostFile[0].FileName); //得到扩展名 Dictionary <string, string> cellheader = new Dictionary <string, string> { { "MaterialCode", "原材料编号" }, { "MaterialName", "原材料名称" }, { "SpecificationModel", "规格型号" }, { "RebarType", "钢筋类型" }, { "MeasurementUnit", "单位" }, { "MeasurementUnitZl", "单位重量" }, { "Remarks", "备注" }, }; var dataList = ExcelHelper.ExcelToEntityList <TbRawMaterialArchives>(cellheader, streamfile, exName, out errorMsg); var retList = new List <TbRawMaterialArchives>(); var index = 1; var projectId = base.CurrentUser.ProjectId; foreach (var item in dataList) { index++; if (string.IsNullOrWhiteSpace(item.MaterialCode)) { errorMsg.AppendFormat("第{0}行原材料编号不能为空!", index); continue; } if (string.IsNullOrWhiteSpace(item.MaterialName)) { errorMsg.AppendFormat("第{0}行原材料名称不能为空!", index); continue; } if (string.IsNullOrWhiteSpace(item.SpecificationModel)) { errorMsg.AppendFormat("第{0}行材料规格型号不能为空!", index); continue; } if (string.IsNullOrWhiteSpace(item.RebarType)) { errorMsg.AppendFormat("第{0}行钢筋类型不能为空!", index); continue; } //查询单位编号 DataTable data1 = _rawMonthDemPlanLogic.GetUnitCode("RebarType", item.RebarType); if (data1 != null && data1.Rows.Count > 0) { item.RebarType = data1.Rows[0][0].ToString(); } else { errorMsg.AppendFormat("第{0}行钢筋类型错误,钢筋类型只能为型钢或者是建筑钢筋!", index, item.RebarType); continue; } if (item.MeasurementUnitZl <= 0) { errorMsg.AppendFormat("第{0}行单位重量不能小于0!", index); continue; } if (string.IsNullOrWhiteSpace(item.MeasurementUnit)) { errorMsg.AppendFormat("第{0}行单位不能为空!", index); continue; } //查询单位编号 DataTable data2 = _rawMonthDemPlanLogic.GetUnitCode("Unit", item.MeasurementUnit); if (data2 != null && data2.Rows.Count > 0) { item.MeasurementUnit = data2.Rows[0][0].ToString(); } else { errorMsg.AppendFormat("第{0}行单位,在系统中不存在,请先完善系统中数据字典信息!", index, item.MeasurementUnit); continue; } var iindex = 1; var flag = false; foreach (var tep in dataList) { flag = false; iindex++; if (item.MaterialCode == tep.MaterialCode && index != iindex && index < iindex) { errorMsg.AppendFormat("第{0}行与第{1}行信息重复!", index, iindex); break; } flag = true; } if (!flag) { continue; } Convert.ToString(item.MaterialCode).Trim(); Convert.ToString(item.MaterialName).Trim(); Convert.ToString(item.SpecificationModel); Convert.ToString(item.MeasurementUnit).Trim(); Convert.ToDecimal(item.MeasurementUnitZl); Convert.ToString(item.RebarType); Convert.ToString(item.Remarks); item.IndexNum = index; retList.Add(item); } if (retList.Count > 0) { return(Content(_rawArchivesImp.Input(retList, errorMsg).ToJson())); } else { return(Error(errorMsg.ToString())); } } catch (Exception ex) { return(Error(ex.ToString())); } }