/// <summary> /// 标签打印 /// </summary> protected virtual void onPrint() { try { string ExcelName = _WTT_LabSetInfo.Tables[0].Rows[0]["LabName"].ToString(); string ExcelPath = "D:\\模板\\PrintTemplates\\Data_Source\\" + ExcelName.Substring(0, ExcelName.Length - 4) + ".xlsx"; //1.获取默认打印机 填充数据 2.开始打印 3.计数清零 4.Exfo待打印数据列表清零 //获取默认打印机 PrintDocument fPrintDocument = new PrintDocument(); Delete_ExcelData(ExcelPath); //填充打印数据源 foreach (DataSet _Temds in _WTT_NotPrintList) { Install_data_ToExcel(_Temds); } Messages messages = null; //设置打印模板 LabelFormatDocument btFormat = btEngine.Documents.Open(LabPatch + LabName); //设置打印机 btFormat.PrintSetup.PrinterName = fPrintDocument.PrinterSettings.PrinterName; btFormat.Activate(); Result result = btFormat.Print("PrintJob1", out messages); btFormat.Close(SaveOptions.SaveChanges); _LabCount = 0; _WTT_NotPrintList.Clear(); Delete_ExcelData(ExcelPath); } catch (System.Exception ex) { My_MessageBox.My_MessageBox_Message(ex.Message); } }
/// <summary> /// 清除指定Excel中的数据 /// </summary> /// <param name="_Patch"></param> /// <returns></returns> private bool Delete_ExcelData(string _Patch) { try { // kill_Process("excel"); //将数据填充到模板 Excel.Application xlApp = new Excel.Application(); if (xlApp == null) { return(false); } xlApp.Workbooks._Open(_Patch); Excel._Worksheet oSheet = (Excel._Worksheet)xlApp.Sheets.get_Item(1); //删除指定区域 for (int t = 0; t < 24; t++) { Excel.Range m_objRange = (Excel.Range)oSheet.Rows[2, System.Reflection.Missing.Value]; m_objRange.EntireRow.Delete(Excel.XlDeleteShiftDirection.xlShiftUp); } //填充完成后的操作 xlApp.DisplayAlerts = false; //设置禁止弹出保存和覆盖的询问提示框 xlApp.AlertBeforeOverwriting = false; xlApp.SaveWorkspace(); //保存工作簿 xlApp.Quit(); //确保Excel进程关闭 xlApp = null; GC.Collect(); //如果不使用这条语句会导致excel进程无法正常退出,使用后正常退出 return(true); } catch (SyntaxErrorException ex) { My_MessageBox.My_MessageBox_Message(ex.Message); return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.sysUser GetModel(string UserID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 UserID,UserName,Password,Workstation,Privilege,ID_Key from sysUser "); strSql.Append(" where UserID=@UserID "); SqlParameter[] parameters = { new SqlParameter("@UserID", SqlDbType.VarChar, 15) }; parameters[0].Value = UserID; Maticsoft.Model.sysUser model = new Maticsoft.Model.sysUser(); DataSet ds = dbs.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { My_MessageBox.My_MessageBox_Message("未找到该工号:" + UserID + " 的用户!"); return(null); } }
//自动生成多表 public void Get_SPC_MPO_Auto(string _SavePatch, string _StartDate, string _EndDate) { try { string[] temList = System.Enum.GetNames(typeof(Maticsoft.Model.E_Generate)); foreach (string _Parameter in temList) { //从模板拷贝数据 string _OrignFile, _NewFile; _OrignFile = "D:\\模板\\Template_SPC.xls"; _NewFile = _SavePatch + "\\" + _Parameter + ".xls"; File.Delete(_NewFile); File.Copy(_OrignFile, _NewFile); //将数据填充到模板 Excel.Application xlApp = new Excel.Application(); if (xlApp == null) { MessageBox.Show("Can’t open Excel!"); return; } xlApp.Workbooks._Open(_NewFile); Excel._Worksheet oSheet = (Excel._Worksheet)xlApp.Sheets.get_Item(1); ArrayList temDataList = DateList(_StartDate, _EndDate); //日期列表 //设置模板 SetTempoler(xlApp, _Parameter); //填充数据 FillData(xlApp, _Parameter, temDataList); } My_MessageBox.My_MessageBox_Message("导出完成!"); System.Diagnostics.Process.Start("explorer.exe", _SavePatch); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
public My_Print() { try { btEngine.Start(); //开启后台线程 } catch { My_MessageBox.My_MessageBox_Message("打印服务未能启动,将导致无法打印!/r/n导致此错误的原因可能是您的计算机未安装BT打印软件或其它必要的服务程序!如有疑问请联系系统管理员"); } }
/// <summary> /// 获取用户名 /// </summary> /// <param name="JobNumber">工号</param> /// <returns></returns> public string Get_UserName(string JobNumber) { Maticsoft.Model.sysUser _user = new Model.sysUser(); _user = GetModel(JobNumber); if (_user != null) { return(_user.UserName); } else { My_MessageBox.My_MessageBox_Message("未找到该工号:" + JobNumber + " 的用户!"); return(""); } }
/// <summary> /// 添加待打印数据 /// </summary> /// <param name="PackInfo"></param> /// <returns></returns> public void Add_PrintData(DataSet _notprintdata) { _WTT_NotPrintList.Add(_notprintdata); _LabCount++; if (_IsBtPrint) //if printType is Bt { BtPrint(); } else //PrintType is HP { if (_LabCount == 12) { Print(); My_MessageBox.My_MessageBox_Message("标签数量为:" + _LabCount + " PCS \r\n系统正在打印..."); } } }
//单表生成 public void Get_SPC_MPO(string _SavePatch, string _Parameter, string _Date) { // try // { //从模板拷贝数据 string _OrignFile, _NewFile; _OrignFile = "D:\\模板\\Template_SPC.xls"; _NewFile = _SavePatch + "\\" + _Date + "_" + _Parameter + ".xls"; File.Delete(_NewFile); File.Copy(_OrignFile, _NewFile); //将数据填充到模板 Excel.Application xlApp = new Excel.Application(); if (xlApp == null) { MessageBox.Show("Can’t open Excel!"); return; } xlApp.Workbooks._Open(_NewFile); Excel._Worksheet oSheet = (Excel._Worksheet)xlApp.Sheets.get_Item(1); //设置模板 SetTempoler(xlApp, _Parameter); //获取指定日期的数据 DateTime StartDate = DateTime.Parse(_Date); string temdata = StartDate.ToString("yyyy-MM-dd"); DataSet temds = GetData_SPC(_Parameter, temdata); //填充数据 FillData(xlApp, temds, _Parameter, 1); My_MessageBox.My_MessageBox_Message("导出完成!"); System.Diagnostics.Process.Start("explorer.exe", _SavePatch); //打开文件夹 // } // catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
//针对跳线设计 public My_Print(Maticsoft.Model.PackBatch _packBatch) { try { //1.获取工单中标签的设置信息 2.开启BT打印程序后台线程 OrderLabSet _M_LabSetInfo = new OrderLabSet(); _WTT_LabSetInfo = _M_LabSetInfo.GetLabInfo("(tb_OrderLabSet.OrderID = '" + _packBatch.OrderID + "' )"); if (_WTT_LabSetInfo.Tables[0].Rows.Count > 0) { LabName = _WTT_LabSetInfo.Tables[0].Rows[0]["LabName"].ToString(); _PrintRecord.BatchNo = _packBatch.BatchNo; _PrintRecord.OrderID = _packBatch.OrderID; _PrintRecord.LabellMode = LabName; btEngine.Start(); //开启后台线程 IsPrint = true; //启用标签打印 //检查标签是否核对 LabVerify labv = new LabVerify(); Maticsoft.Model.LabVerify _temLabv = labv.GetModel(" Orm_ID = '" + _packBatch.OrderID + "'"); if (_temLabv != null && _temLabv.IsVerify != "0") { } else { IsPrint = false; My_MessageBox.My_MessageBox_Erry("此工单标签未经过核对!!!\r\n请通知助理或工程师进行标签核对后重试!"); } } else { IsPrint = false; My_MessageBox.My_MessageBox_Message("未找到此批号的任何标签,将不进行标签打印!!!\r\n请确认是否需要进行标签打印"); } } catch { My_MessageBox.My_MessageBox_Message("打印服务未能启动,将导致无法打印!/r/n导致此错误的原因可能是您的计算机未安装BT打印软件或其它必要的服务程序!如有疑问请联系系统管理员"); } }
/// <summary> /// 通过Bt打印机进行打印 /// </summary> protected virtual void onBtPrint() { try { //1.获取默认打印机 填充数据 2.开始打印 3.计数清零 4.Exfo待打印数据列表清零 //获取默认打印机 PrintDocument fPrintDocument = new PrintDocument(); Messages messages = null; //设置打印模板 LabelFormatDocument btFormat = btEngine.Documents.Open(LabPatch + LabName); //设置打印机 btFormat.PrintSetup.PrinterName = fPrintDocument.PrinterSettings.PrinterName; btFormat.Activate(); if (_WTT_LabSetInfo != null) { //填充打印数据源 foreach (DataRow dr in _WTT_LabSetInfo.Tables[0].Rows) { string drName = dr["Name"].ToString(); btFormat.SubStrings[drName].Value = dr["Value"].ToString(); } //BT打印临时添加代码变更时间 2015-5-26 变更原因 海信标签需要进行1315打印 而其它的则都不需要1315 if (LabName == "海信_RD-A-ELA32983.btw") { Pack_Exfo _M_Pack_Exfo = new Pack_Exfo(); //添加打印数据 DataSet temds = _M_Pack_Exfo.GetList("ClientSN='" + SN + "'"); if (temds.Tables[0].Rows.Count < 4) { My_MessageBox.My_MessageBox_Message("打印数据不足(1310或1550数据不够)请检测标签和数据!请重新上传测试数据"); } //填充打印数据源 foreach (DataRow dr in temds.Tables[0].Rows) { if (dr["PartNumber"].ToString() == "1" && dr["Wave"].ToString() == "1310nm") { btFormat.SubStrings["IL_One_13"].Value = dr["IL_A"].ToString(); btFormat.SubStrings["RL_One_13"].Value = dr["Refl_A"].ToString(); } if (dr["PartNumber"].ToString() == "1" && dr["Wave"].ToString() == "1550nm") { btFormat.SubStrings["IL_One_15"].Value = dr["IL_A"].ToString(); btFormat.SubStrings["RL_One_15"].Value = dr["Refl_A"].ToString(); } if (dr["PartNumber"].ToString() == "2" && dr["Wave"].ToString() == "1310nm") { btFormat.SubStrings["IL_Two_13"].Value = dr["IL_A"].ToString(); btFormat.SubStrings["RL_Two_13"].Value = dr["Refl_A"].ToString(); } if (dr["PartNumber"].ToString() == "2" && dr["Wave"].ToString() == "1550nm") { btFormat.SubStrings["IL_Two_15"].Value = dr["IL_A"].ToString(); btFormat.SubStrings["RL_Two_15"].Value = dr["Refl_A"].ToString(); } } } } btFormat.SubStrings["SN"].Value = SN; // Result result = btFormat.Print("PrintJob1", out messages); btFormat.Print(); btFormat.Close(SaveOptions.SaveChanges); _LabCount = 0; _WTT_NotPrintList.Clear(); SN = ""; } catch (System.Exception ex) { My_MessageBox.My_MessageBox_Message(ex.Message); } }