diff --git a/FactorySystemApi/Controllers/FormulaController.cs b/FactorySystemApi/Controllers/FormulaController.cs
index e73ad25..1337332 100644
--- a/FactorySystemApi/Controllers/FormulaController.cs
+++ b/FactorySystemApi/Controllers/FormulaController.cs
@@ -12,6 +12,8 @@ using System.Web.Http;
using FactorySystemModel.EnumModel;
using FactorySystemModel.RequestModel;
using FactorySystemApi.Plm_Formula;
+using System.Web.UI.WebControls;
+using Newtonsoft.Json;
namespace FactorySystemApi.Controllers
{
@@ -405,6 +407,64 @@ namespace FactorySystemApi.Controllers
}, apiResult, Request);
}
+ ///
+ /// 导出申请配方列表
+ ///
+ ///
+ ///
+ [HttpPost]
+ public ApiResult ExportFormulaApplyInfo(Dictionary inParam)
+ {
+ ApiResult apiResult = new ApiResult();
+ ApiAuthInfo user = Request.Properties["token"] as ApiAuthInfo;
+ string rootPath = System.Web.Hosting.HostingEnvironment.MapPath("/");
+ string savePath = "/File/Temp/配方清单/工艺样品生产记录表_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
+
+ return ExceptionHelper.TryReturnException(() =>
+ {
+ if (inParam != null && inParam.ContainsKey("bomList"))
+ {
+ inParam.TryGetValue("bomList", out object bomObj);
+ List> bomList = JsonConvert.DeserializeObject>>(JsonConvert.SerializeObject(bomObj));
+
+ inParam.TryGetValue("FID", out object oFid);
+
+ string sFid = oFid != null ? oFid.ToString() : "-1";
+ int nFid = 0;
+ int.TryParse(sFid, out nFid);
+
+ string testCode = "";
+ string userName = user.FName;
+ string productNumber = "";
+ string productName = "";
+ string applyTime = DateTime.Now.ToString("yyyy-MM-dd");
+
+ List formulaList = FormulaBll.GetFormulaListById(nFid);
+ if (formulaList != null && formulaList.Count > 0)
+ {
+ TFS_Formula formula = formulaList[0];
+ testCode = formula.FTestCode;
+ productName = formula.FName;
+ }
+
+ bool exportResult = NPOIHelper.ExportBomlist(rootPath + "/File/Formula/配方申请模板.xlsx", rootPath + savePath, testCode, userName, productNumber, productName, applyTime, bomList);
+
+ if (exportResult)
+ {
+ apiResult.Data = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, "").Trim('/') + savePath;
+ }
+ else
+ {
+ apiResult.Data = "";
+ }
+ }
+ else
+ {
+ apiResult.Data = "";
+ }
+ }, apiResult, Request);
+ }
+
#region 内部方法
///
diff --git a/FactorySystemApi/FactorySystemApi.csproj b/FactorySystemApi/FactorySystemApi.csproj
index 0c742b2..5731a00 100644
--- a/FactorySystemApi/FactorySystemApi.csproj
+++ b/FactorySystemApi/FactorySystemApi.csproj
@@ -294,6 +294,7 @@
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/FactorySystemApi/File/Formula/配方申请模板.xlsx b/FactorySystemApi/File/Formula/配方申请模板.xlsx
new file mode 100644
index 0000000..3a0ae2a
Binary files /dev/null and b/FactorySystemApi/File/Formula/配方申请模板.xlsx differ
diff --git a/FactorySystemCommon/NPOIHelper.cs b/FactorySystemCommon/NPOIHelper.cs
index 08315b4..7d06eed 100644
--- a/FactorySystemCommon/NPOIHelper.cs
+++ b/FactorySystemCommon/NPOIHelper.cs
@@ -1514,5 +1514,104 @@ namespace FactorySystemCommon
}
return false;
}
+
+ public static bool ExportBomlist(string templatePath, string savePath, string testCode, string userName, string productNumber, string productName, string applyTime, List> bomList)
+ {
+ bool status = false;
+
+ if (!File.Exists(templatePath))
+ {
+ status = false;
+ }
+
+ FileStream templateFile = new FileStream(templatePath, FileMode.Open, FileAccess.Read);
+ FileStream saveFile = new FileStream(savePath, FileMode.Create);
+
+ try
+ {
+ IWorkbook workbook = null;
+ workbook = new XSSFWorkbook(templateFile);
+
+ ISheet sheetBomList = workbook.GetSheetAt(0);
+ ISheet sheetApplyHistory = workbook.GetSheetAt(1);
+
+ IRow row = sheetBomList.GetRow(2);
+
+ // 试验号
+ ICell testCodeCell = row.GetCell(1);
+ testCodeCell.SetCellValue(testCode);
+
+ // 技术人员
+ ICell userNameCell = row.GetCell(6);
+ userNameCell.SetCellValue(userName);
+
+ // 生产数量(g)
+ ICell productNumberCell = row.GetCell(8);
+ productNumberCell.SetCellValue(productNumber);
+
+ row = sheetBomList.GetRow(4);
+
+ // 产品名称
+ ICell productNameCell = row.GetCell(1);
+ productNameCell.SetCellValue(productName);
+
+ // 申请日期
+ ICell applyTimeCell = row.GetCell(8);
+ applyTimeCell.SetCellValue(applyTime);
+
+ if (bomList != null)
+ {
+ int newRowCount = bomList.Count;
+ int bomColumnCount = bomList[0].Count;
+
+ sheetBomList.ShiftRows(7, 10, newRowCount);
+ IRow tmpRow = sheetBomList.GetRow(7 + newRowCount);
+
+ ICell sourceCell = null;
+ ICell targetCell = null;
+
+ for (int rowNo=7; rowNo<7+newRowCount; rowNo++)
+ {
+ IRow targetRow = sheetBomList.CreateRow(rowNo);
+
+ for (int cellNo = tmpRow.FirstCellNum; cellNo < tmpRow.LastCellNum; cellNo++)
+ {
+ sourceCell = tmpRow.GetCell(cellNo);
+ if (sourceCell == null)
+ {
+ continue;
+ }
+ targetCell = targetRow.CreateCell(cellNo);
+ targetCell.CellStyle = sourceCell.CellStyle;
+ targetCell.SetCellType(sourceCell.CellType);
+ }
+
+ targetRow.GetCell(0).SetCellValue(bomList[rowNo - 7]["原料编号"].ToString());
+ targetRow.GetCell(1).SetCellValue(bomList[rowNo - 7]["SAP编号"].ToString());
+ targetRow.GetCell(2).SetCellValue(bomList[rowNo - 7]["原料名称"].ToString());
+ targetRow.GetCell(3).SetCellValue(bomList[rowNo - 7]["稀释液"].ToString());
+ targetRow.GetCell(4).SetCellValue(bomList[rowNo - 7]["稀释溶剂"].ToString());
+ targetRow.GetCell(5).SetCellValue(bomList[rowNo - 7]["标准数量"].ToString());
+ targetRow.GetCell(6).SetCellValue(bomList[rowNo - 7]["投料数量"].ToString());
+ targetRow.GetCell(7).SetCellValue(bomList[rowNo - 7]["备注"].ToString());
+ targetRow.GetCell(8).SetCellValue(bomList[rowNo - 7]["可替换香基"].ToString());
+ }
+ }
+
+ // 另存文件
+ workbook.Write(saveFile);
+ status = true;
+ }
+ catch {
+ status = false;
+ }
+ finally
+ {
+ templateFile.Close();
+ saveFile.Close();
+ }
+
+ return status;
+ }
}
}