Browse Source

有BUG,只能输入16进制,只能输入数字和负号还有问题.

Kerry 8 years ago
parent
commit
3943b940f2

BIN
.vs/GWSocketClient/v15/.suo View File


+ 2 - 0
GWSocketClient/IdItemEditor.Designer.cs View File

@@ -87,6 +87,7 @@
87 87
             // 
88 88
             this.tbId.Location = new System.Drawing.Point(63, 55);
89 89
             this.tbId.Name = "tbId";
90
+            this.tbId.ReadOnly = true;
90 91
             this.tbId.Size = new System.Drawing.Size(836, 25);
91 92
             this.tbId.TabIndex = 1;
92 93
             // 
@@ -103,6 +104,7 @@
103 104
             this.tbLen.Name = "tbLen";
104 105
             this.tbLen.Size = new System.Drawing.Size(836, 25);
105 106
             this.tbLen.TabIndex = 3;
107
+            this.tbLen.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbLen_KeyPress);
106 108
             // 
107 109
             // tbInfo
108 110
             // 

+ 80 - 9
GWSocketClient/IdItemEditor.cs View File

@@ -44,6 +44,9 @@ namespace GWSocketClient
44 44
                 buttonSubmit.Text = "添加";
45 45
                 addOrUpdate = true;
46 46
             }
47
+
48
+            this.tbDv.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.hex_Valid_KeyPress);
49
+            this.tbUv.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.hex_Valid_KeyPress);
47 50
         }
48 51
 
49 52
         private void addModifyText()
@@ -97,9 +100,10 @@ namespace GWSocketClient
97 100
             string myIdString = tbId.Text.Trim();
98 101
             string lenString = tbLen.Text.Trim();
99 102
             string defalutValueString = tbDv.Text.Trim();
100
-
103
+            string userValueString = tbUv.Text.Trim();
101 104
             bool modeBool = checkBoxWrite.Checked || checkBoxRead.Checked;
102 105
 
106
+            #region ISNULL
103 107
 
104 108
             if (tbIndexString.Equals(""))
105 109
             {
@@ -129,10 +133,45 @@ namespace GWSocketClient
129 133
                 return;
130 134
             }
131 135
 
132
-            string userValueString = tbUv.Text.Trim();
136
+            #endregion
133 137
 
134
-            WvBean wb = new WvBean();
135 138
 
139
+            if (userValueString.Equals(""))
140
+            {
141
+                userValueString = defalutValueString;
142
+            }
143
+
144
+
145
+            if (lenString.Contains("-"))
146
+            {
147
+                if (defalutValueString.Length % 2 == 0)
148
+                {
149
+                    richTextBoxTip.Text = "默认值长度不是整数!!!defalutValueString.Length=" + (defalutValueString.Length / 2.0);
150
+                    return;
151
+                }
152
+                if (userValueString.Length % 2 == 0)
153
+                {
154
+                    richTextBoxTip.Text = "用户值长度不是整数!!!defalutValueString.Length=" + (userValueString.Length / 2.0);
155
+                    return;
156
+                }
157
+            }
158
+            else
159
+            {
160
+                int len = int.Parse(lenString);
161
+                if (defalutValueString.Length / 2 == len)
162
+                {
163
+                    richTextBoxTip.Text = "默认值长度不对.定义长度是=" + lenString + " ,你输入长度是=" +
164
+                                          (defalutValueString.Length / 2.0);
165
+                    return;
166
+                }
167
+                if (userValueString.Length / 2 == len)
168
+                {
169
+                    richTextBoxTip.Text = "默认值长度不对.定义长度是=" + lenString + " ,你输入长度是=" + (userValueString.Length / 2.0);
170
+                    return;
171
+                }
172
+            }
173
+
174
+            WvBean wb = new WvBean();
136 175
             wb.index = int.Parse(tbIndexString);
137 176
             wb.myId = myIdString;
138 177
             wb.idInfo = tbInfo.Text.Trim();
@@ -143,13 +182,7 @@ namespace GWSocketClient
143 182
 
144 183
             wb.mode = modeString;
145 184
             wb.desp = tbDesp.Text.Trim();
146
-
147 185
             wb.defalutValue = defalutValueString;
148
-
149
-            if (userValueString.Equals(""))
150
-            {
151
-                userValueString = defalutValueString;
152
-            }
153 186
             wb.userValue = userValueString;
154 187
             wb.remark = tbRemark.Text.Trim();
155 188
             int res = -1;
@@ -236,6 +269,44 @@ namespace GWSocketClient
236 269
             {
237 270
                 e.Handled = true;
238 271
             }
272
+            /*int ascii = (int) (e.KeyChar);
273
+            if ((ascii >= 48 && ascii <= 57) && ascii == 45)
274
+            {
275
+                e.Handled = true;
276
+            }*/
277
+        }
278
+
279
+
280
+        private void hex_Valid_KeyPress(object sender, KeyPressEventArgs e)
281
+        {
282
+            int ascii = (int) (e.KeyChar);
283
+            Console.WriteLine(e.KeyChar + ": " + ascii);
284
+
285
+            if ((ascii >= 48 && ascii <= 57) || e.KeyChar != 8)
286
+            {
287
+                e.Handled = true;
288
+            }
289
+            else if (ascii >= 65 && ascii <= 70)
290
+            {
291
+                e.Handled = true;
292
+            }
293
+            else if (ascii >= 97 && ascii <= 102)
294
+            {
295
+                e.Handled = true;
296
+            }
297
+        }
298
+
299
+        private void tbLen_KeyPress(object sender, KeyPressEventArgs e)
300
+        {
301
+            int ascii = (int) (e.KeyChar);
302
+            if (ascii >= 48 && ascii <= 57)
303
+            {
304
+                e.Handled = false;
305
+            }
306
+            else if (ascii == 45)
307
+            {
308
+                e.Handled = true;
309
+            }
239 310
         }
240 311
     }
241 312
 }

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