张泳健 7 лет назад
Родитель
Сommit
385a8ee2d9

+ 1 - 0
DotNettyFrom/DotNettyFrom.csproj Просмотреть файл

@@ -138,6 +138,7 @@
138 138
     <Compile Include="dialog\HeartBeatTime.Designer.cs">
139 139
       <DependentUpon>HeartBeatTime.cs</DependentUpon>
140 140
     </Compile>
141
+    <Compile Include="excel\ExcelHelper.cs" />
141 142
     <Compile Include="form\ItemEditorForm.cs">
142 143
       <SubType>Form</SubType>
143 144
     </Compile>

+ 22 - 9
DotNettyFrom/db/DBHelper.cs Просмотреть файл

@@ -98,26 +98,37 @@ namespace DotNettyFrom.db
98 98
             }
99 99
         }
100 100
 
101
+        public int DeleteAllFwData()
102
+        {
103
+            string sql = @"delete from fw";
104
+            using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
105
+            {
106
+                return inst.ExecuteNonQuery();
107
+            }
108
+        }
109
+
101 110
         //Update
102 111
         public int UpdateCmd(WvBean wb)
103 112
         {
104
-            string sql = "update fw set my_index=" + wb.index + ",MY_ID=\"" + wb.myId + "\",idInfo=\"" + wb.idInfo +
105
-                         "\",len=\"" + wb.len +
106
-                         "\",mode=\"" +
107
-                         wb.mode + "\",desp=\"" + wb.desp + "\",default_value=\"" + wb.defalutValue +
108
-                         "\",user_value=\"" +
109
-                         wb.userValue + "\",remark=\"" + wb.remark + "\" where ID=" + wb.id;
110
-            using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
113
+            string updateSQL = "update fw set my_index=" + wb.index + ",MY_ID=\"" + wb.myId + "\",idInfo=\"" +
114
+                               wb.idInfo +
115
+                               "\",len=\"" + wb.len +
116
+                               "\",mode=\"" +
117
+                               wb.mode + "\",desp=\"" + wb.desp + "\",default_value=\"" + wb.defalutValue +
118
+                               "\",user_value=\"" +
119
+                               wb.userValue + "\",remark=\"" + wb.remark + "\" where ID=" + wb.id;
120
+
121
+            using (OleDbCommand inst = new OleDbCommand(updateSQL, _DbConn))
111 122
             {
112 123
                 return inst.ExecuteNonQuery();
113 124
             }
114 125
         }
115 126
 
116 127
         //Select
117
-        public DataTable SelectCmds()
128
+        public DataTable SelectCmds(string sql = @"select * from fw")
118 129
         {
119 130
             DataTable dataTable = new DataTable();
120
-            string sql = @"select * from fw";
131
+//            string sql = @"select * from fw";
121 132
 
122 133
             using (OleDbCommand sqlcmd = new OleDbCommand(sql, _DbConn))
123 134
             {
@@ -222,5 +233,7 @@ namespace DotNettyFrom.db
222 233
             }
223 234
             return wb;
224 235
         }
236
+
237
+       
225 238
     }
226 239
 }

+ 101 - 0
DotNettyFrom/excel/ExcelHelper.cs Просмотреть файл

@@ -0,0 +1,101 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Data;
4
+using System.Data.OleDb;
5
+using System.Linq;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+using System.Windows.Forms;
9
+using DotNettyFrom.util;
10
+
11
+namespace DotNettyFrom.excel
12
+{
13
+    public class ExcelHelper
14
+    {
15
+        private string excelConn = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = ";
16
+
17
+        private RichTextBox richTextBox;
18
+
19
+        private List<WvBean> excelList = new List<WvBean>();
20
+
21
+        public ExcelHelper(string excelPath, RichTextBox richTextBox)
22
+        {
23
+            this.richTextBox = richTextBox;
24
+            excelConn += excelPath + ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'";
25
+        }
26
+
27
+        public List<WvBean> GetExcelList()
28
+        {
29
+            return excelList;
30
+        }
31
+
32
+        public ExcelHelper LoadExcelFile()
33
+        {
34
+            using (OleDbConnection conn = new OleDbConnection(excelConn))
35
+            {
36
+                conn.Open();
37
+                DataSet dataSet = new DataSet();
38
+
39
+                try
40
+                {
41
+                    OleDbDataAdapter odda = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", conn);
42
+                    odda.Fill(dataSet, "Sheet1$");
43
+
44
+                    if (dataSet.Tables.Count > 0)
45
+                    {
46
+                        DataTable dt = dataSet.Tables[0];
47
+
48
+                        int hang = dt.Rows.Count;
49
+
50
+                        excelList.Clear();
51
+
52
+                        for (int i = 1; i < hang; i++)
53
+                        {
54
+                            WvBean wb = null;
55
+                            try
56
+                            {
57
+                                int myIndex = int.Parse(dt.Rows[i][0] + "");
58
+                                string myId = CmdUtil.FrontWithZero(CmdUtil.Dec2Hex(myIndex), 4);
59
+                                string idInfo = dt.Rows[i][1].ToString().Trim();
60
+                                string len = dt.Rows[i][2].ToString().Trim();
61
+                                string mode = dt.Rows[i][3].ToString().Trim();
62
+                                string desp = dt.Rows[i][4].ToString().Trim();
63
+                                string defaultValue = dt.Rows[i][5].ToString().Trim();
64
+                                string remark = dt.Rows[i][6].ToString().Trim();
65
+
66
+                                if (len.Equals("") || mode.Equals("") || defaultValue.Equals(""))
67
+                                {
68
+                                    richTextBox.Text += "第" + i + "行;长度,模式,默认值不能为空\n";
69
+                                    continue;
70
+                                }
71
+
72
+                                wb = new WvBean();
73
+                                wb.index = myIndex;
74
+                                wb.myId = myId;
75
+                                wb.idInfo = idInfo;
76
+                                wb.len = len;
77
+                                wb.mode = mode;
78
+                                wb.desp = desp;
79
+                                wb.defalutValue = defaultValue;
80
+                                wb.userValue = defaultValue;
81
+                                wb.remark = remark;
82
+                                excelList.Add(wb);
83
+                            }
84
+                            catch (Exception exception)
85
+                            {
86
+                                richTextBox.Text += "第" + i + "行;" + exception.Message + "\n";
87
+                                Console.WriteLine(exception);
88
+                            }
89
+                        }
90
+                    }
91
+                }
92
+                catch (Exception exception)
93
+                {
94
+                    Console.WriteLine(exception.Message);
95
+                    richTextBox.Text = "请确定Excel表名为\"Sheet1\"\n" + exception.Message + "\n";
96
+                }
97
+            }
98
+            return this;
99
+        }
100
+    }
101
+}

+ 126 - 93
DotNettyFrom/form/ItemEditorForm.Designer.cs Просмотреть файл

@@ -34,29 +34,31 @@
34 34
             this.TbItemId = new System.Windows.Forms.TextBox();
35 35
             this.TbitemId2 = new System.Windows.Forms.TextBox();
36 36
             this.label4 = new System.Windows.Forms.Label();
37
-            this.textBox3 = new System.Windows.Forms.TextBox();
38
-            this.textBox4 = new System.Windows.Forms.TextBox();
37
+            this.TbInfo = new System.Windows.Forms.TextBox();
38
+            this.TbLen = new System.Windows.Forms.TextBox();
39 39
             this.label5 = new System.Windows.Forms.Label();
40 40
             this.label6 = new System.Windows.Forms.Label();
41
-            this.checkBox1 = new System.Windows.Forms.CheckBox();
42
-            this.checkBox2 = new System.Windows.Forms.CheckBox();
43
-            this.textBox5 = new System.Windows.Forms.TextBox();
41
+            this.CheckBoxRead = new System.Windows.Forms.CheckBox();
42
+            this.CheckBoxWrite = new System.Windows.Forms.CheckBox();
43
+            this.TbDesp = new System.Windows.Forms.TextBox();
44 44
             this.label7 = new System.Windows.Forms.Label();
45
-            this.textBox6 = new System.Windows.Forms.TextBox();
45
+            this.TbDv = new System.Windows.Forms.TextBox();
46 46
             this.label8 = new System.Windows.Forms.Label();
47
-            this.textBox7 = new System.Windows.Forms.TextBox();
47
+            this.TbUv = new System.Windows.Forms.TextBox();
48 48
             this.label9 = new System.Windows.Forms.Label();
49
-            this.textBox8 = new System.Windows.Forms.TextBox();
49
+            this.TbRemark = new System.Windows.Forms.TextBox();
50 50
             this.label10 = new System.Windows.Forms.Label();
51 51
             this.label11 = new System.Windows.Forms.Label();
52
-            this.label12 = new System.Windows.Forms.Label();
52
+            this.LbUserV = new System.Windows.Forms.Label();
53 53
             this.label13 = new System.Windows.Forms.Label();
54
-            this.label14 = new System.Windows.Forms.Label();
54
+            this.LbDefaultV = new System.Windows.Forms.Label();
55 55
             this.RtbInfo = new System.Windows.Forms.RichTextBox();
56 56
             this.BtnCancle = new System.Windows.Forms.Button();
57 57
             this.BtnOp = new System.Windows.Forms.Button();
58 58
             this.CBInputType = new System.Windows.Forms.ComboBox();
59 59
             this.label3 = new System.Windows.Forms.Label();
60
+            this.CBLenUnFix = new System.Windows.Forms.CheckBox();
61
+            this.CBUnCheckUD = new System.Windows.Forms.CheckBox();
60 62
             this.SuspendLayout();
61 63
             // 
62 64
             // label1
@@ -73,9 +75,8 @@
73 75
             this.LbDbPriKey.AutoSize = true;
74 76
             this.LbDbPriKey.Location = new System.Drawing.Point(125, 9);
75 77
             this.LbDbPriKey.Name = "LbDbPriKey";
76
-            this.LbDbPriKey.Size = new System.Drawing.Size(34, 17);
78
+            this.LbDbPriKey.Size = new System.Drawing.Size(0, 17);
77 79
             this.LbDbPriKey.TabIndex = 1;
78
-            this.LbDbPriKey.Text = "Keyr";
79 80
             // 
80 81
             // label2
81 82
             // 
@@ -93,7 +94,6 @@
93 94
             this.TbItemId.Size = new System.Drawing.Size(121, 23);
94 95
             this.TbItemId.TabIndex = 3;
95 96
             this.TbItemId.TextChanged += new System.EventHandler(this.TbItemId_TextChanged);
96
-            this.TbItemId.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
97 97
             // 
98 98
             // TbitemId2
99 99
             // 
@@ -112,19 +112,20 @@
112 112
             this.label4.TabIndex = 6;
113 113
             this.label4.Text = "功能";
114 114
             // 
115
-            // textBox3
115
+            // TbInfo
116 116
             // 
117
-            this.textBox3.Location = new System.Drawing.Point(50, 64);
118
-            this.textBox3.Name = "textBox3";
119
-            this.textBox3.Size = new System.Drawing.Size(615, 23);
120
-            this.textBox3.TabIndex = 7;
117
+            this.TbInfo.Location = new System.Drawing.Point(50, 64);
118
+            this.TbInfo.Name = "TbInfo";
119
+            this.TbInfo.Size = new System.Drawing.Size(615, 23);
120
+            this.TbInfo.TabIndex = 7;
121 121
             // 
122
-            // textBox4
122
+            // TbLen
123 123
             // 
124
-            this.textBox4.Location = new System.Drawing.Point(50, 93);
125
-            this.textBox4.Name = "textBox4";
126
-            this.textBox4.Size = new System.Drawing.Size(615, 23);
127
-            this.textBox4.TabIndex = 9;
124
+            this.TbLen.Location = new System.Drawing.Point(50, 93);
125
+            this.TbLen.Name = "TbLen";
126
+            this.TbLen.Size = new System.Drawing.Size(151, 23);
127
+            this.TbLen.TabIndex = 9;
128
+            this.TbLen.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TbLen_KeyPress);
128 129
             // 
129 130
             // label5
130 131
             // 
@@ -144,32 +145,32 @@
144 145
             this.label6.TabIndex = 10;
145 146
             this.label6.Text = "读写";
146 147
             // 
147
-            // checkBox1
148
+            // CheckBoxRead
148 149
             // 
149
-            this.checkBox1.AutoSize = true;
150
-            this.checkBox1.Location = new System.Drawing.Point(54, 122);
151
-            this.checkBox1.Name = "checkBox1";
152
-            this.checkBox1.Size = new System.Drawing.Size(52, 21);
153
-            this.checkBox1.TabIndex = 11;
154
-            this.checkBox1.Text = "读/R";
155
-            this.checkBox1.UseVisualStyleBackColor = true;
150
+            this.CheckBoxRead.AutoSize = true;
151
+            this.CheckBoxRead.Location = new System.Drawing.Point(54, 122);
152
+            this.CheckBoxRead.Name = "CheckBoxRead";
153
+            this.CheckBoxRead.Size = new System.Drawing.Size(52, 21);
154
+            this.CheckBoxRead.TabIndex = 11;
155
+            this.CheckBoxRead.Text = "读/R";
156
+            this.CheckBoxRead.UseVisualStyleBackColor = true;
156 157
             // 
157
-            // checkBox2
158
+            // CheckBoxWrite
158 159
             // 
159
-            this.checkBox2.AutoSize = true;
160
-            this.checkBox2.Location = new System.Drawing.Point(112, 122);
161
-            this.checkBox2.Name = "checkBox2";
162
-            this.checkBox2.Size = new System.Drawing.Size(56, 21);
163
-            this.checkBox2.TabIndex = 11;
164
-            this.checkBox2.Text = "写/W";
165
-            this.checkBox2.UseVisualStyleBackColor = true;
160
+            this.CheckBoxWrite.AutoSize = true;
161
+            this.CheckBoxWrite.Location = new System.Drawing.Point(112, 122);
162
+            this.CheckBoxWrite.Name = "CheckBoxWrite";
163
+            this.CheckBoxWrite.Size = new System.Drawing.Size(56, 21);
164
+            this.CheckBoxWrite.TabIndex = 11;
165
+            this.CheckBoxWrite.Text = "写/W";
166
+            this.CheckBoxWrite.UseVisualStyleBackColor = true;
166 167
             // 
167
-            // textBox5
168
+            // TbDesp
168 169
             // 
169
-            this.textBox5.Location = new System.Drawing.Point(50, 149);
170
-            this.textBox5.Name = "textBox5";
171
-            this.textBox5.Size = new System.Drawing.Size(615, 23);
172
-            this.textBox5.TabIndex = 13;
170
+            this.TbDesp.Location = new System.Drawing.Point(50, 149);
171
+            this.TbDesp.Name = "TbDesp";
172
+            this.TbDesp.Size = new System.Drawing.Size(615, 23);
173
+            this.TbDesp.TabIndex = 13;
173 174
             // 
174 175
             // label7
175 176
             // 
@@ -180,12 +181,13 @@
180 181
             this.label7.TabIndex = 12;
181 182
             this.label7.Text = "描述";
182 183
             // 
183
-            // textBox6
184
+            // TbDv
184 185
             // 
185
-            this.textBox6.Location = new System.Drawing.Point(62, 178);
186
-            this.textBox6.Name = "textBox6";
187
-            this.textBox6.Size = new System.Drawing.Size(603, 23);
188
-            this.textBox6.TabIndex = 15;
186
+            this.TbDv.Location = new System.Drawing.Point(62, 178);
187
+            this.TbDv.Name = "TbDv";
188
+            this.TbDv.Size = new System.Drawing.Size(603, 23);
189
+            this.TbDv.TabIndex = 15;
190
+            this.TbDv.TextChanged += new System.EventHandler(this.TbDv_TextChanged);
189 191
             // 
190 192
             // label8
191 193
             // 
@@ -196,12 +198,13 @@
196 198
             this.label8.TabIndex = 14;
197 199
             this.label8.Text = "默认值";
198 200
             // 
199
-            // textBox7
201
+            // TbUv
200 202
             // 
201
-            this.textBox7.Location = new System.Drawing.Point(62, 207);
202
-            this.textBox7.Name = "textBox7";
203
-            this.textBox7.Size = new System.Drawing.Size(603, 23);
204
-            this.textBox7.TabIndex = 17;
203
+            this.TbUv.Location = new System.Drawing.Point(62, 207);
204
+            this.TbUv.Name = "TbUv";
205
+            this.TbUv.Size = new System.Drawing.Size(603, 23);
206
+            this.TbUv.TabIndex = 17;
207
+            this.TbUv.TextChanged += new System.EventHandler(this.TbUv_TextChanged);
205 208
             // 
206 209
             // label9
207 210
             // 
@@ -212,12 +215,12 @@
212 215
             this.label9.TabIndex = 16;
213 216
             this.label9.Text = "用户值";
214 217
             // 
215
-            // textBox8
218
+            // TbRemark
216 219
             // 
217
-            this.textBox8.Location = new System.Drawing.Point(50, 236);
218
-            this.textBox8.Name = "textBox8";
219
-            this.textBox8.Size = new System.Drawing.Size(615, 23);
220
-            this.textBox8.TabIndex = 19;
220
+            this.TbRemark.Location = new System.Drawing.Point(50, 236);
221
+            this.TbRemark.Name = "TbRemark";
222
+            this.TbRemark.Size = new System.Drawing.Size(615, 23);
223
+            this.TbRemark.TabIndex = 19;
221 224
             // 
222 225
             // label10
223 226
             // 
@@ -237,14 +240,14 @@
237 240
             this.label11.TabIndex = 20;
238 241
             this.label11.Text = "默认值长度:";
239 242
             // 
240
-            // label12
243
+            // LbUserV
241 244
             // 
242
-            this.label12.AutoSize = true;
243
-            this.label12.Location = new System.Drawing.Point(207, 275);
244
-            this.label12.Name = "label12";
245
-            this.label12.Size = new System.Drawing.Size(22, 17);
246
-            this.label12.TabIndex = 21;
247
-            this.label12.Text = "00";
245
+            this.LbUserV.AutoSize = true;
246
+            this.LbUserV.Location = new System.Drawing.Point(207, 275);
247
+            this.LbUserV.Name = "LbUserV";
248
+            this.LbUserV.Size = new System.Drawing.Size(22, 17);
249
+            this.LbUserV.TabIndex = 21;
250
+            this.LbUserV.Text = "00";
248 251
             // 
249 252
             // label13
250 253
             // 
@@ -255,14 +258,14 @@
255 258
             this.label13.TabIndex = 22;
256 259
             this.label13.Text = "用户值长度:";
257 260
             // 
258
-            // label14
261
+            // LbDefaultV
259 262
             // 
260
-            this.label14.AutoSize = true;
261
-            this.label14.Location = new System.Drawing.Point(89, 275);
262
-            this.label14.Name = "label14";
263
-            this.label14.Size = new System.Drawing.Size(22, 17);
264
-            this.label14.TabIndex = 23;
265
-            this.label14.Text = "00";
263
+            this.LbDefaultV.AutoSize = true;
264
+            this.LbDefaultV.Location = new System.Drawing.Point(89, 275);
265
+            this.LbDefaultV.Name = "LbDefaultV";
266
+            this.LbDefaultV.Size = new System.Drawing.Size(22, 17);
267
+            this.LbDefaultV.TabIndex = 23;
268
+            this.LbDefaultV.Text = "00";
266 269
             // 
267 270
             // RtbInfo
268 271
             // 
@@ -275,6 +278,7 @@
275 278
             // 
276 279
             // BtnCancle
277 280
             // 
281
+            this.BtnCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;
278 282
             this.BtnCancle.Location = new System.Drawing.Point(509, 397);
279 283
             this.BtnCancle.Name = "BtnCancle";
280 284
             this.BtnCancle.Size = new System.Drawing.Size(75, 23);
@@ -290,6 +294,7 @@
290 294
             this.BtnOp.TabIndex = 25;
291 295
             this.BtnOp.Text = "添加";
292 296
             this.BtnOp.UseVisualStyleBackColor = true;
297
+            this.BtnOp.Click += new System.EventHandler(this.BtnOp_Click);
293 298
             // 
294 299
             // CBInputType
295 300
             // 
@@ -314,33 +319,59 @@
314 319
             this.label3.Text = "不同进制";
315 320
             this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter;
316 321
             // 
322
+            // CBLenUnFix
323
+            // 
324
+            this.CBLenUnFix.AutoSize = true;
325
+            this.CBLenUnFix.Location = new System.Drawing.Point(210, 95);
326
+            this.CBLenUnFix.Name = "CBLenUnFix";
327
+            this.CBLenUnFix.Size = new System.Drawing.Size(63, 21);
328
+            this.CBLenUnFix.TabIndex = 27;
329
+            this.CBLenUnFix.Text = "不定长";
330
+            this.CBLenUnFix.UseVisualStyleBackColor = true;
331
+            this.CBLenUnFix.CheckedChanged += new System.EventHandler(this.CBLenUnFix_CheckedChanged);
332
+            // 
333
+            // CBUnCheckUD
334
+            // 
335
+            this.CBUnCheckUD.AutoSize = true;
336
+            this.CBUnCheckUD.Checked = true;
337
+            this.CBUnCheckUD.CheckState = System.Windows.Forms.CheckState.Checked;
338
+            this.CBUnCheckUD.Location = new System.Drawing.Point(279, 95);
339
+            this.CBUnCheckUD.Name = "CBUnCheckUD";
340
+            this.CBUnCheckUD.Size = new System.Drawing.Size(147, 21);
341
+            this.CBUnCheckUD.TabIndex = 28;
342
+            this.CBUnCheckUD.Text = "是否检查长度与默认值";
343
+            this.CBUnCheckUD.UseVisualStyleBackColor = true;
344
+            // 
317 345
             // ItemEditorForm
318 346
             // 
319 347
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
320 348
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
349
+            this.CancelButton = this.BtnCancle;
321 350
             this.ClientSize = new System.Drawing.Size(677, 432);
351
+            this.Controls.Add(this.CBUnCheckUD);
352
+            this.Controls.Add(this.CBLenUnFix);
322 353
             this.Controls.Add(this.CBInputType);
323 354
             this.Controls.Add(this.BtnOp);
324 355
             this.Controls.Add(this.BtnCancle);
325 356
             this.Controls.Add(this.RtbInfo);
326
-            this.Controls.Add(this.label14);
357
+            this.Controls.Add(this.LbDefaultV);
327 358
             this.Controls.Add(this.label13);
328
-            this.Controls.Add(this.label12);
359
+            this.Controls.Add(this.LbUserV);
329 360
             this.Controls.Add(this.label11);
330
-            this.Controls.Add(this.textBox8);
361
+            this.Controls.Add(this.TbRemark);
331 362
             this.Controls.Add(this.label10);
332
-            this.Controls.Add(this.textBox7);
363
+            this.Controls.Add(this.TbUv);
333 364
             this.Controls.Add(this.label9);
334
-            this.Controls.Add(this.textBox6);
365
+            this.Controls.Add(this.TbDv);
335 366
             this.Controls.Add(this.label8);
336
-            this.Controls.Add(this.textBox5);
367
+            this.Controls.Add(this.TbDesp);
337 368
             this.Controls.Add(this.label7);
338
-            this.Controls.Add(this.checkBox2);
339
-            this.Controls.Add(this.checkBox1);
369
+            this.Controls.Add(this.CheckBoxWrite);
370
+            this.Controls.Add(this.CheckBoxRead);
340 371
             this.Controls.Add(this.label6);
341
-            this.Controls.Add(this.textBox4);
372
+            this.Controls.Add(this.TbLen);
342 373
             this.Controls.Add(this.label5);
343
-            this.Controls.Add(this.textBox3);
374
+            this.Controls.Add(this.TbInfo);
344 375
             this.Controls.Add(this.label4);
345 376
             this.Controls.Add(this.TbitemId2);
346 377
             this.Controls.Add(this.label3);
@@ -372,28 +403,30 @@
372 403
         private System.Windows.Forms.TextBox TbItemId;
373 404
         private System.Windows.Forms.TextBox TbitemId2;
374 405
         private System.Windows.Forms.Label label4;
375
-        private System.Windows.Forms.TextBox textBox3;
376
-        private System.Windows.Forms.TextBox textBox4;
406
+        private System.Windows.Forms.TextBox TbInfo;
407
+        private System.Windows.Forms.TextBox TbLen;
377 408
         private System.Windows.Forms.Label label5;
378 409
         private System.Windows.Forms.Label label6;
379
-        private System.Windows.Forms.CheckBox checkBox1;
380
-        private System.Windows.Forms.CheckBox checkBox2;
381
-        private System.Windows.Forms.TextBox textBox5;
410
+        private System.Windows.Forms.CheckBox CheckBoxRead;
411
+        private System.Windows.Forms.CheckBox CheckBoxWrite;
412
+        private System.Windows.Forms.TextBox TbDesp;
382 413
         private System.Windows.Forms.Label label7;
383
-        private System.Windows.Forms.TextBox textBox6;
414
+        private System.Windows.Forms.TextBox TbDv;
384 415
         private System.Windows.Forms.Label label8;
385
-        private System.Windows.Forms.TextBox textBox7;
416
+        private System.Windows.Forms.TextBox TbUv;
386 417
         private System.Windows.Forms.Label label9;
387
-        private System.Windows.Forms.TextBox textBox8;
418
+        private System.Windows.Forms.TextBox TbRemark;
388 419
         private System.Windows.Forms.Label label10;
389 420
         private System.Windows.Forms.Label label11;
390
-        private System.Windows.Forms.Label label12;
421
+        private System.Windows.Forms.Label LbUserV;
391 422
         private System.Windows.Forms.Label label13;
392
-        private System.Windows.Forms.Label label14;
423
+        private System.Windows.Forms.Label LbDefaultV;
393 424
         private System.Windows.Forms.RichTextBox RtbInfo;
394 425
         private System.Windows.Forms.Button BtnCancle;
395 426
         private System.Windows.Forms.Button BtnOp;
396 427
         private System.Windows.Forms.ComboBox CBInputType;
397 428
         private System.Windows.Forms.Label label3;
429
+        private System.Windows.Forms.CheckBox CBLenUnFix;
430
+        private System.Windows.Forms.CheckBox CBUnCheckUD;
398 431
     }
399 432
 }

+ 263 - 13
DotNettyFrom/form/ItemEditorForm.cs Просмотреть файл

@@ -8,6 +8,7 @@ using System.Text;
8 8
 using System.Threading.Tasks;
9 9
 using System.Windows.Forms;
10 10
 using DotNettyFrom.db;
11
+using DotNettyFrom.util;
11 12
 
12 13
 namespace DotNettyFrom.form
13 14
 {
@@ -16,9 +17,10 @@ namespace DotNettyFrom.form
16 17
     public partial class ItemEditorForm : Form
17 18
     {
18 19
         public event OnItemHandlerResult ItemHandler;
19
-        private int _id;
20
+        private string _id;
21
+        private bool _isAdd = true; //true-add
20 22
 
21
-        public ItemEditorForm(int id = int.MinValue)
23
+        public ItemEditorForm(string id = null)
22 24
         {
23 25
             this._id = id;
24 26
             InitializeComponent();
@@ -28,28 +30,60 @@ namespace DotNettyFrom.form
28 30
         {
29 31
             CBInputType.SelectedIndex = 0;
30 32
 
31
-            if (_id != int.MinValue)
33
+            if (_id != null)
32 34
             {
33
-                UpdateOption();
35
+                _isAdd = false;
36
+                try
37
+                {
38
+                    int id = int.Parse(_id);
39
+                    UpdateOption(id);
40
+                }
41
+                catch (Exception)
42
+                {
43
+                    this.Close();
44
+                }
34 45
             }
35 46
         }
36 47
 
37
-        private void UpdateOption()
48
+        private void UpdateOption(int id)
38 49
         {
50
+         
39 51
             BtnOp.Text = "修改";
40
-            WvBean wb = DbHelper.GetInstance().SelectOneCmdById(_id);
41
-            Console.WriteLine(wb.ToString());
52
+            WvBean wb = DbHelper.GetInstance().SelectOneCmdById(id);
42 53
             this.Text = "修改ID - " + wb.id;
43
-        }
54
+            _isAdd = false;
44 55
 
45
-        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
46
-        {
47
-            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
56
+            TbItemId.Enabled = false;
57
+            CBInputType.Enabled = false;
58
+
59
+            LbDbPriKey.Text = wb.id + "";
60
+            TbItemId.Text = wb.index + "";
61
+            TbitemId2.Text = wb.myId;
62
+            TbInfo.Text = wb.idInfo;
63
+            if (wb.len.Contains("-"))
48 64
             {
49
-                e.Handled = true;
65
+                TbLen.Enabled = false;
66
+                CBLenUnFix.Checked = true;
67
+            }
68
+            else
69
+            {
70
+                TbLen.Text = wb.len;
50 71
             }
72
+            if (wb.mode.Contains("R"))
73
+            {
74
+                CheckBoxRead.Checked = true;
75
+            }
76
+            if (wb.mode.Contains("W"))
77
+            {
78
+                CheckBoxWrite.Checked = true;
79
+            }
80
+            TbDesp.Text = wb.desp;
81
+            TbDv.Text = wb.defalutValue;
82
+            TbUv.Text = wb.userValue;
83
+            TbRemark.Text = wb.remark;
51 84
         }
52 85
 
86
+
53 87
         private void CBInputType_SelectedIndexChanged(object sender, EventArgs e)
54 88
         {
55 89
             Console.WriteLine(CBInputType.SelectedIndex);
@@ -57,16 +91,232 @@ namespace DotNettyFrom.form
57 91
 
58 92
         private void TbItemId_TextChanged(object sender, EventArgs e)
59 93
         {
94
+            string text = TbItemId.Text.Trim();
95
+            if (text.Equals(""))
96
+            {
97
+                TbitemId2.Text = "";
98
+                return;
99
+            }
100
+
60 101
             if (CBInputType.SelectedIndex == 0)
61 102
             {
62 103
                 //10 ->16
63
-                
64 104
 
105
+                try
106
+                {
107
+                    int _id = int.Parse(text);
108
+                    TbitemId2.Text = CmdUtil.FrontWithZero(CmdUtil.Dec2Hex(_id), 4);
109
+                    RtbInfo.Text = "";
110
+                }
111
+                catch (Exception esException)
112
+                {
113
+                    RtbInfo.Text = esException.Message;
114
+                }
115
+            }
116
+            else if (CBInputType.SelectedIndex == 1)
117
+            {
118
+                //16 -> 10
65 119
 
120
+                try
121
+                {
122
+                    TbitemId2.Text = CmdUtil.Hex2Dec(text) + "";
123
+                    RtbInfo.Text = "";
124
+                }
125
+                catch (Exception esException)
126
+                {
127
+                    RtbInfo.Text = esException.Message;
128
+                }
129
+            }
130
+        }
131
+
132
+        private void BtnOp_Click(object sender, EventArgs e)
133
+        {
134
+            RtbInfo.Text = "";
135
+
136
+            #region Check
137
+
138
+            int MyIndex = Int32.MinValue;
139
+            string MyId = "";
140
+
141
+
142
+            if (TbItemId.Text.Trim().Equals(""))
143
+            {
144
+                RtbInfo.Text = "ID不能为空";
145
+                return;
146
+            }
147
+
148
+            if (TbitemId2.Text.Trim().Equals(""))
149
+            {
150
+                RtbInfo.Text = "ID不能为空";
151
+                return;
152
+            }
153
+
154
+
155
+            if (CBInputType.SelectedIndex == 0)
156
+            {
157
+                MyIndex = int.Parse(TbItemId.Text.Trim());
158
+                MyId = TbitemId2.Text.Trim();
66 159
             }
67 160
             else if (CBInputType.SelectedIndex == 1)
68 161
             {
162
+                MyIndex = int.Parse(TbitemId2.Text.Trim());
163
+                MyId = TbItemId.Text.Trim();
164
+            }
165
+
166
+            string lenString = "";
167
+
168
+            if (!CBLenUnFix.Checked)
169
+            {
170
+                lenString = TbLen.Text.Trim();
171
+            }
172
+            else
173
+            {
174
+                lenString = "-1";
175
+            }
176
+
177
+            if (lenString.Equals(""))
178
+            {
179
+                RtbInfo.Text = "长度不能为空!";
180
+                return;
181
+            }
182
+
183
+            bool modeBool = CheckBoxWrite.Checked || CheckBoxRead.Checked;
184
+            if (!modeBool)
185
+            {
186
+                RtbInfo.Text = "读写模式不能为空.至少要有一个!";
187
+                return;
188
+            }
189
+
190
+            string defalutValueString = TbDv.Text.Trim();
191
+            string userValueString = TbUv.Text.Trim();
192
+            if (defalutValueString.Equals(""))
193
+            {
194
+                RtbInfo.Text = "默认长度不能为空!";
195
+                return;
196
+            }
197
+            if (userValueString.Equals(""))
198
+            {
199
+                userValueString = defalutValueString;
200
+            }
201
+
202
+
203
+            if (defalutValueString.Length % 2 != 0)
204
+            {
205
+                RtbInfo.Text = "默认值长度不是整数!!!defalutValueString.Length=" + (defalutValueString.Length / 2.0);
206
+                return;
207
+            }
208
+            if (userValueString.Length % 2 != 0)
209
+            {
210
+                RtbInfo.Text = "用户值长度不是整数!!!defalutValueString.Length=" + (userValueString.Length / 2.0);
211
+                return;
212
+            }
213
+
214
+            if (!lenString.Contains("-") && CBUnCheckUD.Checked)
215
+            {
216
+                int len = int.Parse(lenString);
217
+
218
+                if ((defalutValueString.Length / 2) != len)
219
+                {
220
+                    RtbInfo.Text = "默认值长度不对.定义长度是=" + len + " ,你输入长度是=" +
221
+                                   (defalutValueString.Length / 2);
222
+                    return;
223
+                }
224
+                if ((userValueString.Length / 2) != len)
225
+                {
226
+                    RtbInfo.Text = "用户值长度不对.定义长度是=" + len + " ,你输入长度是=" + (userValueString.Length / 2.0);
227
+                    return;
228
+                }
229
+            }
230
+
231
+            #endregion
232
+
233
+            #region 组装操作
234
+
235
+            WvBean wb = new WvBean();
236
+            wb.index = MyIndex;
237
+            wb.myId = MyId;
238
+            wb.idInfo = TbInfo.Text.Trim();
239
+            wb.len = lenString;
240
+            string modeString = CheckBoxRead.Checked ? "R" : "";
241
+            modeString += CheckBoxWrite.Checked ? "W" : "";
242
+            wb.mode = modeString;
243
+            wb.desp = TbDesp.Text.Trim();
244
+            wb.defalutValue = defalutValueString;
245
+            wb.userValue = userValueString;
246
+            wb.remark = TbRemark.Text.Trim();
247
+
248
+            #endregion
249
+
250
+            #region 数据库
251
+
252
+            int res = -1;
253
+
254
+
255
+            if (_isAdd)
256
+            {
257
+                //add
258
+                try
259
+                {
260
+                    res = DbHelper.GetInstance().InsertCmd(wb);
261
+                }
262
+                catch (Exception exception)
263
+                {
264
+                    RtbInfo.Text = "异常:" + exception.Message + "\n请确定 " + MyIndex + " 是否已经存在";
265
+                }
266
+            }
267
+            else
268
+            {
269
+                //update
270
+                try
271
+                {
272
+                    wb.id = int.Parse(LbDbPriKey.Text);
273
+                    res = DbHelper.GetInstance().UpdateCmd(wb);
274
+                }
275
+                catch (Exception exception)
276
+                {
277
+                    RtbInfo.Text = "异常:" + exception.Message + "\n请确定 " + MyIndex + " 是否已经存在";
278
+                }
69 279
             }
280
+
281
+            if (res > 0)
282
+            {
283
+                if (ItemHandler != null)
284
+                    this.ItemHandler(0, "成功"); //执行委托实例  
285
+                this.Close();
286
+            }
287
+
288
+            #endregion
289
+        }
290
+
291
+        private void CBLenUnFix_CheckedChanged(object sender, EventArgs e)
292
+        {
293
+            if (CBLenUnFix.Checked)
294
+            {
295
+                TbLen.Text = "";
296
+                TbLen.Enabled = false;
297
+            }
298
+            else
299
+            {
300
+                TbLen.Enabled = true;
301
+            }
302
+        }
303
+
304
+        private void TbLen_KeyPress(object sender, KeyPressEventArgs e)
305
+        {
306
+            if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
307
+            {
308
+                e.Handled = true;
309
+            }
310
+        }
311
+
312
+        private void TbDv_TextChanged(object sender, EventArgs e)
313
+        {
314
+            LbDefaultV.Text = (TbDv.Text.Trim().Length / 2.0) + "";
315
+        }
316
+
317
+        private void TbUv_TextChanged(object sender, EventArgs e)
318
+        {
319
+            LbUserV.Text = (TbUv.Text.Trim().Length / 2.0) + "";
70 320
         }
71 321
     }
72 322
 }

+ 4 - 22
DotNettyFrom/form/ItemManagerForm.Designer.cs Просмотреть файл

@@ -28,10 +28,7 @@
28 28
         /// </summary>
29 29
         private void InitializeComponent()
30 30
         {
31
-            this.components = new System.ComponentModel.Container();
32 31
             this.dataGridViewItem = new System.Windows.Forms.DataGridView();
33
-            this.Context_Menu_ItemManger = new System.Windows.Forms.ContextMenuStrip(this.components);
34
-            this.MenuItem_Delete = new System.Windows.Forms.ToolStripMenuItem();
35 32
             this.BtnAddCmd = new System.Windows.Forms.Button();
36 33
             this.BtnDelSelectItem = new System.Windows.Forms.Button();
37 34
             this.BtnRefresh = new System.Windows.Forms.Button();
@@ -45,7 +42,6 @@
45 42
             this.BtnFind = new System.Windows.Forms.Button();
46 43
             this.RtbLogInfo = new System.Windows.Forms.RichTextBox();
47 44
             ((System.ComponentModel.ISupportInitialize)(this.dataGridViewItem)).BeginInit();
48
-            this.Context_Menu_ItemManger.SuspendLayout();
49 45
             this.SuspendLayout();
50 46
             // 
51 47
             // dataGridViewItem
@@ -55,31 +51,18 @@
55 51
             | System.Windows.Forms.AnchorStyles.Left) 
56 52
             | System.Windows.Forms.AnchorStyles.Right)));
57 53
             this.dataGridViewItem.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
58
-            this.dataGridViewItem.ContextMenuStrip = this.Context_Menu_ItemManger;
59 54
             this.dataGridViewItem.Location = new System.Drawing.Point(14, 158);
60 55
             this.dataGridViewItem.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
61 56
             this.dataGridViewItem.MultiSelect = false;
62 57
             this.dataGridViewItem.Name = "dataGridViewItem";
63 58
             this.dataGridViewItem.ReadOnly = true;
64 59
             this.dataGridViewItem.RowTemplate.Height = 23;
60
+            this.dataGridViewItem.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
65 61
             this.dataGridViewItem.Size = new System.Drawing.Size(1130, 554);
66 62
             this.dataGridViewItem.TabIndex = 0;
63
+            this.dataGridViewItem.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewItem_CellMouseClick);
67 64
             this.dataGridViewItem.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewItem_CellMouseDoubleClick);
68 65
             // 
69
-            // Context_Menu_ItemManger
70
-            // 
71
-            this.Context_Menu_ItemManger.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
72
-            this.MenuItem_Delete});
73
-            this.Context_Menu_ItemManger.Name = "Context_Menu_ItemManger";
74
-            this.Context_Menu_ItemManger.Size = new System.Drawing.Size(154, 26);
75
-            // 
76
-            // MenuItem_Delete
77
-            // 
78
-            this.MenuItem_Delete.Name = "MenuItem_Delete";
79
-            this.MenuItem_Delete.Size = new System.Drawing.Size(153, 22);
80
-            this.MenuItem_Delete.Text = "删除选中行(&D)";
81
-            this.MenuItem_Delete.Click += new System.EventHandler(this.MenuItem_Delete_Click);
82
-            // 
83 66
             // BtnAddCmd
84 67
             // 
85 68
             this.BtnAddCmd.Location = new System.Drawing.Point(12, 35);
@@ -142,6 +125,7 @@
142 125
             // 
143 126
             // CbFindType
144 127
             // 
128
+            this.CbFindType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
145 129
             this.CbFindType.FormattingEnabled = true;
146 130
             this.CbFindType.Items.AddRange(new object[] {
147 131
             "ID-10进制",
@@ -202,6 +186,7 @@
202 186
             // 
203 187
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
204 188
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
189
+            this.CancelButton = this.BtnClose;
205 190
             this.ClientSize = new System.Drawing.Size(1158, 729);
206 191
             this.Controls.Add(this.RtbLogInfo);
207 192
             this.Controls.Add(this.TBInputFind);
@@ -225,7 +210,6 @@
225 210
             this.Text = "ItemManagerForm";
226 211
             this.Load += new System.EventHandler(this.ItemManagerForm_Load);
227 212
             ((System.ComponentModel.ISupportInitialize)(this.dataGridViewItem)).EndInit();
228
-            this.Context_Menu_ItemManger.ResumeLayout(false);
229 213
             this.ResumeLayout(false);
230 214
             this.PerformLayout();
231 215
 
@@ -234,8 +218,6 @@
234 218
         #endregion
235 219
 
236 220
         private System.Windows.Forms.DataGridView dataGridViewItem;
237
-        private System.Windows.Forms.ContextMenuStrip Context_Menu_ItemManger;
238
-        private System.Windows.Forms.ToolStripMenuItem MenuItem_Delete;
239 221
         private System.Windows.Forms.Button BtnAddCmd;
240 222
         private System.Windows.Forms.Button BtnDelSelectItem;
241 223
         private System.Windows.Forms.Button BtnRefresh;

+ 129 - 23
DotNettyFrom/form/ItemManagerForm.cs Просмотреть файл

@@ -8,11 +8,14 @@ using System.Text;
8 8
 using System.Threading.Tasks;
9 9
 using System.Windows.Forms;
10 10
 using DotNettyFrom.db;
11
+using DotNettyFrom.excel;
11 12
 
12 13
 namespace DotNettyFrom.form
13 14
 {
14 15
     public partial class ItemManagerForm : Form
15 16
     {
17
+        private int _SelectIndex = -1;
18
+
16 19
         public ItemManagerForm()
17 20
         {
18 21
             InitializeComponent();
@@ -28,29 +31,15 @@ namespace DotNettyFrom.form
28 31
 
29 32
         #region 事件
30 33
 
31
-        private void MenuItem_Delete_Click(object sender, EventArgs e)
32
-        {
33
-        }
34
-
35 34
         private void dataGridViewItem_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
36 35
         {
37
-            int col = dataGridViewItem.ColumnCount;
38 36
             int row = dataGridViewItem.RowCount;
39 37
             int x = e.RowIndex;
40
-            int y = e.ColumnIndex;
41
-            if (x >= 0 && y >= 0 && x < row && y < col)
38
+            if (x >= 0 && x < row)
42 39
             {
43
-                int id = int.Parse(dataGridViewItem[0, x].Value + "");
44
-//                int index = int.Parse(dataGridViewItem[1, x].Value + "");
45
-
46
-                ItemEditorForm ief = new ItemEditorForm(id);
47
-                ief.ItemHandler += (action, message) =>
48
-                {
49
-                    Console.WriteLine("reload");
50
-//                    InfoEditorTip.Text = topmost;
51
-//                    dataGridView1.DataSource = AccessDbLoader.getInstance().reloadAccessDb().getDataTable();
52
-                };
53
-
40
+                object value = dataGridViewItem[0, x].Value;
41
+                ItemEditorForm ief = new ItemEditorForm(value.ToString());
42
+                ief.ItemHandler += Ief_ItemHandler;
54 43
                 ief.ShowDialog();
55 44
             }
56 45
         }
@@ -59,46 +48,163 @@ namespace DotNettyFrom.form
59 48
         private void BtnAddCmd_Click(object sender, EventArgs e)
60 49
         {
61 50
             ItemEditorForm ief = new ItemEditorForm();
62
-            ief.ItemHandler += (action, message) =>
63
-            {
64
-                //Conso
65
-            };
51
+            ief.ItemHandler += Ief_ItemHandler;
66 52
             ief.ShowDialog();
67 53
         }
68 54
 
69 55
         private void Ief_ItemHandler(int action, string message)
70 56
         {
71
-            throw new NotImplementedException();
57
+            RtbLogInfo.Text = message;
58
+            ReLoadDatatable();
72 59
         }
73 60
 
74 61
         private void BtnDelSelectItem_Click(object sender, EventArgs e)
75 62
         {
63
+            if (_SelectIndex >= 0)
64
+            {
65
+                int id = int.Parse(dataGridViewItem[0, _SelectIndex].Value + "");
66
+                string hex = dataGridViewItem[2, _SelectIndex].Value + "";
67
+                DialogResult dialogResult = MessageBox.Show("确定删除 Primary Key=" + id + " Hex=" + hex + "?", "提示",
68
+                    MessageBoxButtons.OKCancel,
69
+                    MessageBoxIcon.Warning);
70
+                if (dialogResult == DialogResult.OK)
71
+                {
72
+                    int byId = DbHelper.GetInstance().DeleteCmdById(id);
73
+                    if (byId > 0)
74
+                    {
75
+                        ReLoadDatatable();
76
+                        RtbLogInfo.Text = "删除成功";
77
+                    }
78
+                }
79
+            }
80
+            else
81
+            {
82
+                RtbLogInfo.Text = "请重新选中";
83
+            }
84
+        }
85
+
86
+        private void ReLoadDatatable()
87
+        {
88
+            DataTable dt = dataGridViewItem.DataSource as DataTable;
89
+            dt.Clear();
90
+            dt = DbHelper.GetInstance().SelectCmds();
91
+            dataGridViewItem.DataSource = dt;
76 92
         }
77 93
 
78 94
         private void BtnRefresh_Click(object sender, EventArgs e)
79 95
         {
96
+            DataTable dt = dataGridViewItem.DataSource as DataTable;
97
+            dt.Clear();
98
+            dt = DbHelper.GetInstance().SelectCmds();
99
+            dataGridViewItem.DataSource = dt;
80 100
         }
81 101
 
82 102
         private void BtnReset_Click(object sender, EventArgs e)
83 103
         {
104
+            int res = DbHelper.GetInstance().ResetUserData();
105
+
106
+            RtbLogInfo.Text = res > 0 ? "重置数据成功" : "重置失败";
107
+            ReLoadDatatable();
84 108
         }
85 109
 
86 110
         private void BtnImportExcel_Click(object sender, EventArgs e)
87 111
         {
112
+            OpenFileDialog openFileDialog = new OpenFileDialog();
113
+            openFileDialog.Filter = "Excel文件|*.xls;*.xlsx|所有文件|*.*";
114
+            openFileDialog.InitialDirectory = Application.StartupPath;
115
+            if (openFileDialog.ShowDialog() == DialogResult.OK)
116
+            {
117
+                List<WvBean> wvBeans = new ExcelHelper(openFileDialog.FileName, RtbLogInfo).LoadExcelFile()
118
+                    .GetExcelList();
119
+                InsertExcelList2DB(wvBeans);
120
+            }
121
+
122
+            this.DialogResult = DialogResult.None;
123
+        }
124
+
125
+        private void InsertExcelList2DB(List<WvBean> list)
126
+        {
127
+            for (var i = 0; i < list.Count; i++)
128
+            {
129
+                int res = DbHelper.GetInstance().InsertCmd(list[i]);
130
+                if (res <= 0)
131
+                {
132
+                    RtbLogInfo.Text += "插入失败" + list[i].ToString() + "\n";
133
+                }
134
+            }
135
+            ReLoadDatatable();
88 136
         }
89 137
 
90 138
         private void BtnClearAll_Click(object sender, EventArgs e)
91 139
         {
140
+            DialogResult dialogResult =
141
+                MessageBox.Show("确定要清空所有数据?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
142
+            if (dialogResult == DialogResult.OK)
143
+            {
144
+                //
145
+                DbHelper.GetInstance().DeleteAllFwData();
146
+                ReLoadDatatable();
147
+            }
92 148
         }
93 149
 
94 150
         private void BtnClose_Click(object sender, EventArgs e)
95 151
         {
152
+            this.Close();
96 153
         }
97 154
 
98 155
         private void BtnFind_Click(object sender, EventArgs e)
99 156
         {
157
+            string query = TBInputFind.Text.Trim();
158
+            if (query.Equals(""))
159
+            {
160
+                ReLoadDatatable();
161
+            }
162
+            else
163
+            {
164
+//                ID - 10进制
165
+//                ID - 16进制
166
+//                名字 - IDInfo
167
+//                描述 - Desp
168
+                int mType = CbFindType.SelectedIndex;
169
+                string sql = "";
170
+                switch (mType)
171
+                {
172
+                    case 0:
173
+                        sql = @"select* from fw where my_index = " + query;
174
+                        break;
175
+                    case 1:
176
+                        sql = @"select* from fw where MY_ID = '" + query + "'";
177
+                        break;
178
+                    case 2:
179
+                        sql = @"select* from fw where idInfo like '%" + query + "%'";
180
+                        break;
181
+                    case 3:
182
+                        sql = @"select* from fw where desp like '%" + query + "%'";
183
+                        break;
184
+                    default:
185
+                        ReLoadDatatable();
186
+                        return;
187
+                }
188
+                DataTable dt = dataGridViewItem.DataSource as DataTable;
189
+                dt.Clear();
190
+                dt = DbHelper.GetInstance().SelectCmds(sql);
191
+                dataGridViewItem.DataSource = dt;
192
+            }
100 193
         }
101 194
 
102 195
         #endregion
196
+
197
+        private void dataGridViewItem_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
198
+        {
199
+            if (e.Button == MouseButtons.Left)
200
+            {
201
+                int x = e.RowIndex;
202
+
203
+                if (x >= 0 && x < dataGridViewItem.RowCount)
204
+                {
205
+                    _SelectIndex = x;
206
+                }
207
+            }
208
+        }
103 209
     }
104 210
 }

+ 0 - 3
DotNettyFrom/form/ItemManagerForm.resx Просмотреть файл

@@ -117,7 +117,4 @@
117 117
   <resheader name="writer">
118 118
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119 119
   </resheader>
120
-  <metadata name="Context_Menu_ItemManger.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121
-    <value>17, 17</value>
122
-  </metadata>
123 120
 </root>

+ 2 - 2
DotNettyFrom/util/CmdUtil.cs Просмотреть файл

@@ -46,9 +46,9 @@ namespace DotNettyFrom.util
46 46
             return sb + str;
47 47
         }
48 48
 
49
-        public static string Des2Hex(int dec)
49
+        public static string Dec2Hex(int dec)
50 50
         {
51
-            return "";
51
+            return Convert.ToString(dec, 16);
52 52
         }
53 53
 
54 54