From 91d3b71e4ff6884ae4c064929b0071ed98363ff9 Mon Sep 17 00:00:00 2001 From: cdk <2441919651@qq.com> Date: 星期四, 21 八月 2025 08:29:38 +0800 Subject: [PATCH] Merge branch 'master' of http://git.gs-mes.com:8080/r/~tjx/GsMesClient --- DevApp/Gs.DevApp/test/LoggerHelper.cs | 52 + DevApp/Gs.DevApp/test/MainForm.Designer.cs | 38 + DevApp/Gs.DevApp/test/MainForm.cs | 709 ++++++++++++++++++++++ DevApp/Gs.DevApp/XtraForm2.cs | 274 ++++++++ DevApp/Gs.DevApp/UserControl/UcDictionarySelect.Designer.cs | 24 DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.Designer.cs | 142 +-- DevApp/Gs.DevApp/Gs.DevApp.csproj | 11 DevApp/Gs.DevApp/App.config | 13 DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs | 31 DevApp/Gs.DevApp/XtraForm2.Designer.cs | 76 ++ DevApp/Gs.DevApp/packages.config | 1 DevApp/Gs.DevApp/DevFrm/QC/Jyxm.Designer.cs | 1 DevApp/Gs.DevApp/DevFrm/QC/Jyxm.cs | 4 DevApp/Gs.DevApp/Program.cs | 2 DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.Designer.cs | 2 DevApp/Gs.DevApp/test/SQLHelper.cs | 429 +++++++++++++ 16 files changed, 1,680 insertions(+), 129 deletions(-) diff --git a/DevApp/Gs.DevApp/App.config b/DevApp/Gs.DevApp/App.config index 40932b6..642d77a 100644 --- a/DevApp/Gs.DevApp/App.config +++ b/DevApp/Gs.DevApp/App.config @@ -34,6 +34,12 @@ </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/" />--> @@ -47,6 +53,13 @@ <add key="ToastSeconds" value="5" /><!--鎻愮ず妗嗘椂闂�--> <add key="AsyncSeconds" value="2" /><!--姘存瓒呮椂鏃堕棿--> <add key="IsWater" value="0" /><!--鏄惁瑕佹按妫�鍙婂伐浣嶇爜--> + + + <!--<add key="ExecutionTime" value="5" />--> + <add key="TimingMailInterval" value="10000" /> + <add key="thisText" value="[鏂扮粶绉伴噸鏈嶅姟]" /> + <!--<add key="notifyText" value="5" />--> + <add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> <userSettings> <Gs.DevApp.Properties.Settings> diff --git a/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.Designer.cs b/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.Designer.cs index af362ec..687f828 100644 --- a/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.Designer.cs +++ b/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.Designer.cs @@ -623,6 +623,7 @@ this.txt_itemId.Name = "txt_itemId"; this.txt_itemId.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] { new DevExpress.XtraEditors.Controls.EditorButton()}); + this.txt_itemId.Properties.ReadOnly = true; this.txt_itemId.Size = new System.Drawing.Size(200, 24); this.txt_itemId.StyleController = this.layoutMx1; this.txt_itemId.TabIndex = 391; diff --git a/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.cs b/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.cs index 57b9eda..027e071 100644 --- a/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.cs +++ b/DevApp/Gs.DevApp/DevFrm/QC/Jyxm.cs @@ -62,7 +62,6 @@ { dfValue = 0; gvMx1.Columns["ypsl"].Visible = false; - } //濡傛灉鏄痠pqc宸℃锛屾樉绀哄伐浣� if (strType != QcSeason.ipqc宸℃.ToString()) @@ -268,6 +267,7 @@ gridViews.Add(gvMx1); UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true, gridViews); UtilityHelper.SetDefaultTable(gcMx1, gvMx1); + this.txt_itemId.ReadOnly = true; } /// <summary> @@ -616,7 +616,7 @@ #region 浠ヤ笅涓虹绉嶄笅鎷� private void _setIno() { - txt_itemId.Click += (s, e) => + txt_itemId.ButtonClick += (s, e) => { var frm = new JyxmShow(this.strType); frm.UpdateParent += (ss, ee) => diff --git a/DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.Designer.cs b/DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.Designer.cs index a69c00a..749f878 100644 --- a/DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.Designer.cs +++ b/DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.Designer.cs @@ -400,7 +400,7 @@ 0, 0}); this.txt_noLength.Minimum = new decimal(new int[] { - 4, + 3, 0, 0, 0}); diff --git a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.Designer.cs b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.Designer.cs index 8a46553..b886fce 100644 --- a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.Designer.cs +++ b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.Designer.cs @@ -29,20 +29,19 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - DevExpress.XtraLayout.ColumnDefinition columnDefinition33 = new DevExpress.XtraLayout.ColumnDefinition(); - DevExpress.XtraLayout.ColumnDefinition columnDefinition34 = new DevExpress.XtraLayout.ColumnDefinition(); - DevExpress.XtraLayout.ColumnDefinition columnDefinition35 = new DevExpress.XtraLayout.ColumnDefinition(); - DevExpress.XtraLayout.ColumnDefinition columnDefinition36 = new DevExpress.XtraLayout.ColumnDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition49 = new DevExpress.XtraLayout.RowDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition50 = new DevExpress.XtraLayout.RowDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition51 = new DevExpress.XtraLayout.RowDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition52 = new DevExpress.XtraLayout.RowDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition53 = new DevExpress.XtraLayout.RowDefinition(); - DevExpress.XtraLayout.RowDefinition rowDefinition54 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.ColumnDefinition columnDefinition1 = new DevExpress.XtraLayout.ColumnDefinition(); + DevExpress.XtraLayout.ColumnDefinition columnDefinition2 = new DevExpress.XtraLayout.ColumnDefinition(); + DevExpress.XtraLayout.ColumnDefinition columnDefinition3 = new DevExpress.XtraLayout.ColumnDefinition(); + DevExpress.XtraLayout.ColumnDefinition columnDefinition4 = new DevExpress.XtraLayout.ColumnDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition1 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition2 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition3 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition4 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition5 = new DevExpress.XtraLayout.RowDefinition(); + DevExpress.XtraLayout.RowDefinition rowDefinition6 = new DevExpress.XtraLayout.RowDefinition(); this.splitMx1 = new DevExpress.XtraEditors.SplitContainerControl(); this.splitTop1 = new DevExpress.XtraEditors.SplitContainerControl(); this.layoutMx1 = new DevExpress.XtraLayout.LayoutControl(); - this.lbCollectGuid = new DevExpress.XtraEditors.LabelControl(); this.txt_gdbh = new DevExpress.XtraEditors.TextEdit(); this.txt_gx = new DevExpress.XtraEditors.TextEdit(); this.txt_collectBy = new DevExpress.XtraEditors.TextEdit(); @@ -60,7 +59,6 @@ this.btnGood = new DevExpress.XtraEditors.SimpleButton(); this.btnBad = new DevExpress.XtraEditors.SimpleButton(); this.txt_dianJianPath = new DevExpress.XtraEditors.TextEdit(); - this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem(); this.Root = new DevExpress.XtraLayout.LayoutControlGroup(); this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem(); this.layoutControlItem2 = new DevExpress.XtraLayout.LayoutControlItem(); @@ -78,7 +76,6 @@ this.layoutControlItem13 = new DevExpress.XtraLayout.LayoutControlItem(); this.layoutControlItem10 = new DevExpress.XtraLayout.LayoutControlItem(); this.layoutControlItem11 = new DevExpress.XtraLayout.LayoutControlItem(); - this.layDianJian = new DevExpress.XtraLayout.LayoutControlItem(); this.simpleButton7 = new DevExpress.XtraEditors.SimpleButton(); this.simpleButton6 = new DevExpress.XtraEditors.SimpleButton(); this.simpleButton5 = new DevExpress.XtraEditors.SimpleButton(); @@ -134,6 +131,7 @@ this.gridColumn23 = new DevExpress.XtraGrid.Columns.GridColumn(); this.gridColumn25 = new DevExpress.XtraGrid.Columns.GridColumn(); this.alertControl1 = new DevExpress.XtraBars.Alerter.AlertControl(this.components); + this.layDianJian = new DevExpress.XtraLayout.LayoutControlItem(); ((System.ComponentModel.ISupportInitialize)(this.splitMx1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitMx1.Panel1)).BeginInit(); this.splitMx1.Panel1.SuspendLayout(); @@ -163,7 +161,6 @@ ((System.ComponentModel.ISupportInitialize)(this.txt_yjDate.Properties)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.txt_sjDate.Properties)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.txt_dianJianPath.Properties)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.Root)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).BeginInit(); @@ -181,7 +178,6 @@ ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem13)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem10)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem11)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.layDianJian)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.prog1.Properties)).BeginInit(); this.panel3.SuspendLayout(); this.panel2.SuspendLayout(); @@ -195,6 +191,7 @@ this.tabMxPage2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.gcMx2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.gvMx2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.layDianJian)).BeginInit(); this.SuspendLayout(); // // splitMx1 @@ -250,7 +247,6 @@ // // layoutMx1 // - this.layoutMx1.Controls.Add(this.lbCollectGuid); this.layoutMx1.Controls.Add(this.txt_gdbh); this.layoutMx1.Controls.Add(this.txt_gx); this.layoutMx1.Controls.Add(this.txt_collectBy); @@ -269,8 +265,6 @@ this.layoutMx1.Controls.Add(this.btnBad); this.layoutMx1.Controls.Add(this.txt_dianJianPath); this.layoutMx1.Dock = System.Windows.Forms.DockStyle.Fill; - this.layoutMx1.HiddenItems.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] { - this.layoutControlItem6}); this.layoutMx1.Location = new System.Drawing.Point(0, 0); this.layoutMx1.Name = "layoutMx1"; this.layoutMx1.OptionsCustomizationForm.DesignTimeCustomizationFormPositionAndSize = new System.Drawing.Rectangle(981, 0, 812, 500); @@ -278,15 +272,6 @@ this.layoutMx1.Size = new System.Drawing.Size(828, 229); this.layoutMx1.TabIndex = 0; this.layoutMx1.Text = "layoutControl1"; - // - // lbCollectGuid - // - this.lbCollectGuid.Location = new System.Drawing.Point(214, 177); - this.lbCollectGuid.Name = "lbCollectGuid"; - this.lbCollectGuid.Size = new System.Drawing.Size(79, 18); - this.lbCollectGuid.StyleController = this.layoutMx1; - this.lbCollectGuid.TabIndex = 22; - this.lbCollectGuid.Text = "lbCollectGuid"; // // txt_gdbh // @@ -451,18 +436,6 @@ this.txt_dianJianPath.StyleController = this.layoutMx1; this.txt_dianJianPath.TabIndex = 21; // - // layoutControlItem6 - // - this.layoutControlItem6.Control = this.lbCollectGuid; - this.layoutControlItem6.Location = new System.Drawing.Point(202, 165); - this.layoutControlItem6.Name = "layoutControlItem6"; - this.layoutControlItem6.OptionsTableLayoutItem.ColumnIndex = 1; - this.layoutControlItem6.OptionsTableLayoutItem.RowIndex = 5; - this.layoutControlItem6.Size = new System.Drawing.Size(202, 36); - this.layoutControlItem6.Text = "閲囬泦琛実uid"; - this.layoutControlItem6.TextSize = new System.Drawing.Size(0, 0); - this.layoutControlItem6.TextVisible = false; - // // Root // this.Root.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True; @@ -487,38 +460,38 @@ this.layDianJian}); this.Root.LayoutMode = DevExpress.XtraLayout.Utils.LayoutMode.Table; this.Root.Name = "Root"; - columnDefinition33.SizeType = System.Windows.Forms.SizeType.Percent; - columnDefinition33.Width = 100D; - columnDefinition34.SizeType = System.Windows.Forms.SizeType.Percent; - columnDefinition34.Width = 100D; - columnDefinition35.SizeType = System.Windows.Forms.SizeType.Percent; - columnDefinition35.Width = 100D; - columnDefinition36.SizeType = System.Windows.Forms.SizeType.Percent; - columnDefinition36.Width = 100D; + columnDefinition1.SizeType = System.Windows.Forms.SizeType.Percent; + columnDefinition1.Width = 100D; + columnDefinition2.SizeType = System.Windows.Forms.SizeType.Percent; + columnDefinition2.Width = 100D; + columnDefinition3.SizeType = System.Windows.Forms.SizeType.Percent; + columnDefinition3.Width = 100D; + columnDefinition4.SizeType = System.Windows.Forms.SizeType.Percent; + columnDefinition4.Width = 100D; this.Root.OptionsTableLayoutGroup.ColumnDefinitions.AddRange(new DevExpress.XtraLayout.ColumnDefinition[] { - columnDefinition33, - columnDefinition34, - columnDefinition35, - columnDefinition36}); - rowDefinition49.Height = 100D; - rowDefinition49.SizeType = System.Windows.Forms.SizeType.Percent; - rowDefinition50.Height = 100D; - rowDefinition50.SizeType = System.Windows.Forms.SizeType.Percent; - rowDefinition51.Height = 100D; - rowDefinition51.SizeType = System.Windows.Forms.SizeType.Percent; - rowDefinition52.Height = 100D; - rowDefinition52.SizeType = System.Windows.Forms.SizeType.Percent; - rowDefinition53.Height = 100D; - rowDefinition53.SizeType = System.Windows.Forms.SizeType.Percent; - rowDefinition54.Height = 100D; - rowDefinition54.SizeType = System.Windows.Forms.SizeType.Percent; + columnDefinition1, + columnDefinition2, + columnDefinition3, + columnDefinition4}); + rowDefinition1.Height = 100D; + rowDefinition1.SizeType = System.Windows.Forms.SizeType.Percent; + rowDefinition2.Height = 100D; + rowDefinition2.SizeType = System.Windows.Forms.SizeType.Percent; + rowDefinition3.Height = 100D; + rowDefinition3.SizeType = System.Windows.Forms.SizeType.Percent; + rowDefinition4.Height = 100D; + rowDefinition4.SizeType = System.Windows.Forms.SizeType.Percent; + rowDefinition5.Height = 100D; + rowDefinition5.SizeType = System.Windows.Forms.SizeType.Percent; + rowDefinition6.Height = 100D; + rowDefinition6.SizeType = System.Windows.Forms.SizeType.Percent; this.Root.OptionsTableLayoutGroup.RowDefinitions.AddRange(new DevExpress.XtraLayout.RowDefinition[] { - rowDefinition49, - rowDefinition50, - rowDefinition51, - rowDefinition52, - rowDefinition53, - rowDefinition54}); + rowDefinition1, + rowDefinition2, + rowDefinition3, + rowDefinition4, + rowDefinition5, + rowDefinition6}); this.Root.Size = new System.Drawing.Size(828, 229); this.Root.TextVisible = false; // @@ -703,17 +676,6 @@ this.layoutControlItem11.Size = new System.Drawing.Size(404, 34); this.layoutControlItem11.Text = "浜у搧瑙勬牸"; this.layoutControlItem11.TextSize = new System.Drawing.Size(87, 18); - // - // layDianJian - // - this.layDianJian.Control = this.txt_dianJianPath; - this.layDianJian.Location = new System.Drawing.Point(202, 174); - this.layDianJian.Name = "layDianJian"; - this.layDianJian.OptionsTableLayoutItem.ColumnIndex = 1; - this.layDianJian.OptionsTableLayoutItem.RowIndex = 5; - this.layDianJian.Size = new System.Drawing.Size(202, 35); - this.layDianJian.Text = "鐢垫璺緞"; - this.layDianJian.TextSize = new System.Drawing.Size(87, 18); // // simpleButton7 // @@ -1100,7 +1062,7 @@ // this.tabMxPage2.Controls.Add(this.gcMx2); this.tabMxPage2.Name = "tabMxPage2"; - this.tabMxPage2.Size = new System.Drawing.Size(1365, 354); + this.tabMxPage2.Size = new System.Drawing.Size(1365, 346); this.tabMxPage2.Text = "涓嶈壇鍝佹槑缁�"; // // gcMx2 @@ -1109,7 +1071,7 @@ this.gcMx2.Location = new System.Drawing.Point(0, 0); this.gcMx2.MainView = this.gvMx2; this.gcMx2.Name = "gcMx2"; - this.gcMx2.Size = new System.Drawing.Size(1365, 354); + this.gcMx2.Size = new System.Drawing.Size(1365, 346); this.gcMx2.TabIndex = 1; this.gcMx2.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { this.gvMx2}); @@ -1303,6 +1265,17 @@ this.gridColumn25.VisibleIndex = 12; this.gridColumn25.Width = 94; // + // layDianJian + // + this.layDianJian.Control = this.txt_dianJianPath; + this.layDianJian.Location = new System.Drawing.Point(202, 174); + this.layDianJian.Name = "layDianJian"; + this.layDianJian.OptionsTableLayoutItem.ColumnIndex = 1; + this.layDianJian.OptionsTableLayoutItem.RowIndex = 5; + this.layDianJian.Size = new System.Drawing.Size(202, 35); + this.layDianJian.Text = "鐢垫璺緞"; + this.layDianJian.TextSize = new System.Drawing.Size(87, 18); + // // Frm_Work01 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F); @@ -1344,7 +1317,6 @@ ((System.ComponentModel.ISupportInitialize)(this.txt_yjDate.Properties)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.txt_sjDate.Properties)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.txt_dianJianPath.Properties)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.Root)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).EndInit(); @@ -1362,7 +1334,6 @@ ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem13)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem10)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem11)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.layDianJian)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.prog1.Properties)).EndInit(); this.panel3.ResumeLayout(false); this.panel3.PerformLayout(); @@ -1380,6 +1351,7 @@ this.tabMxPage2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.gcMx2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.gvMx2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.layDianJian)).EndInit(); this.ResumeLayout(false); } @@ -1478,8 +1450,6 @@ private DevExpress.XtraLayout.LayoutControlItem layoutControlItem13; private DevExpress.XtraLayout.LayoutControlItem layoutControlItem10; private DevExpress.XtraLayout.LayoutControlItem layoutControlItem11; - private DevExpress.XtraEditors.LabelControl lbCollectGuid; - private DevExpress.XtraLayout.LayoutControlItem layoutControlItem6; private DevExpress.XtraLayout.LayoutControlItem layDianJian; } } \ No newline at end of file diff --git a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs index 9b74e45..f53004d 100644 --- a/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs +++ b/DevApp/Gs.DevApp/DevFrm/Work/Frm_Work01.cs @@ -107,14 +107,24 @@ }; btnBad.Click += (s, e) => { - string _collectGuid = lbCollectGuid.Text.Trim(); + string _collectGuid =""; + string _collCode = ""; + var dr = gvMx1.GetFocusedDataRow(); + if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString())) + { + } + else + { + _collectGuid = dr["guid"].ToString(); + _collCode = dr["barCode"].ToString(); + } if (_collectGuid.Length < 30) { Toast vm = new Toast(-1, "~璇峰厛閫夋嫨杩芥函鐮亊"); vm.Show(); return; } - string _msg = "浣犲噯澶囧皢銆�" + txt_gdbh.Text + "銆戙��" + txt_currentBarCode.Text.Trim() + "銆戝彉鏇翠负涓嶈壇"; + string _msg = "浣犲噯澶囧皢銆�" + _collCode + "銆戝彉鏇翠负涓嶈壇"; UcDictionarySelect frm = new UcDictionarySelect("宸ュ簭涓嶈壇鎻忚堪", " a.s_type='宸ュ簭涓嶈壇鎻忚堪' and pid<>'00000000-0000-0000-0000-000000000000'", _msg); frm.UpdateParent += (ss, ee) => { @@ -133,22 +143,14 @@ vm.Show(); } else - addModel(badTag, _txt, lbCollectGuid.Text.Trim()); + addModel(badTag, _txt, _collectGuid); }; frm.ShowDialog(); + this.ActiveControl = this.txt_barCode; + txt_barCode.Focus(); }; this.ActiveControl = this.txt_barCode; txt_barCode.Focus(); - gvMx1.FocusedRowChanged += (s, e) => - { - if (e.FocusedRowHandle >= 0) - { - DataRow row = gvMx1.GetDataRow(e.FocusedRowHandle); - txt_gdbh.Text = row["gdbh"].ToString(); - txt_currentBarCode.Text = row["barCode"].ToString(); - lbCollectGuid.Text = row["guid"].ToString(); - } - }; } /// <summary> @@ -347,7 +349,8 @@ string _msg = _rtn.rtnMsg; if (!string.IsNullOrEmpty(_msg)) { - Toast vm = new Toast((goodTag == "鈭�" ? 1 : -1), _msg); + // Toast vm = new Toast((goodTag == "鈭�" ? 1 : -1), _msg); 2025-08-20 淇敼鎻愮ず澶栬 + Toast vm = new Toast(1, _rtn.rtnMsg); vm.Show(); } } diff --git a/DevApp/Gs.DevApp/Gs.DevApp.csproj b/DevApp/Gs.DevApp/Gs.DevApp.csproj index 40f1898..80fdde8 100644 --- a/DevApp/Gs.DevApp/Gs.DevApp.csproj +++ b/DevApp/Gs.DevApp/Gs.DevApp.csproj @@ -127,6 +127,9 @@ <Reference Include="NModbus, Version=3.0.81.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\packages\NModbus.3.0.81\lib\net46\NModbus.dll</HintPath> </Reference> + <Reference Include="NModbus.Serial, Version=3.0.81.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\NModbus.Serial.3.0.81\lib\net46\NModbus.Serial.dll</HintPath> + </Reference> <Reference Include="PresentationCore" /> <Reference Include="PresentationFramework" /> <Reference Include="System" /> @@ -1134,11 +1137,19 @@ <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> </Compile> diff --git a/DevApp/Gs.DevApp/Program.cs b/DevApp/Gs.DevApp/Program.cs index 801da22..b807218 100644 --- a/DevApp/Gs.DevApp/Program.cs +++ b/DevApp/Gs.DevApp/Program.cs @@ -41,7 +41,7 @@ /// </summary> private static void _startLogin() { - //Application.Run(new XtraForm1()); + //Application.Run(new Gs.DevApp.test.MainForm()); //return; CefSettings settings = new CefSettings(); settings.Locale = "zh-CN"; diff --git a/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.Designer.cs b/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.Designer.cs index 2037b0d..96ad9b0 100644 --- a/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.Designer.cs +++ b/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.Designer.cs @@ -32,8 +32,8 @@ this.tlcMenuName = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.tlcActions = new DevExpress.XtraTreeList.Columns.TreeListColumn(); this.panel1 = new System.Windows.Forms.Panel(); - this.btnIn = new DevExpress.XtraEditors.SimpleButton(); this.lbMsg = new DevExpress.XtraEditors.LabelControl(); + this.btnIn = new DevExpress.XtraEditors.SimpleButton(); ((System.ComponentModel.ISupportInitialize)(this.tlMenu)).BeginInit(); this.panel1.SuspendLayout(); this.SuspendLayout(); @@ -88,6 +88,19 @@ this.panel1.Size = new System.Drawing.Size(776, 56); this.panel1.TabIndex = 6; // + // lbMsg + // + this.lbMsg.Appearance.Font = new System.Drawing.Font("Tahoma", 13F); + this.lbMsg.Appearance.ForeColor = System.Drawing.Color.Red; + this.lbMsg.Appearance.Options.UseFont = true; + this.lbMsg.Appearance.Options.UseForeColor = true; + this.lbMsg.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbMsg.Location = new System.Drawing.Point(0, 0); + this.lbMsg.Name = "lbMsg"; + this.lbMsg.Size = new System.Drawing.Size(127, 27); + this.lbMsg.TabIndex = 6; + this.lbMsg.Text = "labelControl1"; + // // btnIn // this.btnIn.Appearance.BackColor = DevExpress.LookAndFeel.DXSkinColors.FillColors.Primary; @@ -99,15 +112,6 @@ this.btnIn.Size = new System.Drawing.Size(94, 56); this.btnIn.TabIndex = 5; this.btnIn.Text = "纭畾閫夋嫨"; - // - // lbMsg - // - this.lbMsg.Dock = System.Windows.Forms.DockStyle.Fill; - this.lbMsg.Location = new System.Drawing.Point(0, 0); - this.lbMsg.Name = "lbMsg"; - this.lbMsg.Size = new System.Drawing.Size(81, 18); - this.lbMsg.TabIndex = 6; - this.lbMsg.Text = "labelControl1"; // // UcDictionarySelect // diff --git a/DevApp/Gs.DevApp/XtraForm2.Designer.cs b/DevApp/Gs.DevApp/XtraForm2.Designer.cs index 7ab1c9d..8b2bf36 100644 --- a/DevApp/Gs.DevApp/XtraForm2.Designer.cs +++ b/DevApp/Gs.DevApp/XtraForm2.Designer.cs @@ -28,34 +28,84 @@ /// </summary> private void InitializeComponent() { - this.labelControl1 = new DevExpress.XtraEditors.LabelControl(); + 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(); // - // labelControl1 + // cmbSerialPortNum // - this.labelControl1.Appearance.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.labelControl1.Appearance.Options.UseFont = true; - this.labelControl1.Location = new System.Drawing.Point(144, 46); - this.labelControl1.Name = "labelControl1"; - this.labelControl1.Size = new System.Drawing.Size(102, 18); - this.labelControl1.TabIndex = 0; - this.labelControl1.Text = "labelControl1"; + 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.labelControl1); + 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 = "XtraForm2"; + this.Text = "娴嬭瘯绉伴噸"; + ((System.ComponentModel.ISupportInitialize)(this.cmbSerialPortNum.Properties)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.cmbBaudRate.Properties)).EndInit(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private DevExpress.XtraEditors.LabelControl labelControl1; + 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 index bee5936..6772666 100644 --- a/DevApp/Gs.DevApp/XtraForm2.cs +++ b/DevApp/Gs.DevApp/XtraForm2.cs @@ -1,21 +1,291 @@ 锘縰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.Text; -using System.Threading.Tasks; 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/packages.config b/DevApp/Gs.DevApp/packages.config index 7df0e9d..e7a5280 100644 --- a/DevApp/Gs.DevApp/packages.config +++ b/DevApp/Gs.DevApp/packages.config @@ -9,6 +9,7 @@ <package id="Microsoft.Web.WebView2" version="1.0.2592.51" targetFramework="net48" /> <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" /> <package id="NModbus" version="3.0.81" targetFramework="net48" /> + <package id="NModbus.Serial" version="3.0.81" targetFramework="net48" /> <package id="System.Buffers" version="4.5.1" targetFramework="net48" /> <package id="System.Configuration.ConfigurationManager" version="8.0.0" targetFramework="net48" /> <package id="System.Diagnostics.DiagnosticSource" version="6.0.1" targetFramework="net48" /> diff --git a/DevApp/Gs.DevApp/test/LoggerHelper.cs b/DevApp/Gs.DevApp/test/LoggerHelper.cs new file mode 100644 index 0000000..dc9453a --- /dev/null +++ b/DevApp/Gs.DevApp/test/LoggerHelper.cs @@ -0,0 +1,52 @@ +锘�// 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 new file mode 100644 index 0000000..2528d09 --- /dev/null +++ b/DevApp/Gs.DevApp/test/MainForm.Designer.cs @@ -0,0 +1,38 @@ +锘縩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 new file mode 100644 index 0000000..f94c41d --- /dev/null +++ b/DevApp/Gs.DevApp/test/MainForm.cs @@ -0,0 +1,709 @@ +锘縰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 new file mode 100644 index 0000000..5da9596 --- /dev/null +++ b/DevApp/Gs.DevApp/test/SQLHelper.cs @@ -0,0 +1,429 @@ +锘�// 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