//打印private void buttonX3_Click(object sender, EventArgs e){IList<CV_MM_LOTSORDER> LOTSORDERlist = new List<CV_MM_LOTSORDER>();CV_MM_LOTSORDER_QueryParam Param = new CV_MM_LOTSORDER_QueryParam();List<string> Print = new List<string>();for (int i = 0; i < dataGridView1.Rows.Count; i++){//将选中的第一行if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value) == true){Printlist ordL = new Printlist();Param.OrderID = dataGridView1.Rows[i].Cells[1].Value.ToString();Param.PlanStartDate= Convert.ToDateTime(dataGridView1.Rows[i].Cells[5].Value.ToString());Param.IsPrinted = false;LOTSORDERlist = cV_MM_LOTSORDERBO.GetPrintByLots(Param);if (LOTSORDERlist.Count > 0){for (int t = 0; t < LOTSORDERlist.Count; t++){Print.Add(LOTSORDERlist[t].LotID);}}}}if (Print.Count <= 0){SSMessageBox.ShowWarning("请选择打印的工单!");return;}int q = 1;//调用批量打印方法。PrintList(Print, q);}/// <summary>/// 批量打印/// </summary>/// <param name="barCodes">条码列表</param>/// <param name="printNum">打几份</param>/// <returns></returns>public static bool PrintList(List<string> barCodes, int? printNum){string strDocName;ApplicationClass lab = new ApplicationClass();try{//默认打印一份int _printNum = 1;//获取模板地址。strDocName = System.Windows.Forms.Application.StartupPath + @"\template\TT.lab";//strDocName = strDocName.Substring(0, strDocName.Length - 10) + @"\template\DTTT.lab";if (!File.Exists(@strDocName)){//SSMessageBox.ShowError(strDocName + " 模板不存在");return false;}if (printNum.HasValue){_printNum = printNum.Value;}//codesoft模板lab.Documents.Open(@strDocName, true);Document doc = lab.ActiveDocument;//获取所有打印机名称Strings vars = lab.PrinterSystem().Printers(enumKindOfPrinters.lppxAllPrinters);PrintDocument prtdoc = new PrintDocument();//获取默认打印机名string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;for (int i = 0; i < vars.Count; i++){string[] arrString = vars.Item(i).Split(',');if (arrString[0] == strDefaultPrinter){doc.Printer.SwitchTo(strDefaultPrinter, arrString[1], true);break;}}////参数传值//doc.Variables.FormVariables.Item("varBarcode").Value = barCodeText;//doc.PrintLabel(_printNum, 1, 1, 1, 1, "");//参数传值foreach (string barCode in barCodes){//BasicCode是变量,需要打印的码。doc.Variables.Item("BasicCode").Value = barCode;doc.PrintLabel(_printNum, 1, 1, 1, 1, "");}doc.FormFeed();}catch (Exception ex){//SSMessageBox.ShowError(ex.Message);return false;}finally{lab.Quit();}return true;}
1500字范文,内容丰富有趣,写作好帮手!