diff --git a/SGGL/BLL/CLGL/TwInOutplandetailService.cs b/SGGL/BLL/CLGL/TwInOutplandetailService.cs
index aec9d136..5bfbeea7 100644
--- a/SGGL/BLL/CLGL/TwInOutplandetailService.cs
+++ b/SGGL/BLL/CLGL/TwInOutplandetailService.cs
@@ -44,8 +44,8 @@ namespace BLL
PipelineComponentId = x.PipelineComponentId,
MaterialCode = x.MaterialCode,
Code = mat.Code,
- HeatNo = x.HeatNo,
- BatchNo = x.BatchNo,
+ HeatNo = mat.HeatNo,
+ BatchNo = mat.BatchNo,
PlanNum = x.PlanNum,
ActNum = x.ActNum,
PipelineComponentCode = y.PipelineComponentCode,
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx
new file mode 100644
index 00000000..30c3784e
--- /dev/null
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx
@@ -0,0 +1,93 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OutPlanMasterDetailImport.aspx.cs" Inherits="FineUIPro.Web.CLGL.OutPlanMasterDetailImport" %>
+
+
+
+
+
+
+ 出库明细导入
+
+
+
+
+
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.cs b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.cs
new file mode 100644
index 00000000..b4dfc24c
--- /dev/null
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.cs
@@ -0,0 +1,372 @@
+using BLL;
+using MiniExcelLibs;
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.IO;
+using System.Linq;
+
+namespace FineUIPro.Web.CLGL
+{
+ public partial class OutPlanMasterDetailImport : PageBase
+ {
+ private readonly string initPath = Const.ExcelUrl;
+
+ public static List ImportDetailList = new List();
+
+ public static string errorInfos = string.Empty;
+
+ public string Id
+ {
+ get
+ {
+ return (string)ViewState["Id"];
+ }
+ set
+ {
+ ViewState["Id"] = value;
+ }
+ }
+
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ if (!IsPostBack)
+ {
+ hdFileName.Text = string.Empty;
+ Id = Request.QueryString["Id"];
+ ImportDetailList.Clear();
+ errorInfos = string.Empty;
+ }
+ }
+
+ protected void btnAudit_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (fuAttachUrl.HasFile == false)
+ {
+ ShowNotify("请您选择Excel文件!", MessageBoxIcon.Warning);
+ return;
+ }
+
+ string isXls = Path.GetExtension(fuAttachUrl.FileName).Trim().ToLower();
+ if (isXls != ".xlsx")
+ {
+ ShowNotify("只可以选择Excel文件!", MessageBoxIcon.Warning);
+ return;
+ }
+
+ ImportDetailList.Clear();
+ errorInfos = string.Empty;
+
+ string rootPath = Server.MapPath("~/");
+ string initFullPath = rootPath + initPath;
+ if (!Directory.Exists(initFullPath))
+ {
+ Directory.CreateDirectory(initFullPath);
+ }
+
+ hdFileName.Text = Funs.GetNewFileName() + isXls;
+ string filePath = initFullPath + hdFileName.Text;
+ fuAttachUrl.PostedFile.SaveAs(filePath);
+ ImportXlsToData(filePath);
+ }
+ catch (Exception ex)
+ {
+ Alert alert = new Alert
+ {
+ Message = "'" + ex.Message + "'",
+ Target = Target.Self
+ };
+ alert.Show();
+ }
+ }
+
+ private void ImportXlsToData(string fileName)
+ {
+ DataTable rows = MiniExcel.QueryAsDataTable(fileName, useHeaderRow: true);
+ ResponeData responeData = AddDataTableToImportList(rows);
+ if (responeData.code == 1)
+ {
+ ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
+ }
+ else
+ {
+ Alert alert = new Alert
+ {
+ Message = responeData.message,
+ Target = Target.Self
+ };
+ alert.Show();
+ }
+ }
+
+ private ResponeData AddDataTableToImportList(DataTable table)
+ {
+ ResponeData responeData = new ResponeData();
+ List result = new List();
+ List importItems = new List();
+
+ if (table == null || table.Rows.Count == 0)
+ {
+ responeData.code = 0;
+ responeData.message = "导入数据为空!";
+ return responeData;
+ }
+
+ string[] requiredColumns = { "材料编码", "炉号", "批号", "计划数量" };
+
+ foreach (string columnName in requiredColumns)
+ {
+ if (!table.Columns.Contains(columnName))
+ {
+ responeData.code = 0;
+ responeData.message = "导入Excel格式错误!模板列必须包含:" + string.Join("、", requiredColumns);
+ return responeData;
+ }
+ }
+
+ Tw_InOutPlanMaster master = TwInOutplanmasterService.GetById(Id);
+ if (master == null)
+ {
+ responeData.code = 0;
+ responeData.message = "请先保存出库单后再导入明细!";
+ return responeData;
+ }
+ if (master.TypeInt != (int)TwConst.TypeInt.其他出库)
+ {
+ responeData.code = 0;
+ responeData.message = "只有选择其他出库时才允许导入出库明细!";
+ return responeData;
+ }
+ List stockList = GetSelectableStockList(master);
+
+ for (int i = 0; i < table.Rows.Count; i++)
+ {
+ string code = GetCellValue(table.Rows[i], "材料编码");
+ string heatNo = GetCellValue(table.Rows[i], "炉号");
+ string batchNo = GetCellValue(table.Rows[i], "批号");
+ string planNumText = GetCellValue(table.Rows[i], "计划数量");
+
+ if (string.IsNullOrEmpty(code) && string.IsNullOrEmpty(heatNo) && string.IsNullOrEmpty(batchNo) && string.IsNullOrEmpty(planNumText))
+ {
+ continue;
+ }
+
+ if (string.IsNullOrEmpty(code))
+ {
+ result.Add("第" + (i + 2).ToString() + "行,材料编码,此项为必填项!");
+ continue;
+ }
+ if (string.IsNullOrEmpty(heatNo))
+ {
+ result.Add("第" + (i + 2).ToString() + "行,炉号,此项为必填项!");
+ continue;
+ }
+ if (string.IsNullOrEmpty(batchNo))
+ {
+ result.Add("第" + (i + 2).ToString() + "行,批号,此项为必填项!");
+ continue;
+ }
+
+ decimal planNum;
+ if (!decimal.TryParse(planNumText, out planNum) || planNum <= 0)
+ {
+ result.Add("第" + (i + 2).ToString() + "行,计划数量,请输入大于0的数字!");
+ continue;
+ }
+
+ Tw_MaterialStockOutput stock = stockList.FirstOrDefault(x => x.Code == code && x.HeatNo == heatNo && x.BatchNo == batchNo);
+ if (stock == null)
+ {
+ result.Add("第" + (i + 2).ToString() + "行,当前仓库可选库存中不存在此材料编码/炉号/批号-" + code + "/" + heatNo + "/" + batchNo);
+ continue;
+ }
+
+ importItems.Add(new OutPlanDetailImportItem
+ {
+ MaterialCode = stock.PipeLineMatCode,
+ Code = stock.Code,
+ HeatNo = stock.HeatNo,
+ BatchNo = stock.BatchNo,
+ PlanNum = planNum,
+ MaterialName = stock.MaterialName,
+ MaterialDef = stock.MaterialDef
+ });
+ }
+
+ if (result.Count > 0)
+ {
+ ImportDetailList.Clear();
+ errorInfos = string.Join("|", result.Distinct());
+ responeData.code = 0;
+ responeData.message = errorInfos;
+ return responeData;
+ }
+
+ ImportDetailList = importItems.GroupBy(x => x.MaterialCode).Select(x =>
+ {
+ OutPlanDetailImportItem item = x.First();
+ item.PlanNum = x.Sum(y => y.PlanNum);
+ return item;
+ }).ToList();
+
+ errorInfos = string.Empty;
+ responeData.code = ImportDetailList.Count > 0 ? 1 : 0;
+ responeData.message = ImportDetailList.Count > 0 ? string.Empty : "导入数据为空!";
+ return responeData;
+ }
+
+ protected void btnImport_Click(object sender, EventArgs e)
+ {
+ if (!string.IsNullOrEmpty(errorInfos))
+ {
+ ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
+ return;
+ }
+
+ if (string.IsNullOrEmpty(hdFileName.Text))
+ {
+ ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
+ return;
+ }
+
+ Grid1.DataSource = ImportDetailList;
+ Grid1.DataBind();
+ Grid1.RecordCount = ImportDetailList.Count;
+ }
+
+ protected void btnSave_Click(object sender, EventArgs e)
+ {
+ if (!string.IsNullOrEmpty(errorInfos))
+ {
+ ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
+ return;
+ }
+
+ SaveStockDetails();
+
+ string rootPath = Server.MapPath("~/");
+ string filePath = rootPath + initPath + hdFileName.Text;
+ if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
+ {
+ File.Delete(filePath);
+ }
+ ShowNotify("导入成功!", MessageBoxIcon.Success);
+ PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
+ }
+
+ private void SaveStockDetails()
+ {
+ foreach (OutPlanDetailImportItem item in ImportDetailList)
+ {
+ Tw_InOutDetailOutput queryDetail = new Tw_InOutDetailOutput()
+ {
+ InOutPlanMasterId = Id,
+ MaterialCode = item.MaterialCode
+ };
+ Tw_InOutDetailOutput detailOutput = TwInOutplandetailService.GetByModle(queryDetail).FirstOrDefault();
+ if (detailOutput == null)
+ {
+ Tw_InOutPlanDetail newDetail = new Tw_InOutPlanDetail
+ {
+ Id = SQLHelper.GetNewID(),
+ InOutPlanMasterId = Id,
+ MaterialCode = item.MaterialCode,
+ PlanNum = item.PlanNum
+ };
+ TwInOutplandetailService.Add(newDetail);
+ }
+ else
+ {
+ Tw_InOutPlanDetail detail = TwInOutplandetailService.GetById(detailOutput.Id);
+ detail.PlanNum = item.PlanNum;
+ TwInOutplandetailService.Update(detail);
+ }
+ }
+ }
+
+ protected void btnDownLoad_Click(object sender, EventArgs e)
+ {
+ string rootPath = Server.MapPath("~/");
+ string tempDirectory = rootPath + @"File\Excel\Temp\";
+ if (!Directory.Exists(tempDirectory))
+ {
+ Directory.CreateDirectory(tempDirectory);
+ }
+
+ string tempPath = tempDirectory + "出库明细导入模板" + string.Format("{0:yyyyMMddHHmmss}", DateTime.Now) + ".xlsx";
+ DataTable template = new DataTable();
+ template.Columns.Add("材料编码");
+ template.Columns.Add("炉号");
+ template.Columns.Add("批号");
+ template.Columns.Add("计划数量");
+ MiniExcel.SaveAs(tempPath, template);
+
+ FileInfo info = new FileInfo(tempPath);
+ long fileSize = info.Length;
+ Response.ClearContent();
+ Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("出库明细导入模板.xlsx", System.Text.Encoding.UTF8));
+ Response.ContentType = "excel/plain";
+ Response.ContentEncoding = System.Text.Encoding.UTF8;
+ Response.AddHeader("Content-Length", fileSize.ToString().Trim());
+ Response.TransmitFile(tempPath, 0, fileSize);
+ Response.Flush();
+ Response.Close();
+ File.Delete(tempPath);
+ }
+
+ protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
+ Grid1.DataSource = ImportDetailList;
+ Grid1.DataBind();
+ Grid1.RecordCount = ImportDetailList.Count;
+ }
+
+ private List GetSelectableStockList(Tw_InOutPlanMaster master)
+ {
+ Tw_MaterialStockOutput stockQuery = new Tw_MaterialStockOutput();
+ stockQuery.WarehouseCode = master.WarehouseCode;
+ stockQuery.ProjectId = CurrUser.LoginProjectId;
+ stockQuery.MaterialUnit = GetRequiredMaterialUnit(master.Category);
+ return TwMaterialstockService.GetTw_MaterialStockByModle(stockQuery);
+ }
+
+ private string GetRequiredMaterialUnit(int? category)
+ {
+ if (category == (int)TwConst.Category.管段)
+ {
+ return "米";
+ }
+ if (category == (int)TwConst.Category.管件)
+ {
+ return "个";
+ }
+ return string.Empty;
+ }
+
+ private string GetCellValue(DataRow row, string columnName)
+ {
+ return Convert.ToString(row[columnName]).Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Trim();
+ }
+
+ public class OutPlanDetailImportItem
+ {
+ public string MaterialCode { get; set; }
+
+ public string Code { get; set; }
+
+ public string HeatNo { get; set; }
+
+ public string BatchNo { get; set; }
+
+ public decimal PlanNum { get; set; }
+
+ public string MaterialName { get; set; }
+
+ public string MaterialDef { get; set; }
+ }
+ }
+}
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.designer.cs b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.designer.cs
new file mode 100644
index 00000000..b0c1f46a
--- /dev/null
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterDetailImport.aspx.designer.cs
@@ -0,0 +1,143 @@
+//------------------------------------------------------------------------------
+// <自动生成>
+// 此代码由工具生成。
+//
+// 对此文件的更改可能导致不正确的行为,如果
+// 重新生成代码,则所做更改将丢失。
+// 自动生成>
+//------------------------------------------------------------------------------
+
+namespace FineUIPro.Web.CLGL
+{
+
+
+ public partial class OutPlanMasterDetailImport
+ {
+
+ ///
+ /// form1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::System.Web.UI.HtmlControls.HtmlForm form1;
+
+ ///
+ /// PageManager1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.PageManager PageManager1;
+
+ ///
+ /// SimpleForm1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Form SimpleForm1;
+
+ ///
+ /// Toolbar2 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Toolbar Toolbar2;
+
+ ///
+ /// hdFileName 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.HiddenField hdFileName;
+
+ ///
+ /// btnDownLoad 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Button btnDownLoad;
+
+ ///
+ /// btnAudit 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Button btnAudit;
+
+ ///
+ /// btnImport 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Button btnImport;
+
+ ///
+ /// btnSave 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Button btnSave;
+
+ ///
+ /// fuAttachUrl 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.FileUpload fuAttachUrl;
+
+ ///
+ /// Grid1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Grid Grid1;
+
+ ///
+ /// ToolbarSeparator1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.ToolbarSeparator ToolbarSeparator1;
+
+ ///
+ /// ToolbarText1 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.ToolbarText ToolbarText1;
+
+ ///
+ /// ddlPageSize 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.DropDownList ddlPageSize;
+ }
+}
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx
index f3b0c768..573b74d9 100644
--- a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx
@@ -119,6 +119,9 @@
+
+
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.cs b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.cs
index 44ac50eb..60204057 100644
--- a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.cs
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.cs
@@ -141,6 +141,12 @@ namespace FineUIPro.Web.CLGL
Save(Const.BtnSave);
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OutPlanMasterSelectStock.aspx?UnitWorkId={0}&Id={1}", UnitWorkId, Id, "选择- ")));
+ }
+ protected void btnImportStock_Click(object sender, EventArgs e)
+ {
+ Save(Const.BtnSave);
+ PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OutPlanMasterDetailImport.aspx?Id={0}", Id, "导入- ")));
+
}
#endregion
@@ -309,4 +315,4 @@ namespace FineUIPro.Web.CLGL
}
}
}
-}
\ No newline at end of file
+}
diff --git a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.designer.cs b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.designer.cs
index e6d64105..bbd4432a 100644
--- a/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.designer.cs
+++ b/SGGL/FineUIPro.Web/CLGL/OutPlanMasterEdit.aspx.designer.cs
@@ -221,6 +221,15 @@ namespace FineUIPro.Web.CLGL
///
protected global::FineUIPro.Button btnSelectStock;
+ ///
+ /// btnImportStock 控件。
+ ///
+ ///
+ /// 自动生成的字段。
+ /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
+ ///
+ protected global::FineUIPro.Button btnImportStock;
+
///
/// nbPlanNum 控件。
///
diff --git a/SGGL/FineUIPro.Web/FineUIPro.Web.csproj b/SGGL/FineUIPro.Web/FineUIPro.Web.csproj
index ae434ca2..1ef4c204 100644
--- a/SGGL/FineUIPro.Web/FineUIPro.Web.csproj
+++ b/SGGL/FineUIPro.Web/FineUIPro.Web.csproj
@@ -351,6 +351,7 @@
+
@@ -8209,6 +8210,13 @@
OutPlanMaster.aspx
+
+ OutPlanMasterDetailImport.aspx
+ ASPXCodeBehind
+
+
+ OutPlanMasterDetailImport.aspx
+
OutPlanMasterEdit.aspx
ASPXCodeBehind
@@ -17192,4 +17200,4 @@
-->
-
\ No newline at end of file
+