chenhaozhe
2025-08-12 ffcef3d87676ebaf7f22413711b57bbe0404b3f2
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,9 +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();
            if (radioButton_IsPrint_Yes.Checked == true)
            {
                //设置打印模板,打印
                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);
            }
            Display4();
        }
        //保存单据
@@ -814,6 +846,7 @@
                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
                        HRemark = "PLC自动生成";
                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
@@ -920,14 +953,14 @@
                string LIU = "";
                int LEN = 4;
                DataSet ds;
                string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "' order by æ‰¹å· desc";
                string sql = "select * from h_v_IF_BarCodeBillList Where HMaterID = " + grdMain.Rows[0].Cells[HMaterIDCol].Value + " and HSTOCKORGID = " + HOrgID + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "' and å¤‡æ³¨ = 'PLC自动生成' order by æ‰¹å· desc";
                ds = oCn.RunProcReturn(sql, "h_v_IF_BarCodeBillList");
                if (ds != null)
                {
                    long count = 0;
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        count = ClsPub.isLong(ds.Tables[0].Rows[0]["批号"].ToString().Replace(sYear + sPeriod + sDay, ""));
                        count = ClsPub.isLong(ds.Tables[0].Rows[0]["批号"].ToString().Replace(sYear + sPeriod + sDay+" ", ""));
                    }
                    LIU += count + 1;
                    while (LIU.Length < LEN)  //如果流水号小于6位数前面补0
@@ -941,7 +974,7 @@
                }
                //拼接批号
                HBatchNo = sYear + sPeriod + sDay + LIU;
                HBatchNo = sYear + sPeriod + sDay+" " + LIU;
            }
@@ -1006,7 +1039,29 @@
            //拼接批号
            HBarCode_MaxNo = sYear + sPeriod + sDay + LIU;
            return HBarCode_MaxNo;
            long HBarCode_MaxNo_long = long.Parse(HBarCode_MaxNo);
            while (true)
            {
                int HCount_BarCodeBillList = 0;
                int HCount_SubBarCodeBill = 0;
                string sql_confirm = "select * from h_v_IF_BarCodeBillList where æ¡ç ç¼–号 = '" + (ClsPub.isStrNull(grdSub.Rows[0].Cells[HMaterModel2Col].Value) + HBarCode_MaxNo_long.ToString()) + "' and æ¡ç ç±»åž‹ = '唯一条码'" + " and CONVERT(varchar(100),条码日期, 23) = '" + HDate + "'";
                ds = oCn.RunProcReturn(sql_confirm, "h_v_IF_BarCodeBillList");
                HCount_BarCodeBillList = ds.Tables[0].Rows.Count;
                sql_confirm = "select * from Gy_BarCodeBill_SWELL_SubBarCodeBill Where HBarCode = '" + (ClsPub.isStrNull(grdSub.Rows[0].Cells[HMaterModel2Col].Value) + HBarCode_MaxNo_long.ToString()) + "' and HBarCodeType = '唯一条码'" + " and CONVERT(varchar(100),HMakeDate, 23) = '" + HDate + "'";
                ds = oCn.RunProcReturn(sql_confirm, "Gy_BarCodeBill_SWELL_SubBarCodeBill");
                HCount_SubBarCodeBill = ds.Tables[0].Rows.Count;
                if (HCount_BarCodeBillList + HCount_SubBarCodeBill > 0)
                {
                    HBarCode_MaxNo_long += 1;
                }
                else
                {
                    break;
                }
            }
            return HBarCode_MaxNo_long.ToString();
        }
        #endregion
@@ -1143,9 +1198,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++)
            {
                //生成条码
@@ -1154,18 +1243,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)
                {
@@ -2152,6 +2244,7 @@
                {
                    sMoney = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value) / ClsPub.isDoule(grdMain.Rows[sRow].Cells[HMinQtyCol].Value);
                }
                sMoney = Math.Round(sMoney, 10);    // ä¿ç•™10位小数进行四舍五入
                sMoney = Math.Ceiling(sMoney);
                grdMain.Rows[sRow].Cells[HBQtyCol].Value = sMoney;
            }
@@ -2412,7 +2505,7 @@
            }
            else
            {
                timer3.Enabled = false;
                //timer3.Enabled = false;
                currentRepeatConnectTimes = 0;
                MessageBox.Show("连接已断开,请重新连接!!");
            }
@@ -2451,6 +2544,21 @@
        #endregion
        #endregion
        #region å»ºç«‹é€šè®¯åŽï¼Œä¸æ–­å‘服务器发送数据,用于帮助服务端确定连接状态
        private void timer4_Tick(object sender, EventArgs e)
        {
            if (getTargetInternetStatus()&& socket!=null && socket.Connected)
            {
                try
                {
                    socket.Send(Encoding.ASCII.GetBytes("1"));
                }
                catch (Exception ex)
                {
                }
            }
        }
        #endregion
    }
}