配方清单申请增加配方清单导出

master
Leo 2 years ago
parent 09f4e642b3
commit 21c3ba5cdc

@ -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);
}
/// <summary>
/// 导出申请配方列表
/// </summary>
/// <param name="inParam"></param>
/// <returns></returns>
[HttpPost]
public ApiResult ExportFormulaApplyInfo(Dictionary<string, object> 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<Dictionary<string, object>> bomList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(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<TFS_Formula> 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 内部方法
/// <summary>

@ -294,6 +294,7 @@
<Content Include="File\Material\副产物导入模板.xlsx" />
<Content Include="File\Material\替代料导入模板.xlsx" />
<Content Include="File\Material\物料信息补全导入模板.xlsx" />
<Content Include="File\Formula\配方申请模板.xlsx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

@ -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<Dictionary<string, object>> 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;
}
}
}

Loading…
Cancel
Save