public ActionResult Save(NameplatePrintViewModel model) { System.DateTime dateStartTime; System.DateTime dateEndTime; TimeSpan tSpan; string lotNumber = ""; MethodReturnResult result = new MethodReturnResult(); try { dateStartTime = System.DateTime.Now; dateEndTime = System.DateTime.Now; //获取批值。 lotNumber = model.LotNumber.ToUpper(); result = GetLot(lotNumber); if (result.Code > 0) { return(Json(result)); } Lot obj = (result as MethodReturnResult <Lot>).Data; //获取打印机名称 ClientConfig printer = null; if (!string.IsNullOrEmpty(model.PrinterName)) { using (ClientConfigServiceClient client = new ClientConfigServiceClient()) { MethodReturnResult <ClientConfig> rst = client.Get(model.PrinterName); if (rst.Code > 0) { return(Json(rst)); } printer = rst.Data; } } //获取打印条码内容 PrintLabel label = null; if (!string.IsNullOrEmpty(model.PrintLabelCode)) { using (PrintLabelServiceClient client = new PrintLabelServiceClient()) { MethodReturnResult <PrintLabel> rst = client.Get(model.PrintLabelCode); if (rst.Code > 0) { return(Json(rst)); } label = rst.Data; } } //获取IV测试数据及其对应的分档数据。 IVTestData ivtest = null; using (IVTestDataServiceClient client = new IVTestDataServiceClient()) { PagingConfig cfg = new PagingConfig() { IsPaging = false, Where = string.Format(@"Key.LotNumber='{0}' AND IsDefault=1" , model.LotNumber), OrderBy = "Key.TestTime Desc" }; MethodReturnResult <IList <IVTestData> > rst = client.Get(ref cfg); if (rst.Code > 0) { return(Json(rst)); } if (rst.Data.Count <= 0) { LogHelper.WriteLogInfo(string.Format("GetIVDataError>{0}IV测试数据不存在。", model.LotNumber)); rst.Message = string.Format("{0} IV测试数据不存在。", model.LotNumber); rst.Code = 1000; return(Json(rst)); } ivtest = rst.Data[0]; } //获取工单分档规则 WorkOrderPowerset wop = null; using (WorkOrderPowersetServiceClient client = new WorkOrderPowersetServiceClient()) { MethodReturnResult <WorkOrderPowerset> rst = client.Get(new WorkOrderPowersetKey() { Code = ivtest.PowersetCode, ItemNo = ivtest.PowersetItemNo ?? -1, OrderNumber = obj.OrderNumber, MaterialCode = obj.MaterialCode }); if (rst.Code > 0) { return(Json(rst)); } wop = rst.Data; } //根据物料编码获取物料数据,进一步获取产品类型。 Material material = null; using (MaterialServiceClient client = new MaterialServiceClient()) { MethodReturnResult <Material> rst = client.Get(obj.MaterialCode); if (rst.Code > 0) { return(Json(rst)); } material = rst.Data; } #region //检查打印铭牌的LOG日志 using (IVTestDataPrintLogServiceClient client = new IVTestDataPrintLogServiceClient()) { int itemNo = 1; if (model.IsRepeatPrint == false) { MethodReturnResult <IVTestDataPrintLog> rst = client.Get(new IVTestDataPrintLogKey() { LotNumber = ivtest.Key.LotNumber, EquipmentCode = ivtest.Key.EquipmentCode, TestTime = ivtest.Key.TestTime, ItemNo = itemNo }); if (rst.Code == 0 && rst.Data != null) { //表示重复打印过 result = new MethodReturnResult() { Code = 1001, Message = string.Format("批次({0})已打印铭牌。", ivtest.Key.LotNumber) }; return(Json(result)); } } } #endregion //End 检查打印铭牌的LOG日志 bool bSuccess = true; //打印动态内容。 if (printer != null && label != null) { //获取工单打印规则 WorkOrderPrintSet woprint = null; using (WorkOrderPrintSetServiceClient client = new WorkOrderPrintSetServiceClient()) { MethodReturnResult <WorkOrderPrintSet> rst = client.Get(new WorkOrderPrintSetKey() { OrderNumber = obj.OrderNumber, MaterialCode = obj.MaterialCode, LabelCode = model.PrintLabelCode }); if (rst.Code > 0) { return(Json(rst)); } woprint = rst.Data; } dynamic d = new ExpandoObject(); d.PrintQty = woprint.Qty; d.LotNumber = lotNumber; d.PM = ivtest.CoefPM; d.ISC = ivtest.CoefISC; d.VOC = ivtest.CoefVOC; d.IPM = ivtest.CoefIPM; d.VPM = ivtest.CoefVPM; d.FF = ivtest.CoefFF; d.StandardPower = string.Format("{0:0.0}", wop.StandardPower); d.StandardFuse = wop.StandardFuse; d.StandardIsc = wop.StandardIsc; d.StandardVoc = wop.StandardVoc; d.StandardVPM = wop.StandardVPM; d.StandardIPM = wop.StandardIPM; d.PowerName = wop.PowerName; d.PowerDifference = wop.PowerDifference; d.ProductType = string.Format("JNM{1}{2}-{0}" , wop == null ? string.Empty : Convert.ToString(wop.StandardPower) , material.Key.StartsWith("1201") ? "M" : "P" , material.MainRawQtyPerLot); d.ProductSpec = material.Spec.Replace("*", "x"); dateEndTime = System.DateTime.Now; tSpan = dateEndTime - dateStartTime; dateStartTime = dateEndTime; LogHelper.WriteLogInfo(string.Format(@"BeforePrintLabel{3}>从{0:yyyy-MM-dd HH:mm:ss} 到 {1:yyyy-MM-dd HH:mm:ss} ,时间间隔{2}", dateStartTime.ToString(), dateEndTime.ToString(), tSpan.TotalMilliseconds, lotNumber ) ); //根据打印机类型,调用不同的打印方法。 using (IPrintHelper helper = PrintHelperFactory.CreatePrintHelper(label.Content)) { if (printer.ClientType == EnumClientType.NetworkPrinter) { string[] vals = printer.IPAddress.Split(':'); string port = "9100"; if (vals.Length > 1) { port = vals[1]; } bSuccess = helper.NetworkPrint(vals[0], port, label.Content, d); } else if (printer.ClientType == EnumClientType.RawPrinter) { bSuccess = helper.RAWPrint(printer.IPAddress, label.Content, d); } else { bSuccess = false; result.Code = 1001; result.Message = "打印失败,打印机类型不正确。"; return(Json(result)); } } if (bSuccess) { #region //Add Print Log using (IVTestDataPrintLogServiceClient client = new IVTestDataPrintLogServiceClient()) { int itemNo = 1; IVTestDataPrintLog ivdpl = new IVTestDataPrintLog() { CoefFF = ivtest.CoefFF, CoefIPM = ivtest.CoefIPM, CoefISC = ivtest.CoefISC, CoefPM = ivtest.CoefPM, CoefVOC = ivtest.CoefVOC, CoefVPM = ivtest.CoefVPM, CreateTime = DateTime.Now, Creator = User.Identity.Name, CTM = ivtest.CTM, LabelCode = model.PrintLabelCode, PowersetCode = ivtest.PowersetCode, PowersetItemNo = ivtest.PowersetItemNo.Value, PowersetSubCode = ivtest.PowersetSubCode, PrintTime = DateTime.Now, Key = new IVTestDataPrintLogKey() { LotNumber = ivtest.Key.LotNumber, EquipmentCode = ivtest.Key.EquipmentCode, TestTime = ivtest.Key.TestTime, ItemNo = itemNo } }; client.Add(ivdpl); } #endregion } } else { bSuccess = false; } //返回打印结果。 StringBuilder sbMessage = new StringBuilder(); if (bSuccess == false) { result.Code = 1001; sbMessage.AppendFormat("批次 {0} 打印操作失败。<br/>", model.LotNumber); } else { sbMessage.AppendFormat("批次 {0} 打印操作成功。<br/>", model.LotNumber); } sbMessage.Append("<table border='1px' width='100%'><tr><td>"); sbMessage.AppendFormat("<font size='14px' color='red'>档位:{0}</font>", wop.PowerName); sbMessage.Append("</td><td>"); sbMessage.AppendFormat("<font size='14px' color='red'>子档位:{0}</font> ", ivtest.PowersetSubCode); sbMessage.AppendFormat("<img src='/ZPVM/WorkOrderPowersetDetail/ShowPicture?OrderNumber={0}&MaterialCode={1}&Code={2}&ItemNo={3}&SubCode={4}&TimeStamp={5}' width='150px'/>" , obj.OrderNumber , obj.MaterialCode , ivtest.PowersetCode , ivtest.PowersetItemNo , ivtest.PowersetSubCode , DateTime.Now.Ticks); sbMessage.Append("</td><td>"); sbMessage.AppendFormat("<font size='14px' color='blue'>花色:{0}</font><br/>", obj.Color); sbMessage.Append("</td><td>"); sbMessage.AppendFormat("<br/><font size='14px' color='blue'>等级:{0}</font><br/>", obj.Grade); sbMessage.Append("</td><tr></table>"); sbMessage.AppendFormat("<font size='10px' color='blue'>功率:{0}</font><br/>", ivtest.CoefPM); sbMessage.AppendFormat("<font size='10px' color='blue'>ISC:{0}</font><br/>", ivtest.CoefISC); sbMessage.AppendFormat("<font size='10px' color='blue'>IPM:{0}</font><br/>", ivtest.CoefIPM); sbMessage.AppendFormat("<font size='10px' color='blue'>VOC:{0}</font><br/>", ivtest.CoefVOC); sbMessage.AppendFormat("<font size='10px' color='blue'>VPM:{0}</font><br/>", ivtest.CoefVPM); result.Message = sbMessage.ToString(); } catch (Exception ex) { LogHelper.WriteLogError(string.Format(@"PrintLabel{0}失败", lotNumber), ex); result.Code = 1000; result.Message = ex.Message; result.Detail = ex.ToString(); } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return(Json(result)); }
public async Task <ActionResult> ExportToExcel(LotPackageQueryViewModel model) { IList <PackageDetail> lstLotPackage = new List <PackageDetail>(); ZPVMLotPackageViewModel m = new ZPVMLotPackageViewModel(); using (PackageQueryServiceClient client = new PackageQueryServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "Key.PackageNo,ItemNo", Where = GetQueryCondition(model) }; MethodReturnResult <IList <PackageDetail> > result = client.GetDetail(ref cfg); if (result.Code == 0) { lstLotPackage = result.Data; } }); } //创建工作薄。 IWorkbook wb = new HSSFWorkbook(); //设置EXCEL格式 ICellStyle style = wb.CreateCellStyle(); style.FillForegroundColor = 10; //有边框 style.BorderBottom = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; IFont font = wb.CreateFont(); font.Boldweight = 10; style.SetFont(font); ISheet ws = null; for (int j = 0; j < lstLotPackage.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); IRow row = ws.CreateRow(0); #region //列名 ICell cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(StringResource.ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("包装号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("项目号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("批次号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("工单号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("物料编码"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("等级"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("花色"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("功率"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("电流"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("最大电流"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("电压"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("最大电压"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("填充因子"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("分档名称"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("子分档代码"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("包装日期"); #endregion font.Boldweight = 5; } PackageDetail obj = lstLotPackage[j]; IRow rowData = ws.CreateRow(j + 1); Lot lot = m.GetLotData(obj.Key.ObjectNumber); IVTestData ivtest = m.GetIVTestData(obj.Key.ObjectNumber); List <string> dic = null; string ff = ""; OemData oemData = m.GetOemData(obj.Key.ObjectNumber); if (oemData != null) { dic = m.GetCodeAndItemNo(oemData); ff = (oemData.FF * 100).ToString("F4"); } else { lot = m.GetLotData(obj.Key.ObjectNumber); ivtest = m.GetIVTestData(obj.Key.ObjectNumber); } #region //数据 ICell cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(j + 1); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Key.PackageNo); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.ItemNo); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Key.ObjectNumber); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.OrderNumber); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.MaterialCode); if (oemData != null) { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.Grade); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.Color); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.PMAX); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.ISC); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.IPM); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.VOC); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.VPM); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ff); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.PnName == null ? string.Empty : oemData.PnName); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(oemData.PsSubCode); } else { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lot != null ? lot.Grade : string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lot != null ? lot.Color : string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefPM : 0); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefISC : 0); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefIPM : 0); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefVOC : 0); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefVPM : 0); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.CoefFF : 0); string powerName = string.Empty; if (ivtest != null && !string.IsNullOrEmpty(ivtest.PowersetCode) && ivtest.PowersetItemNo != null) { powerName = m.GetPowersetName(ivtest.Key.LotNumber, ivtest.PowersetCode, ivtest.PowersetItemNo.Value); } cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(powerName); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtest != null ? ivtest.PowersetSubCode : string.Empty); } cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Format("{0:yyyy-MM-dd}", obj.CreateTime)); #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "LotPackageData.xls")); }
public async Task <ActionResult> ExportToXML(LotPackageSEModulesViewModel model) { IList <Package> lstLotPackage = new List <Package>(); string ftpServerIP = System.Configuration.ConfigurationManager.AppSettings["ftpServerIP"]; string ftpUserID = System.Configuration.ConfigurationManager.AppSettings["ftpUserID"]; string ftpPassword = System.Configuration.ConfigurationManager.AppSettings["ftpPassword"]; string fileDate = DateTime.Now.ToString("yyyyMMdd"); if (!GetFile(ftpServerIP, ftpUserID, ftpPassword, fileDate))// { MakeDir(ftpServerIP, ftpUserID, ftpPassword, fileDate); } LotPackageSEModulesViewModel SEModulesModel = new LotPackageSEModulesViewModel(); try { using (PackageQueryServiceClient client = new PackageQueryServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "Key", Where = GetQueryCondition(model) }; MethodReturnResult <IList <Package> > resultPackage = client.Get(ref cfg); if (resultPackage.Code == 0) { lstLotPackage = resultPackage.Data; } }); } string successMessage = string.Empty; //记录导出成功批次 string failMessage = string.Empty;; //记录导出失败批次 for (int i = 0; i < lstLotPackage.Count; i++) { string packageNo = lstLotPackage[i].Key;//包装号 MethodReturnResult <IList <Lot> > lotDetail = null; using (LotQueryServiceClient client = new LotQueryServiceClient())//取得包装号对应的批次信息 { PagingConfig cfg = new PagingConfig() { Where = string.Format("PackageNo='{0}'", packageNo), IsPaging = false }; lotDetail = client.Get(ref cfg); } //string productType = SEModulesModel.GetProductType(); //创建XML文件 #region 1.创建类型声明节点 XmlDocument xmlDoc = new XmlDocument(); //XML对象 XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "ISO-8859-1", "no"); xmlDoc.AppendChild(node); #endregion #region 2.创建根节点 XmlElement root = xmlDoc.CreateElement("Parts"); root.SetAttribute("xmlns:xsi", @"http://www.w3.org/2001/XMLSchema-instance"); xmlDoc.AppendChild(root); #endregion #region 3批次数据节点 for (int j = 0; j < lotDetail.Data.Count; j++) { string lotNumber = lotDetail.Data[j].Key;//批次号 //string packageNo = lotDetail.Data[j].PackageNo;//托号 string seModulesNo = string.Empty; //if (lotDetail.Data[j].Attr3 != "" && lotDetail.Data[j].Attr3.Split('-').Length > 1) //{ // seModulesNo = lotDetail.Data[j].Attr3.Split('-')[1]; //} //else //{ // seModulesNo = lotDetail.Data[j].Attr3; //} seModulesNo = lotDetail.Data[j].Attr3; string orderNumber = lotDetail.Data[j].OrderNumber; string materialCode = lotDetail.Data[j].MaterialCode; string pmp = ""; string isc = ""; string imp = ""; string voc = ""; string vmp = ""; string ff = ""; string pnom = ""; string current = ""; string colour = ""; if (lotDetail.Data[j].Color == "深蓝") { colour = "Dark Blue"; } if (lotDetail.Data[j].Color == "浅蓝") { colour = "Light Blue"; } if (lotDetail.Data[j].Color == "正蓝") { colour = "Blue"; } IVTestData ivtest = SEModulesModel.GetIVTestData(lotNumber); RPTpackagelistParameter param = new RPTpackagelistParameter(); param.PackageNo = packageNo; param.LotNumber = lotNumber; param.PageSize = 20; using (PackageQueryServiceClient client = new PackageQueryServiceClient()) { MethodReturnResult <DataSet> ds = client.GetRPTpackagelistQueryDb(ref param); if (ds.Code > 0) { //return Content("批次{0}五大参数异常", lotNumber); } else { DataTable dtOfIV = ds.Data.Tables[0]; pmp = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_PMAX"]).ToString("F3"); isc = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_ISC"]).ToString("F3"); imp = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_IMAX"]).ToString("F3"); voc = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_VOC"]).ToString("F3"); vmp = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_VMAX"]).ToString("F3"); if (Convert.ToDecimal(dtOfIV.Rows[0]["COEF_FF"]) < 1) { ff = (Convert.ToDecimal(dtOfIV.Rows[0]["COEF_FF"]) * 100).ToString("F3"); } else { ff = Convert.ToDecimal(dtOfIV.Rows[0]["COEF_FF"]).ToString("F3"); } pnom = dtOfIV.Rows[0]["PM_NAME"].ToString(); current = dtOfIV.Rows[0]["PS_SUBCODE"].ToString(); if (current == "α") { current = "A"; } if (current == "β") { current = "B"; } if (current == "γ") { current = "C"; } } } string productType = SEModulesModel.GetProductType(materialCode, orderNumber, ivtest.PowersetCode, ivtest.PowersetItemNo.Value, lotDetail.Data[j]); //对应主铭牌上的产品型号 string productTypes = SEModulesModel.GetProductTypes(materialCode, orderNumber, ivtest.PowersetCode, ivtest.PowersetItemNo.Value, lotDetail.Data[j]); //对应副标签上的产品型号 if (productType == "" || productTypes == "") { return(Content("产片编码:{0}未设置产品对应属性", materialCode)); } XmlNode PartDataNode = xmlDoc.CreateNode(XmlNodeType.Element, "PartData", null); root.AppendChild(PartDataNode); CreateNode(xmlDoc, PartDataNode, "ModuleSerialNumber", "JN" + lotNumber); CreateNode(xmlDoc, PartDataNode, "SESerialNumber", seModulesNo); CreateNode(xmlDoc, PartDataNode, "PartNumber", productTypes); CreateNode(xmlDoc, PartDataNode, "PalletNumber", packageNo); //CreateNode(xmlDoc, PartDataNode, "Pmp-W", pmp); //CreateNode(xmlDoc, PartDataNode, "Isc-A", isc); //CreateNode(xmlDoc, PartDataNode, "Imp-A", imp); //CreateNode(xmlDoc, PartDataNode, "Voc-V", voc); //CreateNode(xmlDoc, PartDataNode, "Vmp-V", vmp); //CreateNode(xmlDoc, PartDataNode, "FF-%", ff); //CreateNode(xmlDoc, PartDataNode, "Pnom-W", pnom); //CreateNode(xmlDoc, PartDataNode, "Current-A", current); CreateNode(xmlDoc, PartDataNode, "Pmp", pmp + "W"); CreateNode(xmlDoc, PartDataNode, "Isc", isc + "A"); CreateNode(xmlDoc, PartDataNode, "Imp", imp + "A"); CreateNode(xmlDoc, PartDataNode, "Voc", voc + "V"); CreateNode(xmlDoc, PartDataNode, "Vmp", vmp + "V"); CreateNode(xmlDoc, PartDataNode, "FF", ff + "%"); CreateNode(xmlDoc, PartDataNode, "Pnom", pnom); CreateNode(xmlDoc, PartDataNode, "Current", current); CreateNode(xmlDoc, PartDataNode, "Colour", colour); CreateNode(xmlDoc, PartDataNode, "LabelPN", productType); } #endregion //XML路径 string path = Server.MapPath("~/SEModules/"); if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } string fileName = "SEModules" + DateTime.Now.ToString("yyyyMMddHHmm") + packageNo + ".xml"; string pathFile = path + fileName; xmlDoc.Save(pathFile); //string ftpServerIP = "seftp.solaredge.com"; //string ftpUserID = "jinergy"; //string ftpPassword = "******"; if (UploadFtp(path, fileDate, fileName, ftpServerIP, ftpUserID, ftpPassword)) { successMessage = successMessage + packageNo + ";"; } else { failMessage = failMessage + packageNo + ";"; } } if (successMessage.Length > 0) { successMessage = successMessage + "导出成功"; } if (failMessage.Length > 0) { failMessage = failMessage + "导出失败"; } return(Content("批次号:" + successMessage + failMessage)); } catch (Exception err) { return(Content(string.Format("导出XML报错:{0}", err.Message))); } }
public async Task <ActionResult> ExportToExcel(CheckDataQueryViewModel model) { IList <LotTransaction> lstCheckData = new List <LotTransaction>(); CheckDataViewModel m = new CheckDataViewModel(); using (LotQueryServiceClient client = new LotQueryServiceClient()) { await Task.Run(() => { PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "CreateTime DESC", Where = GetQueryCondition(model) }; MethodReturnResult <IList <LotTransaction> > result = client.GetTransaction(ref cfg); if (result.Code == 0) { lstCheckData = result.Data; } }); } //创建工作薄。 IWorkbook wb = new HSSFWorkbook(); //设置EXCEL格式 ICellStyle style = wb.CreateCellStyle(); style.FillForegroundColor = 10; //有边框 style.BorderBottom = BorderStyle.Thin; style.BorderLeft = BorderStyle.Thin; style.BorderRight = BorderStyle.Thin; style.BorderTop = BorderStyle.Thin; IFont font = wb.CreateFont(); font.Boldweight = 10; style.SetFont(font); ISheet ws = null; for (int j = 0; j < lstCheckData.Count; j++) { if (j % 65535 == 0) { ws = wb.CreateSheet(); IRow row = ws.CreateRow(0); #region //列名 ICell cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue(StringResource.ItemNo); //项目号 cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("批次号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("工单号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("产品料号"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("线别"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("等级"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("花色"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际功率"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际电流"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际最大电流"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际电压"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际最大电压"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("实际填充因子"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("分档名称"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("子分档代码"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("备注"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("检验时间"); cell = row.CreateCell(row.Cells.Count); cell.CellStyle = style; cell.SetCellValue("检验操作人"); #endregion font.Boldweight = 5; } LotTransaction obj = lstCheckData[j]; IRow rowData = ws.CreateRow(j + 1); Lot lotObj = m.GetLot(obj.LotNumber); IVTestData ivtestData = m.GetIVTestData(obj.LotNumber); LotTransactionHistory lotHisObj = m.GetLotTransactionHistory(obj.Key); #region //数据 ICell cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(j + 1); //项目号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.LotNumber); //批次号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.OrderNumber); //工单号 cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lotHisObj != null ? lotHisObj.MaterialCode : string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lotHisObj != null ? lotHisObj.LineCode : string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lotObj != null ? lotObj.Grade : string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(lotObj != null ? lotObj.Color : string.Empty); if (ivtestData != null) { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefPM); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefISC); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefIPM); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefVOC); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefVPM); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.CoefFF); } else { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); } if (ivtestData == null || string.IsNullOrEmpty(ivtestData.PowersetCode) || ivtestData.PowersetItemNo == null) { cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Empty); } else { string powersetName = m.GetPowersetName(ivtestData.Key.LotNumber, ivtestData.PowersetCode, ivtestData.PowersetItemNo.Value); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(powersetName); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(ivtestData.PowersetSubCode); } cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Description); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.CreateTime)); cellData = rowData.CreateCell(rowData.Cells.Count); cellData.CellStyle = style; cellData.SetCellValue(obj.Creator); #endregion } MemoryStream ms = new MemoryStream(); wb.Write(ms); ms.Flush(); ms.Position = 0; return(File(ms, "application/vnd.ms-excel", "CheckDataData.xls")); }
/// <summary> /// 将数据从Access数据库转移到MES数据库。 /// </summary> /// <param name="element">设备配置。</param> /// <returns>true:转置成功。false:转置失败。</returns> public bool Execute(IVTestDeviceElement element) { try { //根据设备代码获取SQL Server数据库中最大的测试时间值。 DateTime dtMaxTestTime = new DateTime(2000, 1, 1); PagingConfig cfg = new PagingConfig() { PageNo = 0, PageSize = 1, Where = string.Format("Key.EquipmentCode='{0}'", element.Name), OrderBy = "Key.TestTime Desc" }; using (IVTestDataServiceClient client = new IVTestDataServiceClient()) { MethodReturnResult <IList <IVTestData> > result = client.Get(ref cfg); if (result.Code == 0 && result.Data != null && result.Data.Count > 0) { dtMaxTestTime = result.Data[0].Key.TestTime; } client.Close(); } //组织查询IV测试数据的SQL语句 StringBuilder sbSql = new StringBuilder(); string sql = string.Empty; if (element.Type == IVTestDeviceType.Customer) { sql = element.Sql; } else { sql = GetQueryTestDataSql(element.Type); } sbSql.AppendFormat("SELECT TOP 100 '{2}' AS DeviceNo,a.* FROM ({0}) a WHERE a.TTIME>'{1}' ORDER BY a.TTIME ASC", sql, dtMaxTestTime.ToString("yyyy-MM-dd HH:mm:ss"), element.Name); DataSet dsIVTestData = new DataSet(); //创建 Access的连接对象。 using (OleDbConnection oleCon = new OleDbConnection(this.AccessConnectionString)) { oleCon.Open(); using (OleDbCommand oleCmd = oleCon.CreateCommand()) { //从Access数据库获取>开始日期和开始时间的数据。 oleCmd.CommandType = CommandType.Text; oleCmd.CommandText = sbSql.ToString(); OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCmd); oleAdapter.Fill(dsIVTestData); } oleCon.Close(); } //新增IV测试数据 if (dsIVTestData != null && dsIVTestData.Tables.Count > 0 && dsIVTestData.Tables[0].Rows.Count > 0) { IVTestDataTransferParameter p = new IVTestDataTransferParameter(); p.List = new List <IVTestData>(); foreach (DataRow dr in dsIVTestData.Tables[0].Rows) { IVTestData iv = new IVTestData(); iv.Key = new IVTestDataKey() { EquipmentCode = element.Name, LotNumber = Convert.ToString(dr["LOT_NUMBER"]).ToUpper(), TestTime = Convert.ToDateTime(dr["TTIME"]) }; //--TTIME 测试时间 //--LOT_NUMBER 批次号 //--FF 填充因子 //--ISC 测试短路电流 //--EFF 组件转换效率 //--RSH 串联电阻 //--RS 并联电阻 //--VOC 测试开路电压 //--IPM 测试最大电流 //--PM 测试最大功率 //--VPM 测试最大电压 //--AMBIENTTEMP 测度温度 //--SENSORTEMP 环境温度 //--INTENSITY 光强 iv.FF = dr["FF"] != DBNull.Value ? Convert.ToDouble(dr["FF"]) : 0; iv.ISC = dr["ISC"] != DBNull.Value ? Convert.ToDouble(dr["ISC"]) : 0; iv.EFF = dr["EFF"] != DBNull.Value ? Convert.ToDouble(dr["EFF"]) : 0; iv.RSH = dr["RSH"] != DBNull.Value ? Convert.ToDouble(dr["RSH"]) : 0; iv.RS = dr["RS"] != DBNull.Value ? Convert.ToDouble(dr["RS"]) : 0; iv.VOC = dr["VOC"] != DBNull.Value ? Convert.ToDouble(dr["VOC"]) : 0; iv.IPM = dr["IPM"] != DBNull.Value ? Convert.ToDouble(dr["IPM"]) : 0; iv.PM = dr["PM"] != DBNull.Value ? Convert.ToDouble(dr["PM"]) : 0; iv.VPM = dr["VPM"] != DBNull.Value ? Convert.ToDouble(dr["VPM"]) : 0; iv.AmbientTemperature = dr["AMBIENTTEMP"] != DBNull.Value ? Convert.ToDouble(dr["AMBIENTTEMP"]) : 0; iv.SensorTemperature = dr["SENSORTEMP"] != DBNull.Value ? Convert.ToDouble(dr["SENSORTEMP"]) : 0; iv.Intensity = dr["INTENSITY"] != DBNull.Value ? Convert.ToDouble(dr["INTENSITY"]) : 0; iv.CoefFF = iv.FF; iv.CoefIPM = iv.IPM; iv.CoefISC = iv.ISC; iv.CoefPM = iv.PM; iv.CoefVOC = iv.VOC; iv.CoefVPM = iv.VPM; iv.IsDefault = false; iv.IsPrint = false; //新增IV测试数据。 p.List.Add(iv); } //开始移转IV测试数据。 if (p.List.Count != 0) { using (IVTestDataTransferServiceClient client = new IVTestDataTransferServiceClient()) { MethodReturnResult result = client.Transfer(p); if (result.Code > 0) { EventLog.WriteEntry(EVENT_SOURCE_NAME , string.Format("{0}:{1}", element.Name, result.Message) , EventLogEntryType.Error); client.Close(); return(false); } else { this.TransferCount = p.List.Count; client.Close(); } } } } } catch (Exception ex) { EventLog.WriteEntry(EVENT_SOURCE_NAME , string.Format("{0}:{1}", element.Name, ex.Message) , EventLogEntryType.Error); return(false); } return(true); }