Browse Source

ADD History& keys

张泳健 7 years ago
parent
commit
62d8c3e6c9

BIN
GWSocketClient.rar View File


+ 28 - 10
GWSocketClient/Form1.Designer.cs View File

58
             this.IPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
58
             this.IPToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
59
             this.AddrToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
59
             this.AddrToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
60
             this.CCIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
60
             this.CCIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
61
+            this.SendToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
61
             this.心跳HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
62
             this.心跳HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
62
             this.StripMenuItemLoSucHb = new System.Windows.Forms.ToolStripMenuItem();
63
             this.StripMenuItemLoSucHb = new System.Windows.Forms.ToolStripMenuItem();
63
             this.ToolStripMenuItemHbStart = new System.Windows.Forms.ToolStripMenuItem();
64
             this.ToolStripMenuItemHbStart = new System.Windows.Forms.ToolStripMenuItem();
78
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
79
             this.rightMenuCopyCmd = new System.Windows.Forms.ToolStripMenuItem();
79
             this.rightMenuClearInfo = new System.Windows.Forms.ToolStripMenuItem();
80
             this.rightMenuClearInfo = new System.Windows.Forms.ToolStripMenuItem();
80
             this.timerHeartBeat = new System.Windows.Forms.Timer(this.components);
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
             this.groupBox1.SuspendLayout();
84
             this.groupBox1.SuspendLayout();
83
             this.menuStrip1.SuspendLayout();
85
             this.menuStrip1.SuspendLayout();
84
             this.statusStrip1.SuspendLayout();
86
             this.statusStrip1.SuspendLayout();
368
             this.IPToolStripMenuItem,
370
             this.IPToolStripMenuItem,
369
             this.AddrToolStripMenuItem,
371
             this.AddrToolStripMenuItem,
370
             this.CCIDToolStripMenuItem,
372
             this.CCIDToolStripMenuItem,
371
-            this.SendToolStripMenuItem});
373
+            this.SendToolStripMenuItem,
374
+            this.toolStripSeparator4,
375
+            this.ClearAllAllToolStripMenuItem});
372
             this.toolStripMenuItem1.Name = "toolStripMenuItem1";
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
             // IPToolStripMenuItem
380
             // IPToolStripMenuItem
377
             // 
381
             // 
397
             this.CCIDToolStripMenuItem.Text = "CCID记录";
401
             this.CCIDToolStripMenuItem.Text = "CCID记录";
398
             this.CCIDToolStripMenuItem.Click += new System.EventHandler(this.CCIDToolStripMenuItem_Click);
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
             // 心跳HToolStripMenuItem
412
             // 心跳HToolStripMenuItem
401
             // 
413
             // 
402
             this.心跳HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
414
             this.心跳HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
564
             this.timerHeartBeat.Interval = 5000;
576
             this.timerHeartBeat.Interval = 5000;
565
             this.timerHeartBeat.Tick += new System.EventHandler(this.timerHeartBeat_Tick);
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
             // Form1
591
             // Form1
576
             // 
592
             // 
653
         private System.Windows.Forms.ToolStripMenuItem AddrToolStripMenuItem;
669
         private System.Windows.Forms.ToolStripMenuItem AddrToolStripMenuItem;
654
         private System.Windows.Forms.ToolStripMenuItem CCIDToolStripMenuItem;
670
         private System.Windows.Forms.ToolStripMenuItem CCIDToolStripMenuItem;
655
         private System.Windows.Forms.ToolStripMenuItem SendToolStripMenuItem;
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 View File

143
             string trim = tfTmpSendData.Text.Trim();
143
             string trim = tfTmpSendData.Text.Trim();
144
             trim = trim.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace(" ", "").Replace("-", "");
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
                 tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
206
                 tbPresureTestCount.Visible = !tbPresureTestCount.Visible;
199
                 label4.Visible = !label4.Visible;
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
         private void toolStripMenuItemHBtime_Click(object sender, EventArgs e)
215
         private void toolStripMenuItemHBtime_Click(object sender, EventArgs e)
209
                 timerHeartBeat.Interval = int.Parse(topmost) * 1000;
220
                 timerHeartBeat.Interval = int.Parse(topmost) * 1000;
210
                 //5秒
221
                 //5秒
211
                 toolStripStatusLabelHbShow.Text = "心跳时间: " + topmost + "秒";
222
                 toolStripStatusLabelHbShow.Text = "心跳时间: " + topmost + "秒";
212
-
213
             };
223
             };
214
             id.ShowDialog();
224
             id.ShowDialog();
215
         }
225
         }
221
 
231
 
222
         private void labelHis_Click(object sender, EventArgs e)
232
         private void labelHis_Click(object sender, EventArgs e)
223
         {
233
         {
224
-            Label lab= sender as Label;
234
+            Label lab = sender as Label;
225
             HistoryDialog hd = new HistoryDialog(lab.Name);
235
             HistoryDialog hd = new HistoryDialog(lab.Name);
226
             hd.HistoryHandler += Hd_HistoryHandler;
236
             hd.HistoryHandler += Hd_HistoryHandler;
227
             hd.ShowDialog();
237
             hd.ShowDialog();
241
             {
251
             {
242
                 tbIpaddress.Text = result;
252
                 tbIpaddress.Text = result;
243
             }
253
             }
254
+            else if ("labelSendHIS".Equals(type))
255
+            {
256
+                tfTmpSendData.Text = result;
257
+            }
244
         }
258
         }
245
 
259
 
246
         private void IPToolStripMenuItem_Click(object sender, EventArgs e)
260
         private void IPToolStripMenuItem_Click(object sender, EventArgs e)
263
             hd.HistoryHandler += Hd_HistoryHandler;
277
             hd.HistoryHandler += Hd_HistoryHandler;
264
             hd.ShowDialog();
278
             hd.ShowDialog();
265
         }
279
         }
280
+
266
         private void SendToolStripMenuItem_Click(object sender, EventArgs e)
281
         private void SendToolStripMenuItem_Click(object sender, EventArgs e)
267
         {
282
         {
268
             HistoryDialog hd = new HistoryDialog("labelSendHIS");
283
             HistoryDialog hd = new HistoryDialog("labelSendHIS");
396
 
411
 
397
                 if (ToolStripMenuItemLogHb.Checked && hbLen.Equals("0000"))
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
             else
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
             if (!(funcode == 16 || funcode == 32))
424
             if (!(funcode == 16 || funcode == 32))
508
             //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
525
             //                string loginCmd = "7e7e7e4442832e833c8200143839383630324231313931353530343739383737f7";
509
             string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
526
             string loginCmd = vcarecityProtocolBean.ProtocolStartSymbol;
510
             loginCmd += tbEquipmentAddress.Text.Trim() + "82";
527
             loginCmd += tbEquipmentAddress.Text.Trim() + "82";
511
-                        
512
-            
528
+
529
+
513
             loginCmd += Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
530
             loginCmd += Utils.stringWith0(Utils.tenToHex(tbCCID.Text.Trim().Length / 2), 4);
514
             loginCmd += tbCCID.Text.Trim();
531
             loginCmd += tbCCID.Text.Trim();
515
-            
516
 
532
 
517
-            
533
+
518
             loginCmd = Utils.calcCrcCode(loginCmd);
534
             loginCmd = Utils.calcCrcCode(loginCmd);
519
             //发送登录命令
535
             //发送登录命令
520
             byte[] ts = HexUtil.hexToBytes(loginCmd);
536
             byte[] ts = HexUtil.hexToBytes(loginCmd);
621
                         new SolidBrush(e.ForeColor),
637
                         new SolidBrush(e.ForeColor),
622
                         e.Bounds);
638
                         e.Bounds);
623
                 }
639
                 }
624
-               
640
+
625
                 e.DrawFocusRectangle();
641
                 e.DrawFocusRectangle();
626
             }
642
             }
627
         }
643
         }
678
                     //如果勾选了登录成功并心跳
694
                     //如果勾选了登录成功并心跳
679
                     timerHeartBeat.Enabled = true;
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
             else
703
             else
683
             {
704
             {
690
             }
711
             }
691
         }
712
         }
692
 
713
 
693
-
694
-
695
-
696
-
697
-
698
-
699
         #endregion
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 View File

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

+ 49 - 48
GWSocketClient/HistoryDialog.Designer.cs View File

30
         {
30
         {
31
             this.components = new System.ComponentModel.Container();
31
             this.components = new System.ComponentModel.Container();
32
             this.listBoxHistory = new System.Windows.Forms.ListBox();
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
             this.rightCTXHIS = new System.Windows.Forms.ContextMenuStrip(this.components);
33
             this.rightCTXHIS = new System.Windows.Forms.ContextMenuStrip(this.components);
39
             this.DelteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
34
             this.DelteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
40
             this.AllClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
35
             this.AllClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
41
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
36
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
42
             this.CopyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
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
             this.rightCTXHIS.SuspendLayout();
43
             this.rightCTXHIS.SuspendLayout();
44
             this.SuspendLayout();
44
             this.SuspendLayout();
45
             // 
45
             // 
47
             // 
47
             // 
48
             this.listBoxHistory.ContextMenuStrip = this.rightCTXHIS;
48
             this.listBoxHistory.ContextMenuStrip = this.rightCTXHIS;
49
             this.listBoxHistory.FormattingEnabled = true;
49
             this.listBoxHistory.FormattingEnabled = true;
50
+            this.listBoxHistory.HorizontalScrollbar = true;
50
             this.listBoxHistory.ItemHeight = 20;
51
             this.listBoxHistory.ItemHeight = 20;
51
             this.listBoxHistory.Location = new System.Drawing.Point(12, 7);
52
             this.listBoxHistory.Location = new System.Drawing.Point(12, 7);
52
             this.listBoxHistory.Name = "listBoxHistory";
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
             this.listBoxHistory.TabIndex = 0;
55
             this.listBoxHistory.TabIndex = 0;
55
             this.listBoxHistory.DoubleClick += new System.EventHandler(this.listBoxHistory_DoubleClick);
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
             // buttonRandom
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
             this.buttonRandom.Name = "buttonRandom";
97
             this.buttonRandom.Name = "buttonRandom";
61
             this.buttonRandom.Size = new System.Drawing.Size(119, 39);
98
             this.buttonRandom.Size = new System.Drawing.Size(119, 39);
62
             this.buttonRandom.TabIndex = 1;
99
             this.buttonRandom.TabIndex = 1;
68
             // buttonCancle
105
             // buttonCancle
69
             // 
106
             // 
70
             this.buttonCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;
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
             this.buttonCancle.Name = "buttonCancle";
109
             this.buttonCancle.Name = "buttonCancle";
73
             this.buttonCancle.Size = new System.Drawing.Size(119, 39);
110
             this.buttonCancle.Size = new System.Drawing.Size(119, 39);
74
             this.buttonCancle.TabIndex = 2;
111
             this.buttonCancle.TabIndex = 2;
79
             // 
116
             // 
80
             this.textBoxSourceCCID.Location = new System.Drawing.Point(12, 401);
117
             this.textBoxSourceCCID.Location = new System.Drawing.Point(12, 401);
81
             this.textBoxSourceCCID.Name = "textBoxSourceCCID";
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
             this.textBoxSourceCCID.TabIndex = 3;
120
             this.textBoxSourceCCID.TabIndex = 3;
84
             this.textBoxSourceCCID.Visible = false;
121
             this.textBoxSourceCCID.Visible = false;
85
             this.textBoxSourceCCID.TextChanged += new System.EventHandler(this.textBoxSourceCCID_TextChanged);
122
             this.textBoxSourceCCID.TextChanged += new System.EventHandler(this.textBoxSourceCCID_TextChanged);
87
             // buttonTransalteCCID
124
             // buttonTransalteCCID
88
             // 
125
             // 
89
             this.buttonTransalteCCID.DialogResult = System.Windows.Forms.DialogResult.Cancel;
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
             this.buttonTransalteCCID.Name = "buttonTransalteCCID";
128
             this.buttonTransalteCCID.Name = "buttonTransalteCCID";
92
             this.buttonTransalteCCID.Size = new System.Drawing.Size(119, 39);
129
             this.buttonTransalteCCID.Size = new System.Drawing.Size(119, 39);
93
             this.buttonTransalteCCID.TabIndex = 4;
130
             this.buttonTransalteCCID.TabIndex = 4;
99
             // labelCCIDLEN
136
             // labelCCIDLEN
100
             // 
137
             // 
101
             this.labelCCIDLEN.AutoSize = true;
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
             this.labelCCIDLEN.Name = "labelCCIDLEN";
140
             this.labelCCIDLEN.Name = "labelCCIDLEN";
104
             this.labelCCIDLEN.Size = new System.Drawing.Size(17, 20);
141
             this.labelCCIDLEN.Size = new System.Drawing.Size(17, 20);
105
             this.labelCCIDLEN.TabIndex = 5;
142
             this.labelCCIDLEN.TabIndex = 5;
106
             this.labelCCIDLEN.Text = "0";
143
             this.labelCCIDLEN.Text = "0";
107
             this.labelCCIDLEN.Visible = false;
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
             // HistoryDialog
146
             // HistoryDialog
146
             // 
147
             // 
147
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
148
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
148
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
149
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
149
             this.CancelButton = this.buttonCancle;
150
             this.CancelButton = this.buttonCancle;
150
-            this.ClientSize = new System.Drawing.Size(446, 484);
151
+            this.ClientSize = new System.Drawing.Size(657, 484);
151
             this.Controls.Add(this.labelCCIDLEN);
152
             this.Controls.Add(this.labelCCIDLEN);
152
             this.Controls.Add(this.buttonTransalteCCID);
153
             this.Controls.Add(this.buttonTransalteCCID);
153
             this.Controls.Add(this.textBoxSourceCCID);
154
             this.Controls.Add(this.textBoxSourceCCID);

+ 12 - 23
GWSocketClient/HistoryDialog.cs View File

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

BIN
GWSocketClient/bin/Debug/dbfile/ID_INFO.accdb View File


BIN
GWSocketClient/bin/Release/dbfile/ID_INFO.accdb View File


+ 70 - 11
GWSocketClient/db/AccessDbLoader.cs View File

269
 
269
 
270
         public int deleteAllData(string tableName = "fw")
270
         public int deleteAllData(string tableName = "fw")
271
         {
271
         {
272
-            string sql = "delete from "+ tableName;
272
+            string sql = "delete from " + tableName;
273
             Console.WriteLine(sql);
273
             Console.WriteLine(sql);
274
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
274
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
275
             return inst.ExecuteNonQuery();
275
             return inst.ExecuteNonQuery();
289
         public int getHistoryCount(string tableName)
289
         public int getHistoryCount(string tableName)
290
         {
290
         {
291
             string sql = "select COUNT(*),MIN(ID) from " + tableName;
291
             string sql = "select COUNT(*),MIN(ID) from " + tableName;
292
+
292
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
293
             OleDbCommand inst = new OleDbCommand(sql, objConnection);
293
             int count = 0;
294
             int count = 0;
294
             int minId = 0;
295
             int minId = 0;
295
             using (OleDbDataReader reader = inst.ExecuteReader())
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
             if (count > 30)
312
             if (count > 30)
303
             {
313
             {
304
                 sql = "delete from " + tableName + "  where ID=" + minId;
314
                 sql = "delete from " + tableName + "  where ID=" + minId;
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
         public int addToHistory(string tableName, string his)
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
             OleDbCommand inst = null;
373
             OleDbCommand inst = null;
317
 
374
 
318
             string sql = "INSERT INTO " + tableName + "(";
375
             string sql = "INSERT INTO " + tableName + "(";
331
                 sql += "CCID) VALUES('" + his + "')";
388
                 sql += "CCID) VALUES('" + his + "')";
332
                 Console.WriteLine(sql);
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
             inst = new OleDbCommand(sql, objConnection);
396
             inst = new OleDbCommand(sql, objConnection);
335
             return inst.ExecuteNonQuery();
397
             return inst.ExecuteNonQuery();
336
         }
398
         }
337
 
399
 
338
 
400
 
339
-
340
         public int deleteByID(string tablename, int id)
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
             return inst.ExecuteNonQuery();
405
             return inst.ExecuteNonQuery();
345
         }
406
         }
346
 
407
 
363
             }
424
             }
364
             return hsiList;
425
             return hsiList;
365
         }
426
         }
366
-
367
-
368
     }
427
     }
369
 }
428
 }

+ 4 - 0
GWSocketClientTests/GWSocketClientTests.csproj View File

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

+ 24 - 0
GWSocketClientTests/db/AccessDbLoaderTests.cs View File

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 View File

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