From eeb7cf6accb95c32216edaf8a5cf14a1c64493b2 Mon Sep 17 00:00:00 2001
From: lu <123456>
Date: 星期四, 21 八月 2025 20:22:37 +0800
Subject: [PATCH] bug
---
/dev/null | 429 -----------------------------------------------
DevApp/Gs.DevApp/Gs.DevApp.csproj | 17 -
DevApp/Gs.DevApp/App.config | 8
DevApp/Gs.DevApp/Program.cs | 3
DevApp/Gs.DevApp/DevFrm/QC/WeightIqc.cs | 31 +-
5 files changed, 20 insertions(+), 468 deletions(-)
diff --git a/DevApp/Gs.DevApp/App.config b/DevApp/Gs.DevApp/App.config
index 199f753..d9fa3b0 100644
--- a/DevApp/Gs.DevApp/App.config
+++ b/DevApp/Gs.DevApp/App.config
@@ -34,12 +34,7 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
- <connectionStrings>
- <!--鏂扮粶V2鏁版嵁搴�-->
- <add name="conn" connectionString="RGF0YSBTb3VyY2U9MTkyLjE2OC4xLjQ7SW5pdGlhbCBDYXRhbG9nPVNOTUVTO1VzZXIgSWQ9c2M7UGFzc3dvcmQ9bWVzQDEyMztQb29saW5nPUZhbHNlO1Bvb2xpbmc9dHJ1ZTtNaW4gUG9vbCBTaXplPTEwO01heCBQb29sIFNpemU9NTA7Q29ubmVjdCBUaW1lb3V0PTUwMA==" />
- <!--<add name="conn" connectionString="RGF0YSBTb3VyY2U9MTkyLjE2OC4xLjI7SW5pdGlhbCBDYXRhbG9nPVFYX1NOTUVTO1VzZXIgSWQ9c2M7UGFzc3dvcmQ9bWVzQDEyMztQb29saW5nPUZhbHNlO1Bvb2xpbmc9dHJ1ZTtNaW4gUG9vbCBTaXplPTEwO01heCBQb29sIFNpemU9NTA7Q29ubmVjdCBUaW1lb3V0PTUwMA=="/>-->
- </connectionStrings>
-
+
<appSettings>
<!--<add key="WebApiUrl" value="http://localhost:5263/" />-->
<!--<add key="WebApiUrl" value="http://192.168.1.145:8081/" />-->
@@ -54,7 +49,6 @@
<add key="AsyncSeconds" value="2" /><!--姘存瓒呮椂鏃堕棿-->
<add key="IsWater" value="0" /><!--鏄惁瑕佹按妫�鍙婂伐浣嶇爜-->
<add key="IqcGetWeight" value="3000" /><!--iqc璇荤О閲嶆椂-->
- <add key="TimingMailInterval" value="10000" /><!--iqc绉伴噸鏃跺埛鏂�-->
</appSettings>
<userSettings>
<Gs.DevApp.Properties.Settings>
diff --git a/DevApp/Gs.DevApp/DevFrm/QC/WeightIqc.cs b/DevApp/Gs.DevApp/DevFrm/QC/WeightIqc.cs
index 69ddbf2..fc28335 100644
--- a/DevApp/Gs.DevApp/DevFrm/QC/WeightIqc.cs
+++ b/DevApp/Gs.DevApp/DevFrm/QC/WeightIqc.cs
@@ -74,7 +74,6 @@
this.SizeChanged += new EventHandler(this.frmMain_SizeChanged);
this.contextMenuStrip1.ItemClicked += new ToolStripItemClickedEventHandler(this.contextMenuStrip1_ItemClicked);
this.Initialize();
-
}
private void Initialize()
@@ -94,8 +93,9 @@
}
catch (Exception ex)
{
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
+ //int num = (int)MessageBox.Show(ex.Message);
+ //Application.Exit();
+ MsgHelper.ShowError("Initialize:" + ex.Message);
}
}
@@ -193,7 +193,8 @@
catch (Exception ex)
{
LoggerHelper.WriteErrorLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{ex.Message}");
- int num = (int)MessageBox.Show(ex.Message);
+ // int num = (int)MessageBox.Show(ex.Message);
+ MsgHelper.ShowError("UpdateTextBox:" + ex.Message);
}
}
@@ -281,19 +282,20 @@
}
catch (Exception ex)
{
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
+ //int num = (int)MessageBox.Show(ex.Message);
+ //Application.Exit();
+ MsgHelper.ShowError(ex.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
- if (!this.dicThread.Keys.Contains<string>("RefreshData"))
- {
- Thread thread = new Thread(new ThreadStart(this.RefreshData));
- thread.Start();
- this.dicThread.Add("RefreshData", thread);
- }
+ //if (!this.dicThread.Keys.Contains<string>("RefreshData"))
+ //{
+ // Thread thread = new Thread(new ThreadStart(this.RefreshData));
+ // thread.Start();
+ // this.dicThread.Add("RefreshData", thread);
+ //}
if (this.dicThread.Keys.Contains<string>("GetWeight"))
return;
Thread thread1 = new Thread(new ThreadStart(this.GetWeight));
@@ -331,8 +333,9 @@
}
catch (Exception ex)
{
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
+ //int num = (int)MessageBox.Show(ex.Message);
+ //Application.Exit();
+ MsgHelper.ShowError(ex.Message);
}
}
diff --git a/DevApp/Gs.DevApp/Gs.DevApp.csproj b/DevApp/Gs.DevApp/Gs.DevApp.csproj
index 92c2d08..e0eadc0 100644
--- a/DevApp/Gs.DevApp/Gs.DevApp.csproj
+++ b/DevApp/Gs.DevApp/Gs.DevApp.csproj
@@ -1143,18 +1143,10 @@
<Compile Include="DevFrm\WW\showWwZhongTai.Designer.cs">
<DependentUpon>showWwZhongTai.cs</DependentUpon>
</Compile>
- <Compile Include="test\LoggerHelper.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
- </Compile>
- <Compile Include="test\SQLHelper.cs" />
- <Compile Include="test\MainForm.cs">
- <SubType>Form</SubType>
- </Compile>
- <Compile Include="test\MainForm.Designer.cs">
- <DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="UserControl\SelectCk.cs">
<SubType>Form</SubType>
@@ -1561,12 +1553,6 @@
</Compile>
<Compile Include="XtraForm1.Designer.cs">
<DependentUpon>XtraForm1.cs</DependentUpon>
- </Compile>
- <Compile Include="XtraForm2.cs">
- <SubType>Form</SubType>
- </Compile>
- <Compile Include="XtraForm2.Designer.cs">
- <DependentUpon>XtraForm2.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="DevFrm\BasicData\Frm_Customer.resx">
<DependentUpon>Frm_Customer.cs</DependentUpon>
@@ -2205,9 +2191,6 @@
</EmbeddedResource>
<EmbeddedResource Include="XtraForm1.resx">
<DependentUpon>XtraForm1.cs</DependentUpon>
- </EmbeddedResource>
- <EmbeddedResource Include="XtraForm2.resx">
- <DependentUpon>XtraForm2.cs</DependentUpon>
</EmbeddedResource>
<None Include="App.config" />
<None Include="packages.config" />
diff --git a/DevApp/Gs.DevApp/Program.cs b/DevApp/Gs.DevApp/Program.cs
index b807218..5ab6b77 100644
--- a/DevApp/Gs.DevApp/Program.cs
+++ b/DevApp/Gs.DevApp/Program.cs
@@ -1,6 +1,7 @@
锘縰sing CefSharp;
using CefSharp.WinForms;
using Gs.DevApp.DevFrm;
+using Gs.DevApp.DevFrm.QC;
using Gs.DevApp.DevFrm.Work;
using Gs.DevApp.Properties;
using Gs.DevApp.ToolBox;
@@ -41,7 +42,7 @@
/// </summary>
private static void _startLogin()
{
- //Application.Run(new Gs.DevApp.test.MainForm());
+ //Application.Run(new WeightIqc());
//return;
CefSettings settings = new CefSettings();
settings.Locale = "zh-CN";
diff --git a/DevApp/Gs.DevApp/XtraForm2.Designer.cs b/DevApp/Gs.DevApp/XtraForm2.Designer.cs
deleted file mode 100644
index 8b2bf36..0000000
--- a/DevApp/Gs.DevApp/XtraForm2.Designer.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-锘縩amespace Gs.DevApp
-{
- partial class XtraForm2
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.cmbSerialPortNum = new DevExpress.XtraEditors.ImageComboBoxEdit();
- this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton();
- this.cmbBaudRate = new DevExpress.XtraEditors.ImageComboBoxEdit();
- this.simpleButton2 = new DevExpress.XtraEditors.SimpleButton();
- this.simpleButton3 = new DevExpress.XtraEditors.SimpleButton();
- ((System.ComponentModel.ISupportInitialize)(this.cmbSerialPortNum.Properties)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.cmbBaudRate.Properties)).BeginInit();
- this.SuspendLayout();
- //
- // cmbSerialPortNum
- //
- this.cmbSerialPortNum.Location = new System.Drawing.Point(32, 24);
- this.cmbSerialPortNum.Name = "cmbSerialPortNum";
- this.cmbSerialPortNum.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
- new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
- this.cmbSerialPortNum.Size = new System.Drawing.Size(125, 24);
- this.cmbSerialPortNum.TabIndex = 0;
- //
- // simpleButton1
- //
- this.simpleButton1.Location = new System.Drawing.Point(399, 13);
- this.simpleButton1.Name = "simpleButton1";
- this.simpleButton1.Size = new System.Drawing.Size(94, 29);
- this.simpleButton1.TabIndex = 1;
- this.simpleButton1.Text = "鍏堟墦寮�";
- this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
- //
- // cmbBaudRate
- //
- this.cmbBaudRate.Location = new System.Drawing.Point(32, 83);
- this.cmbBaudRate.Name = "cmbBaudRate";
- this.cmbBaudRate.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
- new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
- this.cmbBaudRate.Size = new System.Drawing.Size(125, 24);
- this.cmbBaudRate.TabIndex = 2;
- //
- // simpleButton2
- //
- this.simpleButton2.Location = new System.Drawing.Point(399, 78);
- this.simpleButton2.Name = "simpleButton2";
- this.simpleButton2.Size = new System.Drawing.Size(94, 29);
- this.simpleButton2.TabIndex = 3;
- this.simpleButton2.Text = "getWeight";
- this.simpleButton2.Click += new System.EventHandler(this.simpleButton2_Click);
- //
- // simpleButton3
- //
- this.simpleButton3.Location = new System.Drawing.Point(399, 153);
- this.simpleButton3.Name = "simpleButton3";
- this.simpleButton3.Size = new System.Drawing.Size(94, 29);
- this.simpleButton3.TabIndex = 4;
- this.simpleButton3.Text = "simpleButton3";
- this.simpleButton3.Click += new System.EventHandler(this.simpleButton3_Click);
- //
- // XtraForm2
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(613, 369);
- this.Controls.Add(this.simpleButton3);
- this.Controls.Add(this.simpleButton2);
- this.Controls.Add(this.cmbBaudRate);
- this.Controls.Add(this.simpleButton1);
- this.Controls.Add(this.cmbSerialPortNum);
- this.Name = "XtraForm2";
- this.Text = "娴嬭瘯绉伴噸";
- ((System.ComponentModel.ISupportInitialize)(this.cmbSerialPortNum.Properties)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.cmbBaudRate.Properties)).EndInit();
- this.ResumeLayout(false);
-
- }
-
- #endregion
-
- private DevExpress.XtraEditors.ImageComboBoxEdit cmbSerialPortNum;
- private DevExpress.XtraEditors.SimpleButton simpleButton1;
- private DevExpress.XtraEditors.ImageComboBoxEdit cmbBaudRate;
- private DevExpress.XtraEditors.SimpleButton simpleButton2;
- private DevExpress.XtraEditors.SimpleButton simpleButton3;
- }
-}
\ No newline at end of file
diff --git a/DevApp/Gs.DevApp/XtraForm2.cs b/DevApp/Gs.DevApp/XtraForm2.cs
deleted file mode 100644
index 6772666..0000000
--- a/DevApp/Gs.DevApp/XtraForm2.cs
+++ /dev/null
@@ -1,291 +0,0 @@
-锘縰sing DevExpress.XtraEditors;
-using DevExpress.XtraEditors.Controls;
-using DevExpress.XtraGrid;
-using DevExpress.XtraGrid.Columns;
-using DevExpress.XtraGrid.Views.Base;
-using DevExpress.XtraGrid.Views.Grid;
-using DevExpress.XtraWaitForm;
-using Gs.DevApp.ToolBox;
-using Microsoft.Win32;
-using NModbus;
-using NModbus.Device;
-using NModbus.Serial;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Configuration;
-using System.Data;
-using System.Drawing;
-using System.IO.Ports;
-using System.Linq;
-using System.Windows.Forms;
-using static DevExpress.Data.Filtering.Helpers.SubExprHelper.ThreadHoppingFiltering;
-using DateTime = System.DateTime;
-
-namespace Gs.DevApp
-{
- public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
- {
- public delegate void HandleInterfaceUpdataDelegate(string text);
- public SerialPort Sp = new SerialPort();
- private XtraForm2.HandleInterfaceUpdataDelegate interfaceUpdataHandle;
- public XtraForm2()
- {
- InitializeComponent();
- this.cmbBaudRate.EditValue = (object)"9600";
- this.GetComList();
- }
-
- private void GetComList()
- {
- this.cmbSerialPortNum.Properties.Items.Clear();
-
- this.cmbBaudRate.Properties.Items.AddRange(new ImageComboBoxItem[5]
- {
- new ImageComboBoxItem("14400", (object) "14400", -1),
- new ImageComboBoxItem("9600", (object) "9600", -1),
- new ImageComboBoxItem("4800", (object) "4800", -1),
- new ImageComboBoxItem("2400", (object) "2400", -1),
- new ImageComboBoxItem("1200", (object) "1200", -1)
- });
-
-
- RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
- if (registryKey == null)
- return;
- foreach (string valueName in registryKey.GetValueNames())
- {
- string description = (string)registryKey.GetValue(valueName);
- this.cmbSerialPortNum.Properties.Items.Add(new ImageComboBoxItem(description, (object)description));
- }
- if (this.cmbSerialPortNum.Properties.Items.Count > 0)
- this.cmbSerialPortNum.SelectedIndex = 0;
- }
-
- public void GetWeight()
- {
- ModbusFactory factory = new ModbusFactory();
- LogHelper.Debug(this.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":鍒涘缓modbus瀵硅薄...");
- IModbusMaster rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- bool flag = true;
- while (true)
- {
- try
- {
- if (!this.Sp.IsOpen)
- {
- LogHelper.Debug(this.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":閲嶆柊鎵撳紑涓插彛杩炴帴...");
- this.Sp.Open();
- rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- }
- if (rtuMaster == null)
- {
- LogHelper.Debug(this.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":閲嶆柊鍒涘缓modbus瀵硅薄...");
- rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- }
- // DataTable dataTable = this._sqlHelper.ExecuteDataTable("\r\nselect top 1 * from WOMZLA(nolock) \r\nwhere ZLA004=convert(varchar(10),getdate(),120) and ZLA003='IQC' and ZLA008='N'\r\norder by ZLA005");
- //if (dataTable != null && dataTable.Rows.Count > 0)
- //{
- // // LoggerHelper.WriteInfoLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:鍙戦�佷笂涓嬮檺鏁版嵁锛歿dataTable.Rows[0]["ZLA006"]}|{dataTable.Rows[0]["ZLA007"]}");
- // byte slaveAddress1 = byte.Parse("1");
- // ushort startAddress1 = ushort.Parse("0104");
- // ushort[] ushort2_1 = this.stringToUshort2(dataTable.Rows[0]["ZLA006"].ToString());
- // rtuMaster.WriteMultipleRegisters(slaveAddress1, startAddress1, ushort2_1);
- // byte slaveAddress2 = byte.Parse("1");
- // ushort startAddress2 = ushort.Parse("0102");
- // ushort[] ushort2_2 = this.stringToUshort2(dataTable.Rows[0]["ZLA007"].ToString());
- // rtuMaster.WriteMultipleRegisters(slaveAddress2, startAddress2, ushort2_2);
- // this._sqlHelper.ExecuteNonQuery($"update WOMZLA set ZLA008='Y',ZLA009=convert(varchar(20),getdate(),120) where ZLA001='{dataTable.Rows[0]["ZLA001"]}'");
- //}
- //else
- {
- byte slaveAddress3 = byte.Parse("1");
- ushort startAddress3 = ushort.Parse("0002");
- ushort numberOfPoints1 = ushort.Parse("2");
- ushort[] numArray = rtuMaster.ReadHoldingRegisters(slaveAddress3, startAddress3, numberOfPoints1);
- float single = BitConverter.ToSingle(this.CombomBinaryArray(BitConverter.GetBytes(numArray[1]), BitConverter.GetBytes(numArray[0])), 0);
- this.Invoke((Delegate)this.interfaceUpdataHandle, (object)single.ToString());
- byte slaveAddress4 = byte.Parse("1");
- ushort startAddress4 = ushort.Parse("0001");
- ushort numberOfPoints2 = ushort.Parse("1");
- int int32 = Convert.ToInt32(rtuMaster.ReadHoldingRegisters(slaveAddress4, startAddress4, numberOfPoints2)[0].ToString());
- string str = Convert.ToString(int32, 2).PadLeft(16 /*0x10*/, '0');
- char ch1 = str[1];
- char ch2 = str[6];
- if (ch1 == '0' && ch2 == '0')
- {
- // this._sqlHelper.ExecuteNonQuery($"\r\nif not exists(select 1 from WOMZLB(nolock) where ZLB001='IQC' and ZLB002='{single.ToString()}' and ZLB003='{int32.ToString()}')\r\nbegin\r\n if exists(select 1 from WOMZLB(nolock) where ZLB001='IQC')\r\n begin\r\n\t update WOMZLB set ZLB002='{single.ToString()}',ZLB003='{int32.ToString()}' where ZLB001='IQC'\r\n end\r\n else\r\n begin\r\n\t insert into WOMZLB(ZLB001,ZLB002,ZLB003)\r\n\t select 'IQC','{single.ToString()}','{int32.ToString()}'\r\n end\r\nend\r\n");
- flag = true;
- }
- else if (flag)
- {
- // this._sqlHelper.ExecuteNonQuery($"\r\nif not exists(select 1 from WOMZLB(nolock) where ZLB001='IQC' and ZLB002='{single.ToString()}' and ZLB003='{int32.ToString()}')\r\nbegin\r\n if exists(select 1 from WOMZLB(nolock) where ZLB001='IQC')\r\n begin\r\n\t update WOMZLB set ZLB002='0',ZLB003='{int32.ToString()}' where ZLB001='IQC'\r\n end\r\n else\r\n begin\r\n\t insert into WOMZLB(ZLB001,ZLB002,ZLB003)\r\n\t select 'IQC','0','{int32.ToString()}'\r\n end\r\nend\r\n");
- flag = false;
- }
- MessageBox.Show(single.ToString() + ":" + int32.ToString());
- LogHelper.Debug(this.ToString(), "single:" + single.ToString());
- LogHelper.Debug(this.ToString(), "int32:" + int32.ToString());
- }
- // Thread.Sleep(2000);
- }
- catch (Exception ex)
- {
- // Thread.Sleep(2000);
- MessageBox.Show(ex.Message);
- LogHelper.Debug(this.ToString(), "single:" + ex.Message);
- }
- }
- }
- private byte[] CombomBinaryArray(byte[] srcArray1, byte[] srcArray2)
- {
- byte[] destinationArray = new byte[srcArray1.Length + srcArray2.Length];
- Array.Copy((Array)srcArray1, 0, (Array)destinationArray, 0, srcArray1.Length);
- Array.Copy((Array)srcArray2, 0, (Array)destinationArray, srcArray1.Length, srcArray2.Length);
- return destinationArray;
- }
- private void simpleButton1_Click(object sender, EventArgs e)
- {
- try
- {
- DateTime now = DateTime.Now;
- // LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":寮�濮嬮噰闆�");
- if (this.cmbBaudRate.Text.Trim() != "" && this.cmbSerialPortNum.Text != "")
- {
- now = DateTime.Now;
- // LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":閰嶇疆涓插彛閫氫俊");
- // this.interfaceUpdataHandle = new MainForm.HandleInterfaceUpdataDelegate(this.UpdateTextBox);
- this.Sp.PortName = this.cmbSerialPortNum.Text.Trim();
- this.Sp.BaudRate = Convert.ToInt32(this.cmbBaudRate.Text.Trim());
- this.Sp.Parity = Parity.None;
- this.Sp.StopBits = StopBits.One;
- now = DateTime.Now;
- // LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":鎵撳紑涓插彛鍚岄�氫俊");
- this.Sp.Open();
- MessageBox.Show("鎵撳紑鎴愬姛Sp:" + Sp.IsOpen.ToString());
- //this.button1.Enabled = false;
- //this.button2.Enabled = true;
- //this.timer1.Enabled = false;
- //now = DateTime.Now;
- //LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":鍚姩鍒锋柊鏁版嵁瀹氭椂鍣�");
- //this.timer1.Start();
- }
- else
- {
- now = DateTime.Now;
- // LoggerHelper.WriteErrorLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":璇疯緭鍏ユ纭殑绔彛鍙峰拰娉㈢壒鐜�");
- int num = (int)MessageBox.Show("璇疯緭鍏ユ纭殑绔彛鍙峰拰娉㈢壒鐜囷紒");
- this.cmbSerialPortNum.Focus();
- }
- }
- catch (Exception ex)
- {
- // LoggerHelper.WriteErrorLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{ex.Message}");
- int num = (int)MessageBox.Show($"绔彛{this.cmbSerialPortNum.Text.Trim()}鎵撳紑澶辫触锛亄ex.Message}");
- }
- }
-
- private void simpleButton2_Click(object sender, EventArgs e)
- {
- GetWeight();
- }
-
- public void ReadWeight222()
- {
- ModbusFactory factory = new ModbusFactory();
- try
- {
- // 1. 閰嶇疆涓插彛鍙傛暟锛堥渶涓庣數瀛愮Г涓�鑷达級
- string portName = "COM1"; // 涓插彛鍙�
- int baudRate = 9600; // 娉㈢壒鐜�
- Parity parity = Parity.None; // 鏍¢獙浣�
- int dataBits = 8; // 鏁版嵁浣�
- StopBits stopBits = StopBits.One; // 鍋滄浣�
-
- // 2. 鍒涘缓涓插彛杩炴帴
- SerialPort serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
- serialPort.Open();
-
- // 3. 鍒涘缓Modbus RTU涓荤珯
- IModbusMaster master = (IModbusMaster)factory.CreateRtuMaster(serialPort);
- // 4. 閰嶇疆璇诲彇鍙傛暟
- //byte slaveId = 1; // 浠庣珯鍦板潃锛堢數瀛愮Г鐨凪odbus鍦板潃锛�
- //ushort startAddress = 0; // 瀵勫瓨鍣ㄨ捣濮嬪湴鍧�锛�40001瀵瑰簲鍦板潃0锛�
- //ushort numRegisters = 2; // 璇诲彇2涓瘎瀛樺櫒锛�32浣嶆暟鎹級
-
-
- byte slaveAddress3 = byte.Parse("1");
- ushort startAddress3 = ushort.Parse("0");
- ushort numberOfPoints1 = ushort.Parse("2");
- // 5. 璇诲彇淇濇寔瀵勫瓨鍣�
- ushort[] registers = master.ReadHoldingRegisters(slaveAddress3, startAddress3, numberOfPoints1);
-
- // 6. 澶勭悊杩斿洖鏁版嵁锛堝亣璁炬暟鎹负32浣嶆诞鐐规暟锛屽ぇ绔牸寮忥級
- byte[] bytes = new byte[4];
- Buffer.BlockCopy(registers, 0, bytes, 0, 4);
-
- // 澶勭悊瀛楄妭搴忥紙鏍规嵁璁惧瑕佹眰鍙兘闇�瑕佽皟鏁达級
- if (BitConverter.IsLittleEndian)
- {
- Array.Reverse(bytes); // 濡傛灉璁惧鏄ぇ绔ā寮忥紝闇�瑕佸弽杞瓧鑺�
- }
-
- // 杞崲涓烘诞鐐规暟
- float weight = BitConverter.ToSingle(bytes, 0);
-
- MessageBox.Show(weight.ToString());
- }
- catch (Exception ex)
- {
- Console.WriteLine($"璇诲彇澶辫触: {ex.Message}");
- MessageBox.Show("err:" + ex.Message.ToString());
- }
- }
-
- private void simpleButton3_Click(object sender, EventArgs e)
- {
- ModbusFactory factory = new ModbusFactory();
- // 1. 閰嶇疆涓插彛鍙傛暟
- SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
- serialPort.Open();
-
-
- // 鏋勯�犺嚜瀹氫箟鍔熻兘鐮佽姹傚抚锛堢ず渚嬶細鍔熻兘鐮� 0x31锛�
- byte[] request = new byte[] { 0x01, 0x31, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00 };
- serialPort.Write(request, 0, request.Length);
-
- // 璇诲彇鍝嶅簲
- byte[] buffer = new byte[256];
- int bytesRead = serialPort.Read(buffer, 0, buffer.Length);
- MessageBox.Show($"鍝嶅簲鏁版嵁: {BitConverter.ToString(buffer, 0, bytesRead)}");
-
- //serialPort.Close();
-
- // 2. 鍒涘缓Modbus RTU涓荤珯
- IModbusMaster modbusMaster = (IModbusMaster)factory.CreateRtuMaster(serialPort);
- try
- {
- while (true)
- {
- // 3. 璇诲彇淇濇寔瀵勫瓨鍣紙浠庣珯鍦板潃1锛岃捣濮嬪湴鍧�0x0001锛岃鍙�2涓瘎瀛樺櫒锛�
- ushort[] registers = modbusMaster.ReadHoldingRegisters(1, 0x0001, 2);
- MessageBox.Show("d");
- // 4. 瑙f瀽鏁版嵁锛堝亣璁惧瘎瀛樺櫒瀛樺偍鐨勬槸閲嶉噺鍊硷紝鍗曚綅涓哄厠锛�
- int weight = (registers[0] << 16) + registers[1];
- Console.WriteLine($"閲嶉噺鍊�: {weight} g");
- MessageBox.Show($"閲嶉噺鍊�: {weight} g");
- System.Threading.Thread.Sleep(1000); // 姣忕璇诲彇涓�娆�
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- Console.WriteLine($"閿欒: {ex.Message}");
- }
- finally
- {
- serialPort.Close();
- }
-
- }
- }
-}
\ No newline at end of file
diff --git a/DevApp/Gs.DevApp/XtraForm2.resx b/DevApp/Gs.DevApp/XtraForm2.resx
deleted file mode 100644
index 1af7de1..0000000
--- a/DevApp/Gs.DevApp/XtraForm2.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-锘�<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
-</root>
\ No newline at end of file
diff --git a/DevApp/Gs.DevApp/test/LoggerHelper.cs b/DevApp/Gs.DevApp/test/LoggerHelper.cs
deleted file mode 100644
index dc9453a..0000000
--- a/DevApp/Gs.DevApp/test/LoggerHelper.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-锘�// Decompiled with JetBrains decompiler
-// Type: ChengZhongModbus.LoggerHelper
-// Assembly: ChengZhongModbusIQC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
-// MVID: 335383E6-9854-4BCE-8CD7-BF94F8E1A377
-// Assembly location: C:\Users\Administrator\Desktop\ChengZhongModbusIQC\ChengZhongModbusIQC.exe
-
-using DevExpress.Xpo.Logger;
-using System;
-using System.Configuration;
-using System.IO;
-
-public class LoggerHelper
-{ //鍒涘缓鏃ュ織鐩綍
- private static readonly string path = AppContext.BaseDirectory +
- ConfigurationManager.AppSettings[
- "LogPath"];
- /**
- * 瀹為檯鐨勫啓鏃ュ織鎿嶄綔
- * @param type 鏃ュ織璁板綍绫诲瀷
- * @param className 绫诲悕
- * @param content 鍐欏叆鍐呭
- */
- protected static void WriteLog(string type, string className,
- string content)
- {
- if (!Directory.Exists(path)) //濡傛灉鏃ュ織鐩綍涓嶅瓨鍦ㄥ氨鍒涘缓
- Directory.CreateDirectory(path);
- var time =
- DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); //鑾峰彇褰撳墠绯荤粺鏃堕棿
- var filename = path + "/" + DateTime.Now.ToString("yyyy-MM-dd") +
- ".log"; //鐢ㄦ棩鏈熷鏃ュ織鏂囦欢鍛藉悕
- //鍒涘缓鎴栨墦寮�鏃ュ織鏂囦欢锛屽悜鏃ュ織鏂囦欢鏈熬杩藉姞璁板綍
- var mySw = File.AppendText(filename);
- //鍚戞棩蹇楁枃浠跺啓鍏ュ唴瀹�
- var write_content =
- time + " " + type + " " + className + ": " + content;
- mySw.WriteLine(write_content);
- //鍏抽棴鏃ュ織鏂囦欢
- mySw.Close();
- }
-
-
- public static void WriteInfoLog(string info)
- {
- WriteLog("DEBUG", "", info);
- }
-
- public static void WriteErrorLog(string info)
- {
- WriteLog("DEBUG", "", info);
- }
-}
diff --git a/DevApp/Gs.DevApp/test/MainForm.Designer.cs b/DevApp/Gs.DevApp/test/MainForm.Designer.cs
deleted file mode 100644
index 2528d09..0000000
--- a/DevApp/Gs.DevApp/test/MainForm.Designer.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-锘縩amespace Gs.DevApp.test
-{
- partial class MainForm
- {
- ///// <summary>
- ///// Required designer variable.
- ///// </summary>
- //private System.ComponentModel.IContainer components = null;
-
- ///// <summary>
- ///// Clean up any resources being used.
- ///// </summary>
- ///// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- //protected override void Dispose(bool disposing)
- //{
- // if (disposing && (components != null))
- // {
- // components.Dispose();
- // }
- // base.Dispose(disposing);
- //}
-
- //#region Windows Form Designer generated code
-
- ///// <summary>
- ///// Required method for Designer support - do not modify
- ///// the contents of this method with the code editor.
- ///// </summary>
- //private void InitializeComponent()
- //{
- // this.components = new System.ComponentModel.Container();
- // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- // this.Text = "MainForm";
- //}
-
- // #endregion
- }
-}
\ No newline at end of file
diff --git a/DevApp/Gs.DevApp/test/MainForm.cs b/DevApp/Gs.DevApp/test/MainForm.cs
deleted file mode 100644
index f94c41d..0000000
--- a/DevApp/Gs.DevApp/test/MainForm.cs
+++ /dev/null
@@ -1,709 +0,0 @@
-锘縰sing DevExpress.XtraEditors;
-using DevExpress.XtraEditors.Controls;
-using DevExpress.XtraGrid;
-using DevExpress.XtraGrid.Columns;
-using DevExpress.XtraGrid.Views.Base;
-using DevExpress.XtraGrid.Views.Grid;
-using Microsoft.Win32;
-using NModbus;
-using NModbus.Serial;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Configuration;
-using System.Data;
-using System.Drawing;
-using System.IO.Ports;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Windows.Forms;
-namespace Gs.DevApp.test
-{
- public partial class MainForm : DevExpress.XtraEditors.XtraForm
- {
- private SQLHelper _sqlHelper;
- public SerialPort Sp = new SerialPort();
- private MainForm.HandleInterfaceUpdataDelegate interfaceUpdataHandle;
- private string strLine = "";
- private string sqlWOMQAB = "";
- private Dictionary<string, Thread> dicThread = new Dictionary<string, Thread>();
- private StringBuilder sb = new StringBuilder();
- private IContainer components = (IContainer)null;
- private SplitContainerControl splitContainerControl1;
- private ImageComboBoxEdit cmbBaudRate;
- private LabelControl labelControl1;
- private TextEdit txtNum;
- private LabelControl labelControl3;
- private SimpleButton button2;
- private SimpleButton button1;
- private SimpleButton btnRefashC;
- private ImageComboBoxEdit cmbSerialPortNum;
- private LabelControl labelControl2;
- private GridControl gridWOMQAB;
- private GridView viewWOMQAB;
- private GridColumn colQAB001;
- private GridColumn colQAB002;
- private GridColumn colQAB003;
- private GridColumn colQAB005;
- private GridColumn colQAB006;
- private GridColumn colQAB007;
- private GridColumn colQAB009;
- private GridColumn colQAB010;
- private GridColumn colMIH004;
- private GridColumn colPAA002;
- private GridColumn colQAB015;
- private GridColumn colQAB025;
- private GridColumn colMCA022;
- private GridColumn colZT;
- private GridColumn colMCA023;
- private NotifyIcon notifyIcon1;
- private ContextMenuStrip contextMenuStrip1;
- private System.Windows.Forms.Timer timer1;
- private ToolStripMenuItem showInTaskbar;
- private ToolStripMenuItem exitWindow;
-
- public MainForm()
- {
- this.InitializeComponent();
- this.timer1.Tick += new EventHandler(this.timer1_Tick);
- this.notifyIcon1.DoubleClick += new EventHandler(this.notifyIcon1_DoubleClick);
- this.SizeChanged += new EventHandler(this.frmMain_SizeChanged);
- this.contextMenuStrip1.ItemClicked += new ToolStripItemClickedEventHandler(this.contextMenuStrip1_ItemClicked);
- this.Initialize();
- }
-
- private void Initialize()
- {
- try
- {
- this._sqlHelper = new SQLHelper(Encoding.Default.GetString(Convert.FromBase64String(ConfigurationManager.ConnectionStrings["conn"].ConnectionString)));
- int int32 = Convert.ToInt32(ConfigurationManager.AppSettings["TimingMailInterval"]);
- string appSetting = ConfigurationManager.AppSettings["thisText"];
- this.Text = appSetting;
- this.notifyIcon1.Text = appSetting;
- this.timer1.Interval = int32;
- this.button1.Enabled = true;
- this.button2.Enabled = false;
- }
- catch (Exception ex)
- {
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
- }
- }
-
- private void GetComList()
- {
- this.cmbSerialPortNum.Properties.Items.Clear();
- RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
- if (registryKey == null)
- return;
- foreach (string valueName in registryKey.GetValueNames())
- {
- string description = (string)registryKey.GetValue(valueName);
- this.cmbSerialPortNum.Properties.Items.Add(new ImageComboBoxItem(description, (object)description));
- }
- if (this.cmbSerialPortNum.Properties.Items.Count > 0)
- this.cmbSerialPortNum.SelectedIndex = 0;
- }
-
- public void RefreshData()
- {
- while (true)
- {
- try
- {
- Thread.Sleep(10000);
- }
- catch (Exception ex)
- {
- Thread.Sleep(10000);
- }
- }
- }
-
- public void GetWeight()
- {
- ModbusFactory factory = new ModbusFactory();
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":鍒涘缓modbus瀵硅薄...");
- IModbusMaster rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- bool flag = true;
- while (true)
- {
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":while...");
- try
- {
- if (!this.Sp.IsOpen)
- {
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":閲嶆柊鎵撳紑涓插彛杩炴帴...");
- this.Sp.Open();
- rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- }
- if (rtuMaster == null)
- {
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":閲嶆柊鍒涘缓modbus瀵硅薄...");
- rtuMaster = (IModbusMaster)factory.CreateRtuMaster(this.Sp);
- }
- DataTable dataTable = this._sqlHelper.ExecuteDataTable("\r\nselect top 1 * from WOMZLA(nolock) \r\nwhere ZLA004=convert(varchar(10),getdate(),120) and ZLA003='IQC' and ZLA008='N'\r\norder by ZLA005");
- if (dataTable != null && dataTable.Rows.Count > 0)
- {
- LoggerHelper.WriteInfoLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:鍙戦�佷笂涓嬮檺鏁版嵁锛歿dataTable.Rows[0]["ZLA006"]}|{dataTable.Rows[0]["ZLA007"]}");
- byte slaveAddress1 = byte.Parse("1");
- ushort startAddress1 = ushort.Parse("0104");
- ushort[] ushort2_1 = this.stringToUshort2(dataTable.Rows[0]["ZLA006"].ToString());
- rtuMaster.WriteMultipleRegisters(slaveAddress1, startAddress1, ushort2_1);
- byte slaveAddress2 = byte.Parse("1");
- ushort startAddress2 = ushort.Parse("0102");
- ushort[] ushort2_2 = this.stringToUshort2(dataTable.Rows[0]["ZLA007"].ToString());
- rtuMaster.WriteMultipleRegisters(slaveAddress2, startAddress2, ushort2_2);
- this._sqlHelper.ExecuteNonQuery($"update WOMZLA set ZLA008='Y',ZLA009=convert(varchar(20),getdate(),120) where ZLA001='{dataTable.Rows[0]["ZLA001"]}'");
- }
- else
- {
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":else...");
- byte slaveAddress3 = byte.Parse("1");
- ushort startAddress3 = ushort.Parse("0002");
- ushort numberOfPoints1 = ushort.Parse("2");
- ushort[] numArray = rtuMaster.ReadHoldingRegisters(slaveAddress3, startAddress3, numberOfPoints1);
- float single = BitConverter.ToSingle(this.CombomBinaryArray(BitConverter.GetBytes(numArray[1]), BitConverter.GetBytes(numArray[0])), 0);
- this.Invoke((Delegate)this.interfaceUpdataHandle, (object)single.ToString());
- byte slaveAddress4 = byte.Parse("1");
- ushort startAddress4 = ushort.Parse("0001");
- ushort numberOfPoints2 = ushort.Parse("1");
- int int32 = Convert.ToInt32(rtuMaster.ReadHoldingRegisters(slaveAddress4, startAddress4, numberOfPoints2)[0].ToString());
- string str = Convert.ToString(int32, 2).PadLeft(16 /*0x10*/, '0');
- char ch1 = str[1];
- char ch2 = str[6];
- if (ch1 == '0' && ch2 == '0')
- {
- this._sqlHelper.ExecuteNonQuery($"\r\nif not exists(select 1 from WOMZLB(nolock) where ZLB001='IQC' and ZLB002='{single.ToString()}' and ZLB003='{int32.ToString()}')\r\nbegin\r\n if exists(select 1 from WOMZLB(nolock) where ZLB001='IQC')\r\n begin\r\n\t update WOMZLB set ZLB002='{single.ToString()}',ZLB003='{int32.ToString()}' where ZLB001='IQC'\r\n end\r\n else\r\n begin\r\n\t insert into WOMZLB(ZLB001,ZLB002,ZLB003)\r\n\t select 'IQC','{single.ToString()}','{int32.ToString()}'\r\n end\r\nend\r\n");
- flag = true;
- }
- else if (flag)
- {
- this._sqlHelper.ExecuteNonQuery($"\r\nif not exists(select 1 from WOMZLB(nolock) where ZLB001='IQC' and ZLB002='{single.ToString()}' and ZLB003='{int32.ToString()}')\r\nbegin\r\n if exists(select 1 from WOMZLB(nolock) where ZLB001='IQC')\r\n begin\r\n\t update WOMZLB set ZLB002='0',ZLB003='{int32.ToString()}' where ZLB001='IQC'\r\n end\r\n else\r\n begin\r\n\t insert into WOMZLB(ZLB001,ZLB002,ZLB003)\r\n\t select 'IQC','0','{int32.ToString()}'\r\n end\r\nend\r\n");
- flag = false;
- }
- LoggerHelper.WriteInfoLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":lse:"+ single.ToString());
- }
- Thread.Sleep(2000);
- }
- catch (Exception ex)
- {
- Thread.Sleep(2000);
- }
- }
- }
-
- private void UpdateTextBox(string text)
- {
- try
- {
- if (this.txtNum.Text == text)
- return;
- this.txtNum.Text = text;
- }
- catch (Exception ex)
- {
- LoggerHelper.WriteErrorLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{ex.Message}");
- int num = (int)MessageBox.Show(ex.Message);
- }
- }
-
- public ushort[] stringToUshort2(string inString)
- {
- byte[] bytes = BitConverter.GetBytes(float.Parse(inString));
- ushort uint16 = BitConverter.ToUInt16(bytes, 0);
- return new ushort[2]
- {
- BitConverter.ToUInt16(bytes, 2),
- uint16
- };
- }
-
- private byte[] CombomBinaryArray(byte[] srcArray1, byte[] srcArray2)
- {
- byte[] destinationArray = new byte[srcArray1.Length + srcArray2.Length];
- Array.Copy((Array)srcArray1, 0, (Array)destinationArray, 0, srcArray1.Length);
- Array.Copy((Array)srcArray2, 0, (Array)destinationArray, srcArray1.Length, srcArray2.Length);
- return destinationArray;
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- DateTime now = DateTime.Now;
- LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":寮�濮嬮噰闆�");
- if (this.cmbBaudRate.Text.Trim() != "" && this.cmbSerialPortNum.Text != "")
- {
- now = DateTime.Now;
- LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":閰嶇疆涓插彛閫氫俊");
- this.interfaceUpdataHandle = new MainForm.HandleInterfaceUpdataDelegate(this.UpdateTextBox);
- this.Sp.PortName = this.cmbSerialPortNum.Text.Trim();
- this.Sp.BaudRate = Convert.ToInt32(this.cmbBaudRate.Text.Trim());
- this.Sp.Parity = Parity.None;
- this.Sp.StopBits = StopBits.One;
- now = DateTime.Now;
- LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":鎵撳紑涓插彛鍚岄�氫俊");
- this.Sp.Open();
- this.button1.Enabled = false;
- this.button2.Enabled = true;
- this.timer1.Enabled = false;
- now = DateTime.Now;
- LoggerHelper.WriteInfoLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":鍚姩鍒锋柊鏁版嵁瀹氭椂鍣�");
- this.timer1.Start();
- }
- else
- {
- now = DateTime.Now;
- LoggerHelper.WriteErrorLog(now.ToString("yyyy-MM-dd HH:mm:ss") + ":璇疯緭鍏ユ纭殑绔彛鍙峰拰娉㈢壒鐜�");
- int num = (int)MessageBox.Show("璇疯緭鍏ユ纭殑绔彛鍙峰拰娉㈢壒鐜囷紒");
- this.cmbSerialPortNum.Focus();
- }
- }
- catch (Exception ex)
- {
- LoggerHelper.WriteErrorLog($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{ex.Message}");
- int num = (int)MessageBox.Show($"绔彛{this.cmbSerialPortNum.Text.Trim()}鎵撳紑澶辫触锛亄ex.Message}");
- }
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dicThread.Keys.Contains<string>("RefreshData"))
- {
- Thread thread = this.dicThread["RefreshData"];
- if (thread.IsAlive)
- thread.Abort();
- this.dicThread.Remove("RefreshData");
- }
- if (this.dicThread.Keys.Contains<string>("GetWeight"))
- {
- Thread thread = this.dicThread["GetWeight"];
- if (thread.IsAlive)
- thread.Abort();
- this.dicThread.Remove("GetWeight");
- }
- this.button1.Enabled = true;
- this.button2.Enabled = false;
- this.timer1.Stop();
- this.Sp.Close();
- }
- catch (Exception ex)
- {
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
- }
- }
-
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (!this.dicThread.Keys.Contains<string>("RefreshData"))
- {
- Thread thread = new Thread(new ThreadStart(this.RefreshData));
- thread.Start();
- this.dicThread.Add("RefreshData", thread);
- }
- if (this.dicThread.Keys.Contains<string>("GetWeight"))
- return;
- Thread thread1 = new Thread(new ThreadStart(this.GetWeight));
- thread1.Start();
- this.dicThread.Add("GetWeight", thread1);
- }
-
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- if (this.dicThread.Keys.Contains<string>("RefreshData"))
- {
- Thread thread = this.dicThread["RefreshData"];
- if (thread.IsAlive)
- thread.Abort();
- this.dicThread.Remove("RefreshData");
- }
- if (this.dicThread.Keys.Contains<string>("GetWeight"))
- {
- Thread thread = this.dicThread["GetWeight"];
- if (thread.IsAlive)
- thread.Abort();
- this.dicThread.Remove("GetWeight");
- }
- this.timer1.Stop();
- this.Sp.Close();
- }
- catch (Exception ex)
- {
- int num = (int)MessageBox.Show(ex.Message);
- Application.Exit();
- }
- }
-
- private void Form1_Load(object sender, EventArgs e) => this.GetComList();
-
- private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- if (e.ClickedItem == this.showInTaskbar)
- {
- if (this.WindowState != FormWindowState.Minimized)
- return;
- this.WindowState = FormWindowState.Normal;
- this.Activate();
- this.ShowInTaskbar = true;
- this.notifyIcon1.Visible = false;
- }
- else
- {
- if (e.ClickedItem != this.exitWindow)
- return;
- this.button2_Click((object)null, (EventArgs)null);
- Environment.Exit(0);
- }
- }
-
- private void frmMain_SizeChanged(object sender, EventArgs e)
- {
- if (this.WindowState != FormWindowState.Minimized)
- return;
- this.ShowInTaskbar = false;
- this.notifyIcon1.Visible = true;
- }
-
- private void notifyIcon1_DoubleClick(object sender, EventArgs e)
- {
- if (this.WindowState != FormWindowState.Minimized)
- return;
- this.WindowState = FormWindowState.Normal;
- this.Activate();
- this.ShowInTaskbar = true;
- this.notifyIcon1.Visible = false;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing && this.components != null)
- this.components.Dispose();
- base.Dispose(disposing);
- }
-
- private void InitializeComponent()
- {
- this.components = (IContainer)new System.ComponentModel.Container();
- GridFormatRule gridFormatRule1 = new GridFormatRule();
- FormatConditionRuleExpression conditionRuleExpression1 = new FormatConditionRuleExpression();
- GridFormatRule gridFormatRule2 = new GridFormatRule();
- FormatConditionRuleExpression conditionRuleExpression2 = new FormatConditionRuleExpression();
- ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(MainForm));
- this.colZT = new GridColumn();
- this.splitContainerControl1 = new SplitContainerControl();
- this.txtNum = new TextEdit();
- this.labelControl3 = new LabelControl();
- this.button2 = new SimpleButton();
- this.button1 = new SimpleButton();
- this.btnRefashC = new SimpleButton();
- this.cmbSerialPortNum = new ImageComboBoxEdit();
- this.labelControl2 = new LabelControl();
- this.cmbBaudRate = new ImageComboBoxEdit();
- this.labelControl1 = new LabelControl();
- this.gridWOMQAB = new GridControl();
- this.viewWOMQAB = new GridView();
- this.colQAB001 = new GridColumn();
- this.colQAB002 = new GridColumn();
- this.colQAB003 = new GridColumn();
- this.colQAB005 = new GridColumn();
- this.colQAB006 = new GridColumn();
- this.colQAB007 = new GridColumn();
- this.colQAB009 = new GridColumn();
- this.colQAB010 = new GridColumn();
- this.colMIH004 = new GridColumn();
- this.colPAA002 = new GridColumn();
- this.colQAB015 = new GridColumn();
- this.colQAB025 = new GridColumn();
- this.colMCA022 = new GridColumn();
- this.colMCA023 = new GridColumn();
- this.notifyIcon1 = new NotifyIcon(this.components);
- this.contextMenuStrip1 = new ContextMenuStrip(this.components);
- this.showInTaskbar = new ToolStripMenuItem();
- this.exitWindow = new ToolStripMenuItem();
- this.timer1 = new System.Windows.Forms.Timer(this.components);
- this.splitContainerControl1.BeginInit();
- this.splitContainerControl1.SuspendLayout();
- this.txtNum.Properties.BeginInit();
- this.cmbSerialPortNum.Properties.BeginInit();
- this.cmbBaudRate.Properties.BeginInit();
- this.gridWOMQAB.BeginInit();
- this.viewWOMQAB.BeginInit();
- this.contextMenuStrip1.SuspendLayout();
- this.SuspendLayout();
- this.colZT.Caption = "鐘舵��";
- this.colZT.FieldName = "ZT";
- this.colZT.Name = "colZT";
- this.splitContainerControl1.Dock = DockStyle.Fill;
- this.splitContainerControl1.Horizontal = false;
- this.splitContainerControl1.Location = new Point(0, 0);
- this.splitContainerControl1.Margin = new Padding(4, 4, 4, 4);
- this.splitContainerControl1.Name = "splitContainerControl1";
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.txtNum);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.labelControl3);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.button2);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.button1);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.btnRefashC);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.cmbSerialPortNum);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.labelControl2);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.cmbBaudRate);
- this.splitContainerControl1.Panel1.Controls.Add((Control)this.labelControl1);
- this.splitContainerControl1.Panel1.Text = "Panel1";
- this.splitContainerControl1.Panel2.Controls.Add((Control)this.gridWOMQAB);
- this.splitContainerControl1.Panel2.Text = "Panel2";
- this.splitContainerControl1.Size = new Size(859, 391);
- this.splitContainerControl1.SplitterPosition = 139;
- this.splitContainerControl1.TabIndex = 0;
- this.splitContainerControl1.Text = "splitContainerControl1";
- this.txtNum.Location = new Point(588, 19);
- this.txtNum.Margin = new Padding(4, 4, 4, 4);
- this.txtNum.Name = "txtNum";
- this.txtNum.Properties.Appearance.Font = new Font("Tahoma", 24f, FontStyle.Regular, GraphicsUnit.Point, (byte)0);
- this.txtNum.Properties.Appearance.Options.UseFont = true;
- this.txtNum.Size = new Size(187, 54);
- this.txtNum.TabIndex = 8;
- this.labelControl3.Appearance.Font = new Font("Tahoma", 24f, FontStyle.Regular, GraphicsUnit.Point, (byte)0);
- this.labelControl3.Appearance.Options.UseFont = true;
- this.labelControl3.Location = new Point(468, 28);
- this.labelControl3.Margin = new Padding(4, 4, 4, 4);
- this.labelControl3.Name = "labelControl3";
- this.labelControl3.Size = new Size(120, 48 /*0x30*/);
- this.labelControl3.TabIndex = 7;
- this.labelControl3.Text = "閲嶉噺锛�";
- this.button2.Location = new Point(315, 48 /*0x30*/);
- this.button2.Margin = new Padding(4, 4, 4, 4);
- this.button2.Name = "button2";
- this.button2.Size = new Size(100, 29);
- this.button2.TabIndex = 6;
- this.button2.Text = "鍋滄";
- this.button2.Click += new EventHandler(this.button2_Click);
- this.button1.Location = new Point(315, 8);
- this.button1.Margin = new Padding(4, 4, 4, 4);
- this.button1.Name = "button1";
- this.button1.Size = new Size(100, 29);
- this.button1.TabIndex = 5;
- this.button1.Text = "纭畾";
- this.button1.Click += new EventHandler(this.button1_Click);
- this.btnRefashC.Location = new Point(213, 48 /*0x30*/);
- this.btnRefashC.Margin = new Padding(4, 4, 4, 4);
- this.btnRefashC.Name = "btnRefashC";
- this.btnRefashC.Size = new Size(33, 29);
- this.btnRefashC.TabIndex = 4;
- this.btnRefashC.Text = "R";
- this.cmbSerialPortNum.Location = new Point(72, 49);
- this.cmbSerialPortNum.Margin = new Padding(4, 4, 4, 4);
- this.cmbSerialPortNum.Name = "cmbSerialPortNum";
- this.cmbSerialPortNum.Properties.Buttons.AddRange(new EditorButton[1]
- {
- new EditorButton(ButtonPredefines.Combo)
- });
- this.cmbSerialPortNum.Size = new Size(133, 24);
- this.cmbSerialPortNum.TabIndex = 3;
- this.labelControl2.Location = new Point(16 /*0x10*/, 52);
- this.labelControl2.Margin = new Padding(4, 4, 4, 4);
- this.labelControl2.Name = "labelControl2";
- this.labelControl2.Size = new Size(45, 18);
- this.labelControl2.TabIndex = 2;
- this.labelControl2.Text = "涓插彛鍙�";
- this.cmbBaudRate.EditValue = (object)"9600";
- this.cmbBaudRate.Location = new Point(72, 11);
- this.cmbBaudRate.Margin = new Padding(4, 4, 4, 4);
- this.cmbBaudRate.Name = "cmbBaudRate";
- this.cmbBaudRate.Properties.Buttons.AddRange(new EditorButton[1]
- {
- new EditorButton(ButtonPredefines.Combo)
- });
- this.cmbBaudRate.Properties.Items.AddRange(new ImageComboBoxItem[5]
- {
- new ImageComboBoxItem("14400", (object) "14400", -1),
- new ImageComboBoxItem("9600", (object) "9600", -1),
- new ImageComboBoxItem("4800", (object) "4800", -1),
- new ImageComboBoxItem("2400", (object) "2400", -1),
- new ImageComboBoxItem("1200", (object) "1200", -1)
- });
- this.cmbBaudRate.Size = new Size(175, 24);
- this.cmbBaudRate.TabIndex = 1;
- this.labelControl1.Location = new Point(16 /*0x10*/, 15);
- this.labelControl1.Margin = new Padding(4, 4, 4, 4);
- this.labelControl1.Name = "labelControl1";
- this.labelControl1.Size = new Size(45, 18);
- this.labelControl1.TabIndex = 0;
- this.labelControl1.Text = "娉㈢壒鐜�";
- this.gridWOMQAB.Dock = DockStyle.Fill;
- this.gridWOMQAB.EmbeddedNavigator.Margin = new Padding(4, 4, 4, 4);
- this.gridWOMQAB.Location = new Point(0, 0);
- this.gridWOMQAB.MainView = (BaseView)this.viewWOMQAB;
- this.gridWOMQAB.Margin = new Padding(4, 4, 4, 4);
- this.gridWOMQAB.Name = "gridWOMQAB";
- this.gridWOMQAB.Size = new Size(859, 246);
- this.gridWOMQAB.TabIndex = 1;
- this.gridWOMQAB.ViewCollection.AddRange(new BaseView[1]
- {
- (BaseView) this.viewWOMQAB
- });
- this.viewWOMQAB.Columns.AddRange(new GridColumn[15]
- {
- this.colQAB001,
- this.colQAB002,
- this.colQAB003,
- this.colQAB005,
- this.colQAB006,
- this.colQAB007,
- this.colQAB009,
- this.colQAB010,
- this.colMIH004,
- this.colPAA002,
- this.colQAB015,
- this.colQAB025,
- this.colMCA022,
- this.colZT,
- this.colMCA023
- });
- gridFormatRule1.ApplyToRow = true;
- gridFormatRule1.Column = this.colZT;
- gridFormatRule1.Name = "ZTRule1";
- conditionRuleExpression1.Appearance.BackColor = System.Drawing.Color.Red;
- conditionRuleExpression1.Appearance.Options.UseBackColor = true;
- conditionRuleExpression1.Expression = "ZT='N'";
- gridFormatRule1.Rule = (FormatConditionRuleBase)conditionRuleExpression1;
- gridFormatRule2.ApplyToRow = true;
- gridFormatRule2.Column = this.colZT;
- gridFormatRule2.Name = "ZTRule2";
- conditionRuleExpression2.Appearance.BackColor = System.Drawing.Color.FromArgb(128 /*0x80*/, (int)byte.MaxValue, 128 /*0x80*/);
- conditionRuleExpression2.Appearance.Options.UseBackColor = true;
- conditionRuleExpression2.Expression = "ZT='Y'";
- gridFormatRule2.Rule = (FormatConditionRuleBase)conditionRuleExpression2;
- this.viewWOMQAB.FormatRules.Add(gridFormatRule1);
- this.viewWOMQAB.FormatRules.Add(gridFormatRule2);
- this.viewWOMQAB.GridControl = this.gridWOMQAB;
- this.viewWOMQAB.Name = "viewWOMQAB";
- this.viewWOMQAB.OptionsView.ColumnAutoWidth = false;
- this.viewWOMQAB.OptionsView.ShowGroupPanel = false;
- this.colQAB001.Caption = "ID";
- this.colQAB001.FieldName = "QAB001";
- this.colQAB001.Name = "colQAB001";
- this.colQAB002.Caption = "鏉$爜";
- this.colQAB002.FieldName = "QAB002";
- this.colQAB002.MinWidth = 150;
- this.colQAB002.Name = "colQAB002";
- this.colQAB002.Visible = true;
- this.colQAB002.VisibleIndex = 0;
- this.colQAB002.Width = 150;
- this.colQAB003.Caption = "宸ュ崟";
- this.colQAB003.FieldName = "QAB003";
- this.colQAB003.MinWidth = 100;
- this.colQAB003.Name = "colQAB003";
- this.colQAB003.Visible = true;
- this.colQAB003.VisibleIndex = 1;
- this.colQAB003.Width = 100;
- this.colQAB005.Caption = "鐗╂枡缂栫爜";
- this.colQAB005.FieldName = "QAB005";
- this.colQAB005.MinWidth = 100;
- this.colQAB005.Name = "colQAB005";
- this.colQAB005.Visible = true;
- this.colQAB005.VisibleIndex = 2;
- this.colQAB005.Width = 100;
- this.colQAB006.Caption = "鐗╂枡鍚嶇О";
- this.colQAB006.FieldName = "QAB006";
- this.colQAB006.Name = "colQAB006";
- this.colQAB006.Visible = true;
- this.colQAB006.VisibleIndex = 3;
- this.colQAB007.Caption = "鐗╂枡瑙勬牸";
- this.colQAB007.FieldName = "QAB007";
- this.colQAB007.MinWidth = 200;
- this.colQAB007.Name = "colQAB007";
- this.colQAB007.Visible = true;
- this.colQAB007.VisibleIndex = 4;
- this.colQAB007.Width = 200;
- this.colQAB009.Caption = "宸ュ簭缂栧彿";
- this.colQAB009.FieldName = "QAB009";
- this.colQAB009.Name = "colQAB009";
- this.colQAB009.Visible = true;
- this.colQAB009.VisibleIndex = 5;
- this.colQAB010.Caption = "宸ュ簭鍚嶇О";
- this.colQAB010.FieldName = "QAB010";
- this.colQAB010.Name = "colQAB010";
- this.colQAB010.Visible = true;
- this.colQAB010.VisibleIndex = 6;
- this.colMIH004.Caption = "绾垮埆";
- this.colMIH004.FieldName = "MIH004";
- this.colMIH004.Name = "colMIH004";
- this.colMIH004.Visible = true;
- this.colMIH004.VisibleIndex = 7;
- this.colPAA002.Caption = "浣滀笟浜哄憳";
- this.colPAA002.FieldName = "PAA002";
- this.colPAA002.Name = "colPAA002";
- this.colPAA002.Visible = true;
- this.colPAA002.VisibleIndex = 8;
- this.colQAB015.Caption = "浣滀笟鏃堕棿";
- this.colQAB015.FieldName = "QAB015";
- this.colQAB015.MinWidth = 150;
- this.colQAB015.Name = "colQAB015";
- this.colQAB015.Visible = true;
- this.colQAB015.VisibleIndex = 9;
- this.colQAB015.Width = 150;
- this.colQAB025.Caption = "瀹為檯閲嶉噺";
- this.colQAB025.FieldName = "QAB025";
- this.colQAB025.Name = "colQAB025";
- this.colQAB025.Visible = true;
- this.colQAB025.VisibleIndex = 10;
- this.colMCA022.Caption = "閲嶉噺涓嬮檺";
- this.colMCA022.FieldName = "MCA022";
- this.colMCA022.Name = "colMCA022";
- this.colMCA022.Visible = true;
- this.colMCA022.VisibleIndex = 11;
- this.colMCA023.Caption = "閲嶉噺涓婇檺";
- this.colMCA023.FieldName = "MCA023";
- this.colMCA023.Name = "colMCA023";
- this.colMCA023.Visible = true;
- this.colMCA023.VisibleIndex = 12;
- this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
- // this.notifyIcon1.Icon = (Icon)componentResourceManager.GetObject("notifyIcon1.Icon");
- this.notifyIcon1.Text = "鎶�鐮旀柊闃虫柊鎶�鐢靛瓙鏈夐檺鍏徃";
- this.notifyIcon1.Visible = true;
- this.contextMenuStrip1.ImageScalingSize = new Size(20, 20);
- this.contextMenuStrip1.Items.AddRange(new ToolStripItem[2]
- {
- (ToolStripItem) this.showInTaskbar,
- (ToolStripItem) this.exitWindow
- });
- this.contextMenuStrip1.Name = "contextMenuStrip1";
- this.contextMenuStrip1.Size = new Size(109, 52);
- this.showInTaskbar.Name = "showInTaskbar";
- this.showInTaskbar.Size = new Size(108, 24);
- this.showInTaskbar.Text = "鏄剧ず";
- this.exitWindow.Name = "exitWindow";
- this.exitWindow.Size = new Size(108, 24);
- this.exitWindow.Text = "閫�鍑�";
- this.timer1.Interval = 10000;
- this.AutoScaleDimensions = new SizeF(8f, 15f);
- this.AutoScaleMode = AutoScaleMode.Font;
- this.ClientSize = new Size(859, 391);
- this.Controls.Add((Control)this.splitContainerControl1);
- this.Margin = new Padding(4, 4, 4, 4);
- this.Name = nameof(MainForm);
- this.Text = "绉伴噸鍙栨暟";
- this.FormClosing += new FormClosingEventHandler(this.Form1_FormClosing);
- this.Load += new EventHandler(this.Form1_Load);
- this.splitContainerControl1.EndInit();
- this.splitContainerControl1.ResumeLayout(false);
- this.txtNum.Properties.EndInit();
- this.cmbSerialPortNum.Properties.EndInit();
- this.cmbBaudRate.Properties.EndInit();
- this.gridWOMQAB.EndInit();
- this.viewWOMQAB.EndInit();
- this.contextMenuStrip1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
-
- public delegate void HandleInterfaceUpdataDelegate(string text);
- }
-}
\ No newline at end of file
diff --git a/DevApp/Gs.DevApp/test/SQLHelper.cs b/DevApp/Gs.DevApp/test/SQLHelper.cs
deleted file mode 100644
index 5da9596..0000000
--- a/DevApp/Gs.DevApp/test/SQLHelper.cs
+++ /dev/null
@@ -1,429 +0,0 @@
-锘�// Decompiled with JetBrains decompiler
-// Type: ChengZhongModbus.SQLHelper
-// Assembly: ChengZhongModbusIQC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
-// MVID: 335383E6-9854-4BCE-8CD7-BF94F8E1A377
-// Assembly location: C:\Users\Administrator\Desktop\ChengZhongModbusIQC\ChengZhongModbusIQC.exe
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.Sql;
-using System.Data.SqlClient;
-
-
-
-public class SQLHelper : ICloneable, IDisposable
-{
- private SqlConnection _connection4Tran;
- private readonly string _connectionString;
- private SqlTransaction _transaction;
- private readonly Queue<SQLHelper.SqlTask> _transactionTaskList;
-
- public SQLHelper(string connectionString)
- {
- this._transactionTaskList = new Queue<SQLHelper.SqlTask>();
- this._connectionString = connectionString;
- }
-
- public SQLHelper(string server, string userID, string password, string database)
- {
- this._transactionTaskList = new Queue<SQLHelper.SqlTask>();
- if (database == string.Empty)
- this._connectionString = $"Data Source={server};User ID={userID};Password={password}";
- else
- this._connectionString = $"Data Source={server};User ID={userID};Password={password};Initial Catalog={database}";
- }
-
- public void BeginTransaction(IsolationLevel isolationLevel)
- {
- this._connection4Tran = this._transaction == null && this._connection4Tran == null ? new SqlConnection(this._connectionString) : throw new Exception("瑕佸紑濮嬩竴涓柊鐨勪簨鍔★紝璇峰厛瀹屾垚褰撳墠浜嬪姟!");
- this._connection4Tran.Open();
- this._transaction = this._connection4Tran.BeginTransaction(isolationLevel);
- this._transactionTaskList.Clear();
- }
-
- public void CancelTransaction()
- {
- if (this._transaction != null)
- this._transaction.Dispose();
- if (this._connection4Tran != null)
- this._connection4Tran.Close();
- if (this._connection4Tran != null)
- this._connection4Tran.Dispose();
- this._transaction = (SqlTransaction)null;
- this._connection4Tran = (SqlConnection)null;
- }
-
- public object Clone() => (object)new SQLHelper(this._connectionString);
-
- public void CommitTransaction()
- {
- try
- {
- if (this._transactionTaskList.Count > 0)
- {
- foreach (SQLHelper.SqlTask transactionTask in this._transactionTaskList)
- {
- using (SqlCommand sqlCommand = new SqlCommand(transactionTask.Text, this._connection4Tran))
- {
- sqlCommand.CommandType = transactionTask.CommandType;
- if (transactionTask.Parameters != null)
- {
- foreach (SqlParameter parameter in transactionTask.Parameters)
- sqlCommand.Parameters.Add(parameter);
- }
- sqlCommand.Transaction = this._transaction;
- sqlCommand.ExecuteNonQuery();
- }
- }
- }
- this._transaction.Commit();
- }
- catch (Exception ex)
- {
- this._transaction.Rollback();
- }
- finally
- {
- if (this._transaction != null)
- this._transaction.Dispose();
- if (this._connection4Tran != null)
- this._connection4Tran.Close();
- if (this._connection4Tran != null)
- this._connection4Tran.Dispose();
- this._transaction = (SqlTransaction)null;
- this._connection4Tran = (SqlConnection)null;
- }
- }
-
- public DataSet ExecuteDataSet(string sql)
- {
- return this.ExecuteDataSet(sql, CommandType.Text, (SqlParameter[])null);
- }
-
- public DataSet ExecuteDataSet(string sql, CommandType commandType)
- {
- return this.ExecuteDataSet(sql, commandType, (SqlParameter[])null);
- }
-
- public DataSet ExecuteDataSet(string sql, CommandType commandType, SqlParameter[] parameters)
- {
- DataSet dataSet = new DataSet(Guid.NewGuid().ToString());
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- using (SqlCommand selectCommand = new SqlCommand(sql, connection))
- {
- selectCommand.CommandType = commandType;
- if (parameters != null)
- {
- foreach (SqlParameter parameter in parameters)
- selectCommand.Parameters.Add(parameter);
- }
- new SqlDataAdapter(selectCommand).Fill(dataSet);
- }
- }
- return dataSet;
- }
-
- public DataTable ExecuteDataTable(string sql)
- {
- return this.ExecuteDataTable(sql, CommandType.Text, (SqlParameter[])null);
- }
-
- public DataTable ExecuteDataTable(string sql, CommandType commandType)
- {
- return this.ExecuteDataTable(sql, commandType, (SqlParameter[])null);
- }
-
- public DataTable ExecuteDataTable(string sql, CommandType commandType, SqlParameter[] parameters)
- {
- DataTable dataTable = new DataTable(Guid.NewGuid().ToString());
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- using (SqlCommand selectCommand = new SqlCommand(sql, connection))
- {
- selectCommand.CommandType = commandType;
- if (parameters != null)
- {
- foreach (SqlParameter parameter in parameters)
- selectCommand.Parameters.Add(parameter);
- }
- new SqlDataAdapter(selectCommand).Fill(dataTable);
- }
- }
- return dataTable;
- }
-
- public int ExecuteNonQuery(string sql)
- {
- return this.ExecuteNonQuery(sql, CommandType.Text, (SqlParameter[])null);
- }
-
- public int ExecuteNonQuery(string sql, CommandType commandType)
- {
- return this.ExecuteNonQuery(sql, commandType, (SqlParameter[])null);
- }
-
- public int ExecuteNonQuery(string sql, CommandType commandType, SqlParameter[] parameters)
- {
- return this.ExecuteNonQuery(sql, commandType, parameters, false);
- }
-
- public int ExecuteNonQuery(
- string sql,
- CommandType commandType,
- SqlParameter[] parameters,
- bool joinTransaction)
- {
- if (joinTransaction)
- {
- if (this._transaction == null || this._connection4Tran == null)
- throw new Exception("浜嬪姟鏈垵濮嬪寲锛�");
- this._transactionTaskList.Enqueue(new SQLHelper.SqlTask(sql, commandType, parameters));
- }
- int num;
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- SqlCommand sqlCommand;
- using (sqlCommand = new SqlCommand(sql, connection))
- {
- sqlCommand.CommandType = commandType;
- if (parameters != null)
- {
- foreach (SqlParameter parameter in parameters)
- sqlCommand.Parameters.Add(parameter);
- }
- connection.Open();
- num = sqlCommand.ExecuteNonQuery();
- }
- }
- return num;
- }
-
- public SqlDataReader ExecuteReader(string sql)
- {
- return this.ExecuteReader(sql, CommandType.Text, (SqlParameter[])null);
- }
-
- public SqlDataReader ExecuteReader(string sql, CommandType commandType)
- {
- return this.ExecuteReader(sql, commandType, (SqlParameter[])null);
- }
-
- public SqlDataReader ExecuteReader(
- string sql,
- CommandType commandType,
- SqlParameter[] parameters)
- {
- SqlConnection connection = new SqlConnection(this._connectionString);
- SqlCommand sqlCommand1 = new SqlCommand(sql, connection);
- sqlCommand1.CommandType = commandType;
- SqlCommand sqlCommand2 = sqlCommand1;
- if (parameters != null)
- {
- foreach (SqlParameter parameter in parameters)
- sqlCommand2.Parameters.Add(parameter);
- }
- connection.Open();
- return sqlCommand2.ExecuteReader(CommandBehavior.CloseConnection);
- }
-
- public object ExecuteScalar(string sql)
- {
- return this.ExecuteScalar(sql, CommandType.Text, (SqlParameter[])null);
- }
-
- public object ExecuteScalar(string sql, CommandType commandType)
- {
- return this.ExecuteScalar(sql, commandType, (SqlParameter[])null);
- }
-
- public object ExecuteScalar(string sql, CommandType commandType, SqlParameter[] parameters)
- {
- object obj;
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- using (SqlCommand sqlCommand = new SqlCommand(sql, connection))
- {
- sqlCommand.CommandType = commandType;
- if (parameters != null)
- {
- foreach (SqlParameter parameter in parameters)
- sqlCommand.Parameters.Add(parameter);
- }
- connection.Open();
- obj = sqlCommand.ExecuteScalar();
- }
- }
- return obj;
- }
-
- public DataTable GetDatabases()
- {
- using (SqlConnection sqlConnection = new SqlConnection(this._connectionString))
- {
- sqlConnection.Open();
- return sqlConnection.GetSchema("Databases");
- }
- }
-
- public static ArrayList GetServerList()
- {
- ArrayList serverList = new ArrayList();
- foreach (DataRow row in (InternalDataCollectionBase)SqlDataSourceEnumerator.Instance.GetDataSources().Rows)
- serverList.Add((object)row[0].ToString());
- return serverList;
- }
-
- public DataTable GetTables()
- {
- using (SqlConnection sqlConnection = new SqlConnection(this._connectionString))
- {
- sqlConnection.Open();
- return sqlConnection.GetSchema("Tables");
- }
- }
-
- public bool SaveDataToDB(DataSet dataSet)
- {
- try
- {
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- foreach (DataTable table in (InternalDataCollectionBase)dataSet.Tables)
- {
- using (SqlCommand selectCommand = new SqlCommand($"SELECT * FROM {table.TableName} WHERE 1<1", connection))
- {
- SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
- SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(adapter);
- adapter.UpdateBatchSize = 100;
- if (table.GetChanges() != null)
- adapter.Update(table.GetChanges());
- }
- }
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- return true;
- }
-
- public bool SaveDataToDB(DataTable dataTable)
- {
- try
- {
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- using (SqlCommand selectCommand = new SqlCommand("select top 0 * from " + dataTable.TableName, connection))
- {
- SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
- SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(adapter);
- adapter.UpdateBatchSize = 100;
- if (dataTable.GetChanges() != null)
- adapter.Update(dataTable);
- }
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- return true;
- }
-
- public bool SaveDataToDB(DataSet oldDataSet, DataSet newDataSet)
- {
- oldDataSet.Merge(newDataSet, false);
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- connection.Open();
- SqlTransaction transaction = connection.BeginTransaction();
- try
- {
- foreach (DataTable table in (InternalDataCollectionBase)oldDataSet.Tables)
- {
- using (SqlCommand selectCommand = new SqlCommand($"SELECT * FROM {table.TableName} WHERE 1<1", connection, transaction))
- {
- SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
- SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(adapter);
- adapter.UpdateBatchSize = 500;
- adapter.Update(table);
- }
- }
- transaction.Commit();
- return true;
- }
- catch (Exception ex)
- {
- transaction.Rollback();
- throw;
- }
- finally
- {
- transaction?.Dispose();
- }
- }
- }
-
- public bool SaveDataToDB(DataTable oldDataTable, DataTable newDataTable)
- {
- oldDataTable.Merge(newDataTable, false);
- bool db;
- using (SqlConnection connection = new SqlConnection(this._connectionString))
- {
- using (SqlCommand selectCommand = new SqlCommand($"SELECT * FROM {oldDataTable.TableName} WHERE 1<1", connection))
- {
- SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
- SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(adapter);
- adapter.UpdateBatchSize = 100;
- adapter.Update(oldDataTable);
- db = true;
- }
- }
- return db;
- }
-
- public bool TestConnection()
- {
- bool flag;
- try
- {
- using (SqlConnection sqlConnection = new SqlConnection(this._connectionString))
- {
- sqlConnection.Open();
- sqlConnection.Close();
- flag = true;
- }
- }
- catch (Exception ex)
- {
- flag = false;
- }
- return flag;
- }
-
- public void Dispose()
- {
- this._connection4Tran = (SqlConnection)null;
- this._transaction = (SqlTransaction)null;
- }
-
- private class SqlTask
- {
- public string Text { get; private set; }
-
- public CommandType CommandType { get; private set; }
-
- public SqlParameter[] Parameters { get; private set; }
-
- public SqlTask(string text, CommandType commandType, SqlParameter[] paras)
- {
- this.Text = text;
- this.CommandType = commandType;
- this.Parameters = paras;
- }
- }
-}
--
Gitblit v1.9.3