using iWareCC.Common;
using iWareCommon.Utils;
using iWareSql.MyDbContext;
using iWareTestForm.Model;
using OfficeOpenXml;
using OfficeOpenXml.Drawing;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace autuPrint.printService
{
public class CreatExcelForCheckStatsus
{
///
/// //线程锁防止并发
///
private static Mutex single = new Mutex();
///
/// 生成打印数据源
///
/// 条形码
/// 标签参数
/// 成功返回true
public static bool creatEXcel(List dataList, ref string realFilePath, ref string readFolderPath, ref string errMsg)
{
if (single.WaitOne())//增加线程锁防止双击并发
{
try
{
//获取模板文件
readFolderPath = SystemValueUtil.TEMPORARY_MAILWARNING_DIR;
realFilePath = SystemValueUtil.TEMPORARY_MAILWARNING_DIR + @"\SAP和WMS比对质检报告(" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ").xlsx";
FileInfo copyFile = new FileInfo(SystemValueUtil.SAP和WMS比对质检报告模板);
copyFile.CopyTo(realFilePath, true);
FileInfo existingFile = new FileInfo(realFilePath);
using (ExcelPackage package = new ExcelPackage(existingFile))
{
//获取模板内容
ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
//行,列
//注意:行和列都是从1开始,而不是从0开始!!!
for (int i = 0; i < (dataList.Count); i++)
{
worksheet.Cells[i + 2, 1].Value = dataList[i].Type;
worksheet.Cells[i + 2, 2].Value = dataList[i].WMS_Type;
worksheet.Cells[i + 2, 3].Value = dataList[i].OrderNo;
worksheet.Cells[i + 2, 4].Value = dataList[i].LineNumber;
worksheet.Cells[i + 2, 5].Value = dataList[i].Material;
worksheet.Cells[i + 2, 6].Value = dataList[i].MaterialDescription;
worksheet.Cells[i + 2, 7].Value = dataList[i].Qty;
worksheet.Cells[i + 2, 8].Value = dataList[i].HasReciveQty;
worksheet.Cells[i + 2, 9].Value = dataList[i].WMS_Qty;
worksheet.Cells[i + 2, 10].Value = dataList[i].WMS_HasReciveQty;
worksheet.Cells[i + 2, 11].Value = dataList[i].AnalysisResult;
worksheet.Cells[i + 2, 12].Value = dataList[i].Remark;
worksheet.Cells[i + 2, 13].Value = dataList[i].Remark2;
}
package.Save();//保存
}
}
catch (Exception ex)
{
Log4NetHelper.WriteErrorLog(LogType.SrmTheadService, "类名: creatExcelPrint 方法名: creatEXcel 生成打印文件出错 \r\n " + ex.ToString(), ex);
//logtxt.txtWrite("类名: creatExcelPrint 方法名: creatEXcel 生成打印文件出错 \r\n " + ex.ToString(), 2);
errMsg = ex.Message;
return false;
}
finally { single.ReleaseMutex(); }//一轮结束
}
return true;
}
}
}