1
zrg
2024-10-15 a1e3e548ea03ceb32d07bf9f73f4719dd14f7f2e
WarM/ÌõÂë´òÓ¡/Gy_BarCodeBill_automaticallyByPLC_New.cs
@@ -14,6 +14,7 @@
using System.IO;
using System.Management;
using System.Net.NetworkInformation;
using System.Printing;
namespace WarM
{
@@ -407,22 +408,40 @@
        #region ç”ŸæˆæŒ‰é’®
        private void bc_Click(object sender, EventArgs e)
        {
            //审核权限
            if (!DBUtility.ClsPub.Security_Log_second("Gy_BarCodeBill_automaticallyByPLC_ProduceByHand", 1, false, DBUtility.ClsPub.CurUserName))
            {
                MessageBox.Show("生成失败,无权限!");
                return;
            }
            //清除打印任务
            string msg = "";
            if (!clearPrinterTask(ref msg))
            {
                MessageBox.Show(msg);
                return;
            }
            this.Sub_SaveBill();
            Display();
            //设置打印模板,打印
            grdList.Rows[0].Cells[0].Value = "*";
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
            if (comboBox_PrinterParams.Text != "")
            if (radioButton_IsPrint_Yes.Checked == true)
            {
                Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(默认)", "");
                //设置打印模板,打印
                grdList.Rows[0].Cells[0].Value = "*";
                Report = new GridppReport();
                Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
                Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
                Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
                Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
                if (comboBox_PrinterParams.Text != "")
                {
                    Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(默认)", "");
                }
                Report.Print(false);
            }
            Report.Print(false);
            Display4();
        }
        //保存单据
@@ -1156,9 +1175,43 @@
            return false;
        }
        //清除指定打印机任务
        private bool clearPrinterTask(ref string msg)
        {
            try
            {
                PrintServer localPrintServer = new LocalPrintServer();
                PrintQueue pq = localPrintServer.GetPrintQueue(comboBox_PrinterParams.Text.Replace("(默认)", "").ToLower());
                pq.Refresh();
                PrintJobInfoCollection allPrintJobs = pq.GetPrintJobInfoCollection();
                foreach (PrintSystemJobInfo printJob in allPrintJobs)
                {
                    printJob.Cancel();
                }
                return true;
            }
            catch(Exception ex)
            {
                msg = ex.Message;
                return false;
            }
        }
        //根据通讯信息生成条码并打印
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (produceQty > 0)
            {
                //清除打印任务
                string msg = "";
                if (!clearPrinterTask(ref msg))
                {
                    MessageBox.Show(msg);
                    produceQty = 0;
                }
            }
            for (int i = 0; i < produceQty; i++)
            {
                //生成条码
@@ -1167,18 +1220,21 @@
                //获取需要打印的数据
                Display();
                //设置打印模板,打印
                grdList.Rows[0].Cells[0].Value = "*";
                Report = new GridppReport();
                Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
                Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
                Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
                Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
                if (comboBox_PrinterParams.Text != "")
                if (radioButton_IsPrint_Yes.Checked == true)
                {
                    Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(默认)", "");
                    //设置打印模板,打印
                    grdList.Rows[0].Cells[0].Value = "*";
                    Report = new GridppReport();
                    Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + textBox_PrintModelParams.Text + ".grf");  //here .
                    Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
                    Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
                    Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
                    if (comboBox_PrinterParams.Text != "")
                    {
                        Report.Printer.PrinterName = comboBox_PrinterParams.Text.Replace("(默认)", "");
                    }
                    Report.Print(false);
                }
                Report.Print(false);
                if (i == produceQty - 1)
                {