Bläddra i källkod

ADD History& keys

张泳健 7 år sedan
förälder
incheckning
62d8c3e6c9

Binär
GWSocketClient.rar Visa fil


+ 28 - 10
GWSocketClient/Form1.Designer.cs Visa fil

@@ -58,6 +58,7 @@
58 58
             this.IPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
59 59
             this.AddrToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
60 60
             this.CCIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
61
+            this.SendToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
61 62
             this.心跳HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
62 63
             this.StripMenuItemLoSucHb = new System.Windows.Forms.ToolStripMenuItem();
63 64
             this.ToolStripMenuItemHbStart = new System.Windows.Forms.ToolStripMenuItem();
@@ -78,7 +79,8 @@
78 79
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
79 80
             this.rightMenuClearInfo = new System.Windows.Forms.ToolStripMenuItem();
80 81
             this.timerHeartBeat = new System.Windows.Forms.Timer(this.components);
81
-            this.SendToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
82
+            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
83
+            this.ClearAllAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
82 84
             this.groupBox1.SuspendLayout();
83 85
             this.menuStrip1.SuspendLayout();
84 86
             this.statusStrip1.SuspendLayout();
@@ -368,10 +370,12 @@
368 370
             this.IPToolStripMenuItem,
369 371
             this.AddrToolStripMenuItem,
370 372
             this.CCIDToolStripMenuItem,
371
-            this.SendToolStripMenuItem});
373
+            this.SendToolStripMenuItem,
374
+            this.toolStripSeparator4,
375
+            this.ClearAllAllToolStripMenuItem});
372 376
             this.toolStripMenuItem1.Name = "toolStripMenuItem1";
373
-            this.toolStripMenuItem1.Size = new System.Drawing.Size(44, 21);
374
-            this.toolStripMenuItem1.Text = "记录";
377
+            this.toolStripMenuItem1.Size = new System.Drawing.Size(60, 21);
378
+            this.toolStripMenuItem1.Text = "记录(&C)";
375 379
             // 
376 380
             // IPToolStripMenuItem
377 381
             // 
@@ -397,6 +401,14 @@
397 401
             this.CCIDToolStripMenuItem.Text = "CCID记录";
398 402
             this.CCIDToolStripMenuItem.Click += new System.EventHandler(this.CCIDToolStripMenuItem_Click);
399 403
             // 
404
+            // SendToolStripMenuItem
405
+            // 
406
+            this.SendToolStripMenuItem.Name = "SendToolStripMenuItem";
407
+            this.SendToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D4)));
408
+            this.SendToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
409
+            this.SendToolStripMenuItem.Text = "发送记录";
410
+            this.SendToolStripMenuItem.Click += new System.EventHandler(this.SendToolStripMenuItem_Click);
411
+            // 
400 412
             // 心跳HToolStripMenuItem
401 413
             // 
402 414
             this.心跳HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -564,13 +576,17 @@
564 576
             this.timerHeartBeat.Interval = 5000;
565 577
             this.timerHeartBeat.Tick += new System.EventHandler(this.timerHeartBeat_Tick);
566 578
             // 
567
-            // SendToolStripMenuItem
579
+            // toolStripSeparator4
568 580
             // 
569
-            this.SendToolStripMenuItem.Name = "SendToolStripMenuItem";
570
-            this.SendToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.D4)));
571
-            this.SendToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
572
-            this.SendToolStripMenuItem.Text = "发送记录";
573
-            this.SendToolStripMenuItem.Click += new System.EventHandler(this.SendToolStripMenuItem_Click);
581
+            this.toolStripSeparator4.Name = "toolStripSeparator4";
582
+            this.toolStripSeparator4.Size = new System.Drawing.Size(184, 6);
583
+            // 
584
+            // ClearAllAllToolStripMenuItem
585
+            // 
586
+            this.ClearAllAllToolStripMenuItem.Name = "ClearAllAllToolStripMenuItem";
587
+            this.ClearAllAllToolStripMenuItem.Size = new System.Drawing.Size(187, 22);
588
+            this.ClearAllAllToolStripMenuItem.Text = "清空所有记录";
589
+            this.ClearAllAllToolStripMenuItem.Click += new System.EventHandler(this.ClearAllAllToolStripMenuItem_Click);
574 590
             // 
575 591
             // Form1
576 592
             // 
@@ -653,6 +669,8 @@
653 669
         private System.Windows.Forms.ToolStripMenuItem AddrToolStripMenuItem;
654 670
         private System.Windows.Forms.ToolStripMenuItem CCIDToolStripMenuItem;
655 671
         private System.Windows.Forms.ToolStripMenuItem SendToolStripMenuItem;
672
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
673
+        private System.Windows.Forms.ToolStripMenuItem ClearAllAllToolStripMenuItem;
656 674
     }
657 675
 }
658 676
 

+ 42 - 21
GWSocketClient/Form1.cs Visa fil

@@ -143,13 +143,21 @@ namespace GWSocketClient
143 143
             string trim = tfTmpSendData.Text.Trim();
144 144
             trim = trim.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("-", "");
145 145
 
146
-            if (!trim.Equals(""))
146
+            try
147 147
             {
148
-                byte[] ts = HexUtil.hexToBytes(trim);
148
+                if (!trim.Equals(""))
149
+                {
150
+                    byte[] ts = HexUtil.hexToBytes(trim);
149 151
 
150
-                addToListboxItem(string.Format("发送到服务端:[{0}]", trim));
152
+                    AccessDbLoader.getInstance().addToHistory(AccessDbLoader.SEND_HIS, trim);
153
+                    addToListboxItem(string.Format("发送到服务端:[{0}]", trim));
151 154
 
152
-                sockeTcpClients.SendData(ts);
155
+                    sockeTcpClients.SendData(ts);
156
+                }
157
+            }
158
+            catch (Exception exception)
159
+            {
160
+                MessageBox.Show(exception.Message);
153 161
             }
154 162
         }
155 163
 
@@ -198,7 +206,10 @@ namespace GWSocketClient
198 206
                 tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
199 207
                 label4.Visible = !label4.Visible;
200 208
             }
201
-
209
+            else
210
+            {
211
+                AccessDbLoader.getInstance().addToHistory(AccessDbLoader.SEND_HIS, "1234567890");
212
+            }
202 213
         }
203 214
 
204 215
         private void toolStripMenuItemHBtime_Click(object sender, EventArgs e)
@@ -209,7 +220,6 @@ namespace GWSocketClient
209 220
                 timerHeartBeat.Interval = int.Parse(topmost) * 1000;
210 221
                 //5秒
211 222
                 toolStripStatusLabelHbShow.Text = "心跳时间: " + topmost + "秒";
212
-
213 223
             };
214 224
             id.ShowDialog();
215 225
         }
@@ -221,7 +231,7 @@ namespace GWSocketClient
221 231
 
222 232
         private void labelHis_Click(object sender, EventArgs e)
223 233
         {
224
-            Label lab= sender as Label;
234
+            Label lab = sender as Label;
225 235
             HistoryDialog hd = new HistoryDialog(lab.Name);
226 236
             hd.HistoryHandler += Hd_HistoryHandler;
227 237
             hd.ShowDialog();
@@ -241,6 +251,10 @@ namespace GWSocketClient
241 251
             {
242 252
                 tbIpaddress.Text = result;
243 253
             }
254
+            else if ("labelSendHIS".Equals(type))
255
+            {
256
+                tfTmpSendData.Text = result;
257
+            }
244 258
         }
245 259
 
246 260
         private void IPToolStripMenuItem_Click(object sender, EventArgs e)
@@ -263,6 +277,7 @@ namespace GWSocketClient
263 277
             hd.HistoryHandler += Hd_HistoryHandler;
264 278
             hd.ShowDialog();
265 279
         }
280
+
266 281
         private void SendToolStripMenuItem_Click(object sender, EventArgs e)
267 282
         {
268 283
             HistoryDialog hd = new HistoryDialog("labelSendHIS");
@@ -396,12 +411,14 @@ namespace GWSocketClient
396 411
 
397 412
                 if (ToolStripMenuItemLogHb.Checked && hbLen.Equals("0000"))
398 413
                 {
399
-                    addToListboxItem(string.Format("收到服务端{0}发来心跳funCode={2}:[{1}]", sks.Ip, reqData,reqData.Substring(18,2)));
414
+                    addToListboxItem(string.Format("收到服务端{0}发来心跳funCode={2}:[{1}]", sks.Ip, reqData,
415
+                        reqData.Substring(18, 2)));
400 416
                 }
401 417
             }
402 418
             else
403 419
             {
404
-                addToListboxItem(string.Format("收到服务端{0}发来消息,funCode={2}:[{1}]", sks.Ip, reqData,reqData.Substring(18,2)));
420
+                addToListboxItem(string.Format("收到服务端{0}发来消息,funCode={2}:[{1}]", sks.Ip, reqData,
421
+                    reqData.Substring(18, 2)));
405 422
             }
406 423
 
407 424
             if (!(funcode == 16 || funcode == 32))
@@ -508,13 +525,12 @@ namespace GWSocketClient
508 525
             //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
509 526
             string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
510 527
             loginCmd += tbEquipmentAddress.Text.Trim() + "82";
511
-                        
512
-            
528
+
529
+
513 530
             loginCmd += Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
514 531
             loginCmd += tbCCID.Text.Trim();
515
-            
516 532
 
517
-            
533
+
518 534
             loginCmd = Utils.calcCrcCode(loginCmd);
519 535
             //发送登录命令
520 536
             byte[] ts = HexUtil.hexToBytes(loginCmd);
@@ -621,7 +637,7 @@ namespace GWSocketClient
621 637
                         new SolidBrush(e.ForeColor),
622 638
                         e.Bounds);
623 639
                 }
624
-               
640
+
625 641
                 e.DrawFocusRectangle();
626 642
             }
627 643
         }
@@ -678,6 +694,11 @@ namespace GWSocketClient
678 694
                     //如果勾选了登录成功并心跳
679 695
                     timerHeartBeat.Enabled = true;
680 696
                 }
697
+
698
+                //ADD To History
699
+                AccessDbLoader.getInstance().addToHistory(AccessDbLoader.IP_HIS, tbIpaddress.Text.Trim());
700
+                AccessDbLoader.getInstance().addToHistory(AccessDbLoader.CCID_HIS, tbCCID.Text.Trim());
701
+                AccessDbLoader.getInstance().addToHistory(AccessDbLoader.ADDR_HIS, tbEquipmentAddress.Text.Trim());
681 702
             }
682 703
             else
683 704
             {
@@ -690,14 +711,14 @@ namespace GWSocketClient
690 711
             }
691 712
         }
692 713
 
693
-
694
-
695
-
696
-
697
-
698
-
699 714
         #endregion
700 715
 
701
-       
716
+        private void ClearAllAllToolStripMenuItem_Click(object sender, EventArgs e)
717
+        {
718
+            AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.IP_HIS);
719
+            AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.ADDR_HIS);
720
+            AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.SEND_HIS);
721
+            AccessDbLoader.getInstance().deleteAllData(AccessDbLoader.CCID_HIS);
722
+        }
702 723
     }
703 724
 }

+ 1 - 1
GWSocketClient/GWSocketClient.csproj Visa fil

@@ -5,7 +5,7 @@
5 5
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6 6
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7 7
     <ProjectGuid>{1E7C256A-9CA5-4937-A5DD-7F281A2EBB21}</ProjectGuid>
8
-    <OutputType>Exe</OutputType>
8
+    <OutputType>WinExe</OutputType>
9 9
     <RootNamespace>GWSocketClient</RootNamespace>
10 10
     <AssemblyName>GWSocketClient</AssemblyName>
11 11
     <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>

+ 49 - 48
GWSocketClient/HistoryDialog.Designer.cs Visa fil

@@ -30,16 +30,16 @@
30 30
         {
31 31
             this.components = new System.ComponentModel.Container();
32 32
             this.listBoxHistory = new System.Windows.Forms.ListBox();
33
-            this.buttonRandom = new System.Windows.Forms.Button();
34
-            this.buttonCancle = new System.Windows.Forms.Button();
35
-            this.textBoxSourceCCID = new System.Windows.Forms.TextBox();
36
-            this.buttonTransalteCCID = new System.Windows.Forms.Button();
37
-            this.labelCCIDLEN = new System.Windows.Forms.Label();
38 33
             this.rightCTXHIS = new System.Windows.Forms.ContextMenuStrip(this.components);
39 34
             this.DelteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
40 35
             this.AllClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
41 36
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
42 37
             this.CopyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
38
+            this.buttonRandom = new System.Windows.Forms.Button();
39
+            this.buttonCancle = new System.Windows.Forms.Button();
40
+            this.textBoxSourceCCID = new System.Windows.Forms.TextBox();
41
+            this.buttonTransalteCCID = new System.Windows.Forms.Button();
42
+            this.labelCCIDLEN = new System.Windows.Forms.Label();
43 43
             this.rightCTXHIS.SuspendLayout();
44 44
             this.SuspendLayout();
45 45
             // 
@@ -47,16 +47,53 @@
47 47
             // 
48 48
             this.listBoxHistory.ContextMenuStrip = this.rightCTXHIS;
49 49
             this.listBoxHistory.FormattingEnabled = true;
50
+            this.listBoxHistory.HorizontalScrollbar = true;
50 51
             this.listBoxHistory.ItemHeight = 20;
51 52
             this.listBoxHistory.Location = new System.Drawing.Point(12, 7);
52 53
             this.listBoxHistory.Name = "listBoxHistory";
53
-            this.listBoxHistory.Size = new System.Drawing.Size(422, 364);
54
+            this.listBoxHistory.Size = new System.Drawing.Size(633, 364);
54 55
             this.listBoxHistory.TabIndex = 0;
55 56
             this.listBoxHistory.DoubleClick += new System.EventHandler(this.listBoxHistory_DoubleClick);
56 57
             // 
58
+            // rightCTXHIS
59
+            // 
60
+            this.rightCTXHIS.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
61
+            this.DelteToolStripMenuItem,
62
+            this.AllClearToolStripMenuItem,
63
+            this.toolStripSeparator1,
64
+            this.CopyToolStripMenuItem});
65
+            this.rightCTXHIS.Name = "rightCTXHIS";
66
+            this.rightCTXHIS.Size = new System.Drawing.Size(166, 76);
67
+            // 
68
+            // DelteToolStripMenuItem
69
+            // 
70
+            this.DelteToolStripMenuItem.Name = "DelteToolStripMenuItem";
71
+            this.DelteToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
72
+            this.DelteToolStripMenuItem.Text = "删除选中记录(&D)";
73
+            this.DelteToolStripMenuItem.Click += new System.EventHandler(this.DelteToolStripMenuItem_Click);
74
+            // 
75
+            // AllClearToolStripMenuItem
76
+            // 
77
+            this.AllClearToolStripMenuItem.Name = "AllClearToolStripMenuItem";
78
+            this.AllClearToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
79
+            this.AllClearToolStripMenuItem.Text = "清空所有记录(&A)";
80
+            this.AllClearToolStripMenuItem.Click += new System.EventHandler(this.AllClearToolStripMenuItem_Click);
81
+            // 
82
+            // toolStripSeparator1
83
+            // 
84
+            this.toolStripSeparator1.Name = "toolStripSeparator1";
85
+            this.toolStripSeparator1.Size = new System.Drawing.Size(162, 6);
86
+            // 
87
+            // CopyToolStripMenuItem
88
+            // 
89
+            this.CopyToolStripMenuItem.Name = "CopyToolStripMenuItem";
90
+            this.CopyToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
91
+            this.CopyToolStripMenuItem.Text = "复制选中记录(&C)";
92
+            this.CopyToolStripMenuItem.Click += new System.EventHandler(this.CopyToolStripMenuItem_Click);
93
+            // 
57 94
             // buttonRandom
58 95
             // 
59
-            this.buttonRandom.Location = new System.Drawing.Point(190, 433);
96
+            this.buttonRandom.Location = new System.Drawing.Point(401, 433);
60 97
             this.buttonRandom.Name = "buttonRandom";
61 98
             this.buttonRandom.Size = new System.Drawing.Size(119, 39);
62 99
             this.buttonRandom.TabIndex = 1;
@@ -68,7 +105,7 @@
68 105
             // buttonCancle
69 106
             // 
70 107
             this.buttonCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;
71
-            this.buttonCancle.Location = new System.Drawing.Point(315, 433);
108
+            this.buttonCancle.Location = new System.Drawing.Point(526, 433);
72 109
             this.buttonCancle.Name = "buttonCancle";
73 110
             this.buttonCancle.Size = new System.Drawing.Size(119, 39);
74 111
             this.buttonCancle.TabIndex = 2;
@@ -79,7 +116,7 @@
79 116
             // 
80 117
             this.textBoxSourceCCID.Location = new System.Drawing.Point(12, 401);
81 118
             this.textBoxSourceCCID.Name = "textBoxSourceCCID";
82
-            this.textBoxSourceCCID.Size = new System.Drawing.Size(376, 26);
119
+            this.textBoxSourceCCID.Size = new System.Drawing.Size(610, 26);
83 120
             this.textBoxSourceCCID.TabIndex = 3;
84 121
             this.textBoxSourceCCID.Visible = false;
85 122
             this.textBoxSourceCCID.TextChanged += new System.EventHandler(this.textBoxSourceCCID_TextChanged);
@@ -87,7 +124,7 @@
87 124
             // buttonTransalteCCID
88 125
             // 
89 126
             this.buttonTransalteCCID.DialogResult = System.Windows.Forms.DialogResult.Cancel;
90
-            this.buttonTransalteCCID.Location = new System.Drawing.Point(65, 433);
127
+            this.buttonTransalteCCID.Location = new System.Drawing.Point(276, 433);
91 128
             this.buttonTransalteCCID.Name = "buttonTransalteCCID";
92 129
             this.buttonTransalteCCID.Size = new System.Drawing.Size(119, 39);
93 130
             this.buttonTransalteCCID.TabIndex = 4;
@@ -99,55 +136,19 @@
99 136
             // labelCCIDLEN
100 137
             // 
101 138
             this.labelCCIDLEN.AutoSize = true;
102
-            this.labelCCIDLEN.Location = new System.Drawing.Point(394, 404);
139
+            this.labelCCIDLEN.Location = new System.Drawing.Point(628, 404);
103 140
             this.labelCCIDLEN.Name = "labelCCIDLEN";
104 141
             this.labelCCIDLEN.Size = new System.Drawing.Size(17, 20);
105 142
             this.labelCCIDLEN.TabIndex = 5;
106 143
             this.labelCCIDLEN.Text = "0";
107 144
             this.labelCCIDLEN.Visible = false;
108 145
             // 
109
-            // rightCTXHIS
110
-            // 
111
-            this.rightCTXHIS.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
112
-            this.DelteToolStripMenuItem,
113
-            this.AllClearToolStripMenuItem,
114
-            this.toolStripSeparator1,
115
-            this.CopyToolStripMenuItem});
116
-            this.rightCTXHIS.Name = "rightCTXHIS";
117
-            this.rightCTXHIS.Size = new System.Drawing.Size(166, 76);
118
-            // 
119
-            // DelteToolStripMenuItem
120
-            // 
121
-            this.DelteToolStripMenuItem.Name = "DelteToolStripMenuItem";
122
-            this.DelteToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
123
-            this.DelteToolStripMenuItem.Text = "删除选中记录(&D)";
124
-            this.DelteToolStripMenuItem.Click += new System.EventHandler(this.DelteToolStripMenuItem_Click);
125
-            // 
126
-            // AllClearToolStripMenuItem
127
-            // 
128
-            this.AllClearToolStripMenuItem.Name = "AllClearToolStripMenuItem";
129
-            this.AllClearToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
130
-            this.AllClearToolStripMenuItem.Text = "清空所有记录(&A)";
131
-            this.AllClearToolStripMenuItem.Click += new System.EventHandler(this.AllClearToolStripMenuItem_Click);
132
-            // 
133
-            // toolStripSeparator1
134
-            // 
135
-            this.toolStripSeparator1.Name = "toolStripSeparator1";
136
-            this.toolStripSeparator1.Size = new System.Drawing.Size(162, 6);
137
-            // 
138
-            // CopyToolStripMenuItem
139
-            // 
140
-            this.CopyToolStripMenuItem.Name = "CopyToolStripMenuItem";
141
-            this.CopyToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
142
-            this.CopyToolStripMenuItem.Text = "复制选中记录(&C)";
143
-            this.CopyToolStripMenuItem.Click += new System.EventHandler(this.CopyToolStripMenuItem_Click);
144
-            // 
145 146
             // HistoryDialog
146 147
             // 
147 148
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
148 149
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
149 150
             this.CancelButton = this.buttonCancle;
150
-            this.ClientSize = new System.Drawing.Size(446, 484);
151
+            this.ClientSize = new System.Drawing.Size(657, 484);
151 152
             this.Controls.Add(this.labelCCIDLEN);
152 153
             this.Controls.Add(this.buttonTransalteCCID);
153 154
             this.Controls.Add(this.textBoxSourceCCID);

+ 12 - 23
GWSocketClient/HistoryDialog.cs Visa fil

@@ -13,11 +13,10 @@ using System.Windows.Forms;
13 13
 
14 14
 namespace GWSocketClient
15 15
 {
16
-    public delegate void OnHistoryResult(string type,string result);
16
+    public delegate void OnHistoryResult(string type, string result);
17 17
 
18 18
     public partial class HistoryDialog : Form
19 19
     {
20
-        
21 20
         public event OnHistoryResult HistoryHandler;
22 21
         private string type;
23 22
         private string tableName;
@@ -30,11 +29,8 @@ namespace GWSocketClient
30 29
         }
31 30
 
32 31
 
33
-    
34
-
35 32
         private void HistoryDialog_Load(object sender, EventArgs e)
36 33
         {
37
-
38 34
             if ("labelCCIDHIS".Equals(type))
39 35
             {
40 36
                 textBoxSourceCCID.Visible = true;
@@ -70,7 +66,6 @@ namespace GWSocketClient
70 66
 
71 67
         private void buttonRandom_Click(object sender, EventArgs e)
72 68
         {
73
-
74 69
             if ("labelCCIDHIS".Equals(type))
75 70
             {
76 71
                 HistoryHandler(type, randomCCID());
@@ -80,7 +75,7 @@ namespace GWSocketClient
80 75
             {
81 76
                 string add = "00000";
82 77
                 Random rd = new Random();
83
-                for(int i = 0; i < 7; i++)
78
+                for (int i = 0; i < 7; i++)
84 79
                 {
85 80
                     add += Utils.tenToHex(rd.Next(0, 16));
86 81
                 }
@@ -92,9 +87,9 @@ namespace GWSocketClient
92 87
         private void textBoxSourceCCID_TextChanged(object sender, EventArgs e)
93 88
         {
94 89
             string tt = textBoxSourceCCID.Text.Trim();
95
-            if(tt.Length>0)
90
+            if (tt.Length > 0)
96 91
             {
97
-                labelCCIDLEN.Text = tt.Length+"";
92
+                labelCCIDLEN.Text = tt.Length + "";
98 93
             }
99 94
             else
100 95
             {
@@ -112,11 +107,11 @@ namespace GWSocketClient
112 107
                 {
113 108
                     result = Utils.transateCCID(tt);
114 109
                 }
115
-                catch(Exception ex)
110
+                catch (Exception ex)
116 111
                 {
117 112
                     MessageBox.Show(ex.Message);
118 113
                     this.DialogResult = DialogResult.None;
119
-                    return; 
114
+                    return;
120 115
                 }
121 116
             }
122 117
             else
@@ -124,15 +119,14 @@ namespace GWSocketClient
124 119
                 result = randomCCID();
125 120
             }
126 121
             HistoryHandler(this.type, result);
127
-
128 122
         }
129 123
 
130 124
         private string randomCCID()
131 125
         {
132 126
             string res = "";
133 127
             Random rd = new Random();
134
-          
135
-            for (int i=0; i < 20; i++)
128
+
129
+            for (int i = 0; i < 20; i++)
136 130
             {
137 131
                 res += rd.Next(30, 40);
138 132
             }
@@ -158,7 +152,7 @@ namespace GWSocketClient
158 152
             if (index >= 0 && index < listBoxHistory.Items.Count)
159 153
             {
160 154
                 HisBean hb = listBoxHistory.SelectedItem as HisBean;
161
-                AccessDbLoader.getInstance().deleteByID(tableName,hb.ID);
155
+                AccessDbLoader.getInstance().deleteByID(tableName, hb.ID);
162 156
                 his.Clear();
163 157
                 his = AccessDbLoader.getInstance().getInputHistory(AccessDbLoader.CCID_HIS);
164 158
                 listBoxHistory.Items.Clear();
@@ -168,13 +162,8 @@ namespace GWSocketClient
168 162
 
169 163
         private void AllClearToolStripMenuItem_Click(object sender, EventArgs e)
170 164
         {
171
-            int index = listBoxHistory.SelectedIndex;
172
-            if (index >= 0 && index < listBoxHistory.Items.Count)
173
-            {
174
-                AccessDbLoader.getInstance().deleteAllData(tableName);
175
-                listBoxHistory.Items.Clear();
176
-            }
177
-
165
+            AccessDbLoader.getInstance().deleteAllData(tableName);
166
+            listBoxHistory.Items.Clear();
178 167
         }
179 168
 
180 169
         private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
@@ -187,4 +176,4 @@ namespace GWSocketClient
187 176
             }
188 177
         }
189 178
     }
190
-}
179
+}

Binär
GWSocketClient/bin/Debug/dbfile/ID_INFO.accdb Visa fil


Binär
GWSocketClient/bin/Release/dbfile/ID_INFO.accdb Visa fil


+ 70 - 11
GWSocketClient/db/AccessDbLoader.cs Visa fil

@@ -269,7 +269,7 @@ namespace GWSocketClient.db
269 269
 
270 270
         public int deleteAllData(string tableName = "fw")
271 271
         {
272
-            string sql = "delete from "+ tableName;
272
+            string sql = "delete from " + tableName;
273 273
             Console.WriteLine(sql);
274 274
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
275 275
             return inst.ExecuteNonQuery();
@@ -289,16 +289,26 @@ namespace GWSocketClient.db
289 289
         public int getHistoryCount(string tableName)
290 290
         {
291 291
             string sql = "select COUNT(*),MIN(ID) from " + tableName;
292
+
292 293
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
293 294
             int count = 0;
294 295
             int minId = 0;
295 296
             using (OleDbDataReader reader = inst.ExecuteReader())
296 297
             {
297
-                reader.Read();
298
-                count = reader.GetInt32(0);
299
-                minId = reader.GetInt32(1);
298
+                if (reader != null)
299
+                {
300
+                    reader.Read();
301
+                    try
302
+                    {
303
+                        count = reader.GetInt32(0);
304
+                        minId = reader.GetInt32(1);
305
+                    }
306
+                    catch (Exception e)
307
+                    {
308
+                        // 当数据库中没有记录的时候,MIN ID 就会出错.
309
+                    }
310
+                }
300 311
             }
301
-
302 312
             if (count > 30)
303 313
             {
304 314
                 sql = "delete from " + tableName + "  where ID=" + minId;
@@ -309,10 +319,57 @@ namespace GWSocketClient.db
309 319
         }
310 320
 
311 321
 
322
+        public int checkHistoryExits(string tableName, string his)
323
+        {
324
+            his = his.Trim().ToUpper();
325
+            string sql = "select COUNT(*) from " + tableName + " ";
326
+
327
+            switch (tableName)
328
+            {
329
+                case IP_HIS:
330
+                    sql += "where ip ='" + his + "'";
331
+                    break;
332
+                case SEND_HIS:
333
+                    sql += "where s_data ='" + his + "'";
334
+                    break;
335
+                case CCID_HIS:
336
+                    sql += "where CCID ='" + his + "'";
337
+                    break;
338
+                case ADDR_HIS:
339
+                    sql += "where addr ='" + his + "'";
340
+                    break;
341
+                default:
342
+                    break;
343
+            }
344
+
345
+            Console.WriteLine("检查是否存在SQL=" + sql);
346
+
347
+            int count;
348
+            using (OleDbCommand inst = new OleDbCommand(sql, objConnection))
349
+            {
350
+                count = 0;
351
+                using (OleDbDataReader reader = inst.ExecuteReader())
352
+                {
353
+                    if (reader != null)
354
+                    {
355
+                        reader.Read();
356
+                        count = reader.GetInt32(0);
357
+                    }
358
+                }
359
+            }
360
+            return count;
361
+        }
362
+
312 363
         public int addToHistory(string tableName, string his)
313 364
         {
314
-            int rowCount = getHistoryCount(tableName);          
365
+            his = his.ToUpper();
366
+            Console.WriteLine(tableName + "; " + his);
367
+
368
+            int exits = checkHistoryExits(tableName, his);
369
+            if (exits != 0)
370
+                return -1;
315 371
 
372
+            int rowCount = getHistoryCount(tableName);
316 373
             OleDbCommand inst = null;
317 374
 
318 375
             string sql = "INSERT INTO " + tableName + "(";
@@ -331,16 +388,20 @@ namespace GWSocketClient.db
331 388
                 sql += "CCID) VALUES('" + his + "')";
332 389
                 Console.WriteLine(sql);
333 390
             }
391
+            else if (tableName.Equals(ADDR_HIS))
392
+            {
393
+                sql += "addr) VALUES('" + his + "')";
394
+                Console.WriteLine(sql);
395
+            }
334 396
             inst = new OleDbCommand(sql, objConnection);
335 397
             return inst.ExecuteNonQuery();
336 398
         }
337 399
 
338 400
 
339
-
340 401
         public int deleteByID(string tablename, int id)
341 402
         {
342
-            string  sql = "delete from " + tablename + "  where ID=" + id;
343
-            OleDbCommand  inst = new OleDbCommand(sql, objConnection);
403
+            string sql = "delete from " + tablename + "  where ID=" + id;
404
+            OleDbCommand inst = new OleDbCommand(sql, objConnection);
344 405
             return inst.ExecuteNonQuery();
345 406
         }
346 407
 
@@ -363,7 +424,5 @@ namespace GWSocketClient.db
363 424
             }
364 425
             return hsiList;
365 426
         }
366
-
367
-
368 427
     }
369 428
 }

+ 4 - 0
GWSocketClientTests/GWSocketClientTests.csproj Visa fil

@@ -39,6 +39,9 @@
39 39
     <WarningLevel>4</WarningLevel>
40 40
   </PropertyGroup>
41 41
   <ItemGroup>
42
+    <Reference Include="dotMemory.Unit, Version=103.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
43
+      <HintPath>..\packages\JetBrains.dotMemoryUnit.2.3.20160517.113140\lib\dotMemory.Unit.dll</HintPath>
44
+    </Reference>
42 45
     <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
43 46
       <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
44 47
     </Reference>
@@ -56,6 +59,7 @@
56 59
     <Otherwise />
57 60
   </Choose>
58 61
   <ItemGroup>
62
+    <Compile Include="db\AccessDbLoaderTests.cs" />
59 63
     <Compile Include="Properties\AssemblyInfo.cs" />
60 64
     <Compile Include="util\UtilsTests.cs" />
61 65
   </ItemGroup>

+ 24 - 0
GWSocketClientTests/db/AccessDbLoaderTests.cs Visa fil

@@ -0,0 +1,24 @@
1
+using Microsoft.VisualStudio.TestTools.UnitTesting;
2
+using GWSocketClient.db;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Linq;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+
9
+namespace GWSocketClient.db.Tests
10
+{
11
+    [TestClass()]
12
+    public class AccessDbLoaderTests
13
+    {
14
+        [TestMethod()]
15
+        public void getHistoryCountTest()
16
+        {
17
+
18
+//            int count = AccessDbLoader.getInstance().getHistoryCount(AccessDbLoader.ADDR_HIS);
19
+//            Console.WriteLine(count);
20
+
21
+            Console.WriteLine("abc");
22
+        }
23
+    }
24
+}

+ 1 - 0
GWSocketClientTests/packages.config Visa fil

@@ -1,5 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <packages>
3
+  <package id="JetBrains.dotMemoryUnit" version="2.3.20160517.113140" targetFramework="net452" />
3 4
   <package id="MSTest.TestAdapter" version="1.1.11" targetFramework="net452" />
4 5
   <package id="MSTest.TestFramework" version="1.1.11" targetFramework="net452" />
5 6
 </packages>