//根据传入的参数处理事情 public void ProcessRequest(HttpContext context) { //清空之前数据 context.Response.Clear(); //检测是否含有session if (context.Session.Count < 5) { //跳转 context.Response.Redirect("/Account/Login", true); //停止加载后续内容 context.Response.End(); //直接返回 return; } //执行基类的方法 if (!base.CheckIsLogin(context)) { return; } //用户传入的查询参数 //lot卡号 string lotId = context.Request["lid"]; if (string.IsNullOrWhiteSpace(lotId)) { return; } //生产编号 string productNum = context.Request["pnum"]; if (string.IsNullOrWhiteSpace(productNum)) { //从数据库获取当前lot卡号的生产编号 using (var da = new v_ppc_lot_card_join_orderTableAdapter()) { //获取数据 var tab = da.GetDataByLotId(lotId); //检测有无数据 if (tab.Rows.Count <= 0) { return; } //取得首行数据 var row = (DataSetPpcLotCardMgr.v_ppc_lot_card_join_orderRow)tab.Rows[0]; //取得生产编号 productNum = row.product_num; if (string.IsNullOrWhiteSpace(productNum)) { return; } } } //待输出到浏览器的数据 string strResult = string.Empty; //获取汇总内容 using (var da = new t_product_record_chongxingTableAdapter()) { //取得结果 strResult = da.GetToolNumAndPnlPunchCount(lotId, productNum).ToString(); //写入数据到浏览器 context.Response.Write(strResult); } }
//根据传入的参数处理事情 public void ProcessRequest(HttpContext context) { //清空之前数据 context.Response.Clear(); //检测是否含有session if (context.Session.Count < 5) { //跳转 context.Response.Redirect("/Account/Login", true); //停止加载后续内容 context.Response.End(); //直接返回 return; } //执行基类的方法 if (!base.CheckIsLogin(context)) { return; } //用户传入的lot卡号 string lotId = context.Request["lid"]; //检测lot卡号 if (lotId == null || lotId.Length < 6) { throw new Exception("未提供lot卡号参数或者lot卡号参数长度太短!"); } //待输出到浏览器的数据 string strResult = string.Empty; try { //根据lot卡号获取lot卡和订单信息 using (var da = new v_ppc_lot_card_join_orderTableAdapter()) using (var tab = da.GetDataByLotId(lotId)) { //检测获取到的数据数据 if (tab.Rows.Count <= 0) { strResult = "打印失败:PMC录入的lot卡不存在!"; } else { //首行 var row = (DataSetPpcLotCardMgr.v_ppc_lot_card_join_orderRow)tab.Rows[0]; //取得生产编号 string productNum = row.product_num.Trim().ToUpper(); //检测生产编号的正确性 string strReg = @"^TY(?!Y)[A-Z]-[1-9]\d{0,7}[0A-Z][0-9]$"; if (!Regex.IsMatch(productNum, strReg)) { strResult = string.Format("打印失败:{0}生产编号不符合规则,必须为 TYZ-100A0 格式!", productNum); } else { //生产编号中的层数起始字符索引 int iNumStart = productNum.IndexOf("-") + 1; //抓取生产编号中的数字序号串和版本 int pNum = int.Parse(productNum.Substring(iNumStart, productNum.Length - iNumStart - 2)); string pVersion = productNum.Substring(productNum.Length - 2); //根目录编号段 int iNumBegin = (pNum / 3000) * 3000 + 1; int iNumEnd = iNumBegin + 3000 - 1; //拼接文件夹路径 var sb = new StringBuilder("E:\\工程"); //确定顶级文件夹名称 sb.Append(iNumBegin.ToString("0000") + "-" + iNumEnd.ToString("0000")); //确定次级文件夹名称 sb.Append("\\" + productNum + "\\" + productNum + ".xls"); //得到lot卡文件全路径 string lotCardFullPath = sb.ToString(); //检查文件是否存在 if (!File.Exists(lotCardFullPath)) { strResult = "打印失败:工程lot卡不存在!路径为:" + lotCardFullPath; } else { //excel对象 var xlApp = new Excel.Application(); //打开该excel文件 xlApp.Visible = true; xlApp.DisplayAlerts = false; try { //打开工作簿 var xlBook = xlApp.Workbooks.Open(lotCardFullPath, ReadOnly: true); foreach (Excel.Worksheet item in xlBook.Worksheets) { if (item.Name != "normal") { item.Delete(); } } var xlSheet = (Excel.Worksheet)xlBook.Worksheets[1]; //设置为活动 ((Excel._Worksheet)xlSheet).Select(); //设置值 //订单序号 xlSheet.Range["S1"].Value = row.order_id; //LOT卡号 xlSheet.Range["S2"].Value = row.lot_id; //客户名称 xlSheet.Range["C3"].Value = row.Iscust_nameNull() ? string.Empty : row.cust_name; //下单日期 xlSheet.Range["F3"].Value = row.Isorder_dateNull() ? string.Empty : row.order_date.ToString("yyyy-MM-dd"); //需求日期 xlSheet.Range["K3"].Value = row.Isneed_dateNull() ? string.Empty : row.need_date.ToString("yyyy-MM-dd"); //生产日期 xlSheet.Range["S3"].Value = row.Isproduct_dateNull() ? string.Empty : row.product_date.ToString("yyyy-MM-dd"); //订单数量 xlSheet.Range["C6"].Value = row.Isorder_pcs_qtyNull() ? string.Empty : row.order_pcs_qty.ToString(); //投产数量 using (var da2 = new t_ppc_lot_cardTableAdapter()) { xlSheet.Range["F6"].Value = da2.SumPcsQtyByOrderId(row.order_id).ToString(); } //当前开料lot卡pnl长宽 var strPnlLength = row.pnl_length.ToString(); var strPnlWidth = row.pnl_width.ToString(); //当前工程lot卡pnl长宽A var strPnlLengthA = xlSheet.Range["I5"].Text.ToString(); var strPnlWidthA = xlSheet.Range["L5"].Text.ToString(); //当前工程lot卡pnl长宽B var strPnlLengthB = xlSheet.Range["I6"].Text.ToString(); var strPnlWidthB = xlSheet.Range["L6"].Text.ToString(); //检测使用的是哪种工程MI尺寸 string strPnlSize = string.Empty; //检测是否符合工程MI中填写的pnl尺寸 if ((strPnlLength == strPnlLengthA && strPnlWidth == strPnlWidthA) || (strPnlLength == strPnlWidthA && strPnlWidth == strPnlLengthA)) { strPnlSize = "A板"; } else if ((strPnlLength == strPnlLengthB&& strPnlWidth == strPnlWidthB) || (strPnlLength == strPnlWidthB && strPnlWidth == strPnlLengthB)) { strPnlSize = "B板"; } else { strPnlSize = "B板"; xlSheet.Range["I6"].Value = strPnlLength; xlSheet.Range["L6"].Value = strPnlWidth; xlSheet.Range["N6"].Value = string.Empty; xlSheet.Range["Q6"].Value = string.Empty; xlSheet.Range["T6"].Value = row.pnl_count_pcs; } //本卡数量 xlSheet.Range["K7"].Value = strPnlSize + row.pnl_qty; //本卡面积 xlSheet.Range["R7"].Value = row.total_pnl_area; //订单编号 xlSheet.Range["C64"].Value = row.Isorder_numNull() ? string.Empty : row.order_num; //只打印为一页 xlSheet.PageSetup.FitToPagesWide = 1; xlSheet.PageSetup.FitToPagesTall = 1; //打印lot卡 xlSheet.PrintOut(From: 1, To: 1, Copies: 1, Collate: true); //关闭工作表 xlBook.Close(SaveChanges: false); //待返回的状态结果 strResult = "打印成功!"; //注销excel相关对象 xlSheet = null; xlBook = null; } catch (Exception exx) { throw exx; } finally { //关闭excel文档 foreach (Excel.Workbook itm in xlApp.Workbooks) { itm.Close(SaveChanges: false); } xlApp.Quit(); //关闭excel进程 ydPublicMethod.KillExcel(xlApp); xlApp = null; } } } } } } catch (Exception ex) { strResult = "打印失败:" + ex.Message; } //写入数据到浏览器 context.Response.Write(strResult); }
//根据传入的参数处理事情 public void ProcessRequest(HttpContext context) { //清空之前数据 context.Response.Clear(); //检测是否含有session if (context.Session.Count < 5) { //跳转 context.Response.Redirect("/Account/Login", true); //停止加载后续内容 context.Response.End(); //直接返回 return; } //执行基类的方法 if (!base.CheckIsLogin(context)) { return; } //用户传入的批量卡序号 string lotId = context.Request["lid"]; //检测批量卡序号 if (lotId == null || lotId.Length < 6) { throw new Exception("未提供批量卡序号参数或者批量卡号参数长度太短!"); } //待输出到浏览器的数据 string strResult = string.Empty; try { //根据批量卡序号获取批量卡和订单信息 using (var da = new v_ppc_lot_card_join_orderTableAdapter()) using (var tab = da.GetDataByLotId(lotId)) { //检测获取到的数据数据 if (tab.Rows.Count <= 0) { strResult = "打印失败:PMC录入的批量卡不存在!"; } else { //首行 var row = (DataSetPpcLotCardMgr.v_ppc_lot_card_join_orderRow)tab.Rows[0]; //取得生产编号 string productNum = row.product_num.Trim().ToUpper(); //生产编号中的层数起始字符索引 int iLayerStart = 0; //检测生产编号的正确性 string strReg = @"^L-H[DSM]\d{4,}[0A-Z][0-9]$"; if (!Regex.IsMatch(productNum, strReg)) { strResult = string.Format("打印失败:{0}生产编号不符合规则!", productNum); } else { //第二个字符为减号则从第三个字符开始 if (productNum.Substring(2, 1) == "-") { iLayerStart += 2; } //抓取生产编号中的数字序号串和版本 string pNum = string.Empty; for (int i = iLayerStart; i < productNum.Length; i++) { //层数截至位置 if (char.IsLetter(productNum, i)) { for (int j = i + 1; j < productNum.Length; j++) { //流程截至位置 if (char.IsNumber(productNum, j)) { //最后两位为版本号 pNum = productNum.Substring(j, productNum.Length - j - 2); break; } } break; } } string pVersion = productNum.Substring(productNum.Length - 2); //生产编号转数字 int k = pNum.IndexOf("-"); int iNum, iNum2; string strFileNameNum = string.Empty; if (k > 0) { iNum = int.Parse(pNum.Substring(0, k)); iNum2 = int.Parse(pNum.Substring(k + 1)); } else { iNum = int.Parse(pNum); iNum2 = 0; } //当前生产编号数字或者生产编号数字段 strFileNameNum = iNum.ToString("0000"); if (iNum2 > 0) { strFileNameNum += "-" + iNum2.ToString("0000"); } //根目录编号段 int iNumBegin = (iNum / 3000) * 3000 + 1; int iNumEnd = iNumBegin + 3000 - 1; //拼接文件夹路径 var sb = new StringBuilder("H:\\工程"); //确定顶级文件夹名称 sb.Append(iNumBegin.ToString("0000") + "-" + iNumEnd.ToString("0000")); //确定次级文件夹名称 sb.Append("\\" + strFileNameNum); //加入版本文件夹 sb.Append("\\" + pVersion); //存储路径用来取得单体图路径 var sb2 = new StringBuilder(sb.ToString()); //批量卡末级文件夹名称 sb.Append("\\DOC"); //确认批量卡文件名称 sb.Append("\\" + strFileNameNum + pVersion + ".xls"); //得到批量卡文件全路径 string lotCardFullPath = sb.ToString(); //单体图末级文件夹名称 sb2.Append("\\DWG"); //确认单体图文件名称 sb2.Append("\\" + strFileNameNum + pVersion + "单体图.dwg"); //得到单体图文件全路径 string danTiTuFullPath = sb2.ToString(); //检查文件是否存在 if (!File.Exists(lotCardFullPath)) { lotCardFullPath = lotCardFullPath.Replace("\\DOC\\", "\\D0C\\"); } if (!File.Exists(lotCardFullPath)) { lotCardFullPath = lotCardFullPath.Replace("\\D0C\\", "\\DOC\\"); strResult = "打印失败:工程批量卡不存在!路径为:" + lotCardFullPath; } else { //excel对象 var xlApp = new Excel.Application(); //打开该excel文件 xlApp.Visible = true; xlApp.DisplayAlerts = false; try { //打开工作簿 var xlBook = xlApp.Workbooks.Open(lotCardFullPath, ReadOnly: true); var xlSheet = (Excel.Worksheet)xlBook.Worksheets[1]; //设置值 //开料总数量 xlSheet.Range["M3"].Value = row.total_pnl_qty.ToString() + " pnl"; //开料本LOT数量 xlSheet.Range["M7"].Value = row.pnl_qty.ToString() + " pnl"; //订单数量 xlSheet.Range["A4"].Value = "订单数量: " + row.order_pcs_qty.ToString() + " pcs"; //单据状态 xlSheet.Range["I4"].Value = row.state; //LOT NO ((Excel.Range)xlSheet.Range["J3:M4"]).MergeCells = false; ((Excel.Range)xlSheet.Range["K4:M4"]).Merge(); xlSheet.Range["K4"].HorizontalAlignment = Excel.Constants.xlCenter; xlSheet.Range["K4"].Value = row.lot_id; //设置字体加大加粗 xlSheet.Range["M3,M7,A4,K4"].Font.Bold = true; xlSheet.Range["M3,M7,K4"].Font.Size = 18; xlSheet.Range["A4"].Characters[6].Font.Size = 18; //只打印为一页 xlSheet.PageSetup.FitToPagesWide = 1; xlSheet.PageSetup.FitToPagesTall = 1; //检查文件是否存在 if (!File.Exists(danTiTuFullPath)) { strResult = "打印部分失败:单体图不存在!路径为:" + danTiTuFullPath; } else { //待打印成的图片文件的名称 string imgName = context.Server.MapPath( string.Format(@"dwg2jpg-{0}.jpg", context.Session["user_name"]) ); imgName = (new FileInfo(imgName)).FullName; //待打印成的图片文件的名称 imgName = (new FileInfo(imgName)).FullName; //删除之前的文件 if (File.Exists(imgName)) { File.Delete(imgName); } //执行打印单体图生成图片文件 var p = new Process(); p.StartInfo.UseShellExecute = false; //p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; //p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.FileName = context.Server.MapPath(@"PrintLotCard\Dwg2Jpg.exe"); p.StartInfo.Arguments = string.Format(@" {0} {1}", danTiTuFullPath, imgName); p.Start(); string strOutPut = p.StandardOutput.ReadToEnd(); //p.WaitForExit(60000); //检测文件是否存在 if (strOutPut.Length > 0 || !File.Exists(imgName)) { strResult = string.Format("打印单体图失败:{0}" + strOutPut, productNum); } else { //设置为活动 ((Excel._Workbook)xlBook).Activate(); ((Excel._Worksheet)xlSheet).Select(); //在excel中插入该图片并设置分页 string strError = string.Empty; if (InsertImageToExcelSheet(xlSheet, imgName, out strError)) { //打印lot卡和单体图 xlSheet.PrintOut(From: 1, To: 2, Copies: 1, Collate: true); //关闭工作表 xlBook.Close(SaveChanges: false); } else { //抛出错误 throw new Exception(strError); } //删除生成的图片文件 if (File.Exists(imgName)) { File.Delete(imgName); } //待返回的状态结果 strResult = "打印成功!"; } } //注销excel相关对象 xlSheet = null; xlBook = null; } catch (Exception exx) { throw exx; } finally { //关闭excel文档 foreach (Excel.Workbook itm in xlApp.Workbooks) { itm.Close(SaveChanges: false); } xlApp.Quit(); //关闭excel进程 ydPublicMethod.KillExcel(xlApp); xlApp = null; } } } } } } catch (Exception ex) { strResult = "打印失败:" + ex.Message; } //写入数据到浏览器 context.Response.Write(strResult); }