From 33253e48c0f67a177cb0e41459b2a2785b49c5aa Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期四, 31 十月 2024 10:27:48 +0800
Subject: [PATCH] 工艺路线:调用h_p_Gy_RoutingBillCheck存储过程的地方加一个参数
---
WarM/条码打印/Gy_BarCodeBill_automaticallyByPLC_New.cs | 200 +++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 188 insertions(+), 12 deletions(-)
diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
index c29c99c..1ad2c42 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Gy_BarCodeBill_automaticallyByPLC_New.cs"
@@ -13,6 +13,8 @@
using System.Drawing.Printing;
using System.IO;
using System.Management;
+using System.Net.NetworkInformation;
+using System.Printing;
namespace WarM
{
@@ -406,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();
}
//淇濆瓨鍗曟嵁
@@ -1066,6 +1099,8 @@
Thread thread = new Thread(ReceiveMess);
thread.Start();
MessageBox.Show("杩炴帴鎴愬姛锛�");
+
+ timer3.Enabled = true;
}
catch (Exception ex)
{
@@ -1099,8 +1134,8 @@
}
catch (Exception ex)
{
- MessageBox.Show("鎺ュ彛寮傚父锛屽凡鍏抽棴杩炴帴锛�" + ex.Message);
- socket.Close();
+ //MessageBox.Show("鎺ュ彛寮傚父锛屽凡鍏抽棴杩炴帴锛�" + ex.Message);
+ //socket.Close();
}
}
@@ -1140,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++)
{
//鐢熸垚鏉$爜
@@ -1151,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)
{
@@ -1253,6 +1325,10 @@
catch (Exception ex)
{
MessageBox.Show(ex.Message);
+ }
+ finally
+ {
+ timer3.Enabled = false;
}
}
#endregion
@@ -2360,5 +2436,105 @@
}
}
+
+
+
+ #region 鏂嚎閲嶈繛
+ private int maxRepeatConnectTimes = 5;
+ private int currentRepeatConnectTimes = 0;
+
+ #region 瀹氭椂鍣ㄦ娴嬭繛鎺ョ姸鎬併�佹柇绾块噸杩�
+ private void timer3_Tick(object sender, EventArgs e)
+ {
+ if (currentRepeatConnectTimes < maxRepeatConnectTimes)
+ {
+ //鍒ゆ柇瀹㈡埛绔槸鍚﹀彲浠ヨ闂湇鍔″櫒锛岃嫢涓嶅彲浠ヨ闂紝鍏抽棴socket杩炴帴
+ if (!getTargetInternetStatus())
+ {
+ if (socket != null && socket.Connected)
+ {
+ socket.Close();
+ }
+
+ currentRepeatConnectTimes += 1;
+ }
+ else if (getTargetInternetStatus() && !socket.Connected)
+ {
+ //鑻ュ鎴风鍙互璁块棶鏈嶅姟鍣紝socket閲嶆柊杩炴帴鏈嶅姟鍣�
+ try
+ {
+ socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ IPAddress iPAddress = IPAddress.Parse(textBox_IPParams.Text);
+ IPEndPoint point = new IPEndPoint(iPAddress, Convert.ToInt32(textBox_PortParams.Text));
+ socket.Connect(point);
+
+ Thread thread = new Thread(ReceiveMess);
+ thread.Start();
+
+ currentRepeatConnectTimes = 0;
+ }
+ catch (Exception ex)
+ {
+ currentRepeatConnectTimes += 1;
+ }
+ }
+ }
+ else
+ {
+ //timer3.Enabled = false;
+ currentRepeatConnectTimes = 0;
+ MessageBox.Show("杩炴帴宸叉柇寮�锛岃閲嶆柊杩炴帴锛�!");
+ }
+ }
+ #endregion
+
+ #region 鑾峰彇鐩爣璁惧缃戠粶杩炴帴鐘舵��
+ private bool getTargetInternetStatus()
+ {
+ try
+ {
+ string targetIp = textBox_IPParams.Text; // 鏇挎崲涓虹洰鏍囩數鑴戠殑IP鍦板潃
+ Ping pingSender = new Ping();
+ PingOptions options = new PingOptions();
+ // 浣跨敤64瀛楄妭鐨勬暟鎹寘锛屸�屼綘鍙互鏍规嵁闇�瑕佽皟鏁磋繖涓��
+ string data = "Hello from Ping!";
+ byte[] buffer = Encoding.ASCII.GetBytes(data);
+ int timeout = 1200; // 瓒呮椂鏃堕棿锛屸�屽崟浣嶄负姣
+ PingReply reply = pingSender.Send(targetIp, timeout, buffer, options);
+
+ if (reply.Status == IPStatus.Success)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+
+ }
+ #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
}
}
\ No newline at end of file
--
Gitblit v1.9.1