/
UtilModel.cs
1297 lines (1240 loc) · 44.3 KB
/
UtilModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.Collections;
using System.Data;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.NetworkInformation;
using System.IO;
using System.Xml;
using LitJson;
namespace UtilModel
{
public class myUtil
{
static public string m_strCnn = "";
static public string m_strCnnFile = "";
static public string ftpServerIP = "";
static public string ftpLogin = "";
static public string ftpPassword = "";
static public string ftpRootPath = "";
static public bool isLong(string sInput, out long iRet)
{
bool bRet = true;
iRet = 0;
try
{
iRet = Convert.ToInt32(sInput);
}
catch (System.Exception)
{
bRet = false;
}
return bRet;
}
static public bool isDouble(string sInput, out double dRet)
{
bool bRet = true;
dRet = 0;
try
{
dRet = Convert.ToDouble(sInput);
}
catch (System.Exception)
{
bRet = false;
}
return bRet;
}
static public bool isInteger(string sInput, out int iRet)
{
bool bRet = true;
iRet = 0;
try
{
iRet = Convert.ToInt32(sInput);
}
catch (System.Exception)
{
bRet = false;
}
return bRet;
}
static public double GetValue(string sInput)
{
double dVal;
isNumeric(sInput, out dVal);
return dVal;
}
/// <summary>
/// 字符串是否在表内
/// </summary>
/// <param name="lst">表</param>
/// <param name="sText">字符串</param>
/// <param name="ignoreCase">是否忽略大小写</param>
/// <returns>true/false</returns>
static public bool isInList(List<string> lst, string sText, bool ignoreCase)
{
int i;
bool bIn = false;
if (lst != null)
{
for (i = 0; i < lst.Count; i++)
{
if (string.Compare(sText, lst[i], ignoreCase) == 0)
{
bIn = true;
break;
}
}
}
return bIn;
}
/// <summary>
/// 拆分特定格式字符串
/// sInput="T@1"
/// getId(sInput,out sType)=1; sType返回"T"
/// </summary>
/// <param name="sInput"></param>
/// <param name="sType"></param>
/// <returns></returns>
static public long getId(string sInput, out string sType)
{
long iId = 0;
sType = "";
int iIndex = sInput.IndexOf('@');
if (iIndex > 0)
{
string s = sInput.Substring(iIndex + 1);
sType = sInput.Substring(0, iIndex);
try
{
iId = Convert.ToInt32(s);
}
catch (System.Exception)
{
iId = 0;
sType = "";
}
}
return iId;
}
static public DialogResult ExclamationMessage(string sText, string sTitle)
{
return MessageBox.Show(sText, sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
static public DialogResult QuestionMessage(string sText, string sTitle)
{
return MessageBox.Show(sText, sTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
static public DialogResult InformationMessage(string sText, string sTitle)
{
return MessageBox.Show(sText, sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
static public double atof(string sInput)
{
double dVal = 0;
isNumeric(sInput, out dVal);
return dVal;
}
static public int atoi(string sInput)
{
double dVal = 0;
isNumeric(sInput, out dVal);
return (int)dVal;
}
static public bool isNumeric(string sInput, out double dResult)
{
dResult = 0;
bool bRet = false;
try
{
dResult = Convert.ToDouble(sInput);
bRet = true;
}
catch (System.Exception) { }
return bRet;
}
static public bool GetNumberInString(string sInput, out double dResult)
{
bool bRet;
double dVal;
dResult = 0;
bRet = isNumeric(sInput, out dVal);
if (bRet)
{
dResult = dVal;
return bRet;
}
else
{
string sNum = "0123456789.+-",sVal="";
char s;
int i, iflag = 0;
for (i = 0; i < sInput.Length; i++)
{
s = sInput[i];
if (sNum.IndexOf(s) >= 0)
{
if (s == '.')
{
if (sVal.Length > 0) { sVal += s; }
else
{
if (iflag == 1) { break; }
}
}
else
{
sVal += s;
iflag = 1;
}
}
else
{
if (iflag == 1) { break; }
}
}
if (sVal.Length > 0) { bRet = isNumeric(sVal, out dResult); }
}
return bRet;
}
static public string DeleteLastZero(string sInput)
{
string sRet = sInput;
if (sRet.IndexOf('.') > 0)
{
int iLen = sRet.Length;
char s = sRet[iLen - 1];
while (s == '0' || s=='.')
{
sRet = sRet.Substring(0, iLen - 1);
if (s == '.') { break; }
iLen = sRet.Length;
s = sRet[iLen - 1];
}
}
return sRet;
}
static public bool isDateTime(string sInput,out DateTime deResult)
{
deResult = DateTime.MinValue;
bool bRet = false;
try
{
deResult = Convert.ToDateTime(sInput);
bRet = true;
}
catch (System.Exception) {}
return bRet;
}
static public string m_InvalidChar = "*@|\\/\"#%^~`";
/// <summary>
/// 判断字符串中是否包含字符"*@|\\/\"#%^~`"
/// </summary>
/// <param name="sInput"></param>
/// <returns></returns>
static public bool CheckChar(string sInput)
{
int i;
bool bRet = true;
for (i = 0; i < m_InvalidChar.Length; i++)
{
if (sInput.IndexOf(m_InvalidChar[i]) >= 0)
{
bRet = false;
}
}
return bRet;
}
/// <summary>
/// 运行一段JavaScript代码
/// </summary>
/// <param name="sCode">传入代码</param>
/// <param name="sResult">返回内容</param>
/// <returns>0执行正确/-1执行错误</returns>
static public int JScriptEval(string sCode, out string sResult)
{
int nRet = 0;
sResult = "";
try
{
Microsoft.JScript.Vsa.VsaEngine vEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
sResult = Microsoft.JScript.Eval.JScriptEvaluate(sCode, vEngine).ToString();
}
catch (System.Exception ex)
{
nRet = -1;
sResult = ex.Message;
}
return nRet;
}
/// <summary>
/// 分割字符串"[{...{..}},{....}...]"为数组"{...{..}}","{....}"...
/// 允许嵌套
/// </summary>
/// <param name="sInput"></param>
/// <returns></returns>
static public List<string> SpliteListItemData(string sInput)
{
List<string> ayItem = new List<string>();
string sItem;
int i, iFlag = 0;
if (sInput.Length == 0) { return ayItem; }
if (sInput[0] == '[')
{
sInput = sInput.Substring(1, sInput.Length - 2);
}
i = 0;
try
{
while (i < sInput.Length)
{
if (sInput[i] == '{') { iFlag++; i++; }
else if (sInput[i] == '}')
{
iFlag--;
if (iFlag == 0)
{
sItem = sInput.Substring(0, i + 1);
ayItem.Add(sItem);
if (i < sInput.Length - 1)
{
sInput = sInput.Substring(i + 1);
}
else { break; }
if (sInput.Length > 0 && sInput[0] == ',')
{
sInput = sInput.Substring(1, sInput.Length - 1);
}
i = 0;
}
else { i++; }
}
else { i++; }
}
if (sInput.Length > 0)
{
ayItem.Add(sInput);
}
}
catch (System.Exception ex)
{
sItem = ex.Message;
}
return ayItem;
}
/// <summary>
/// 提取字符串中若干{}内的内容
/// </summary>
/// <param name="sInput"></param>
/// <returns></returns>
static public List<string> SpliteListData(string sInput)
{
List<string> ayList = new List<string>();
int[] iPos = new int[2];
string sData, sList;
sList = sInput;
iPos[0] = sList.IndexOf('{');
iPos[1] = sList.IndexOf('}');
while (iPos[0] >= 0 && iPos[1] > iPos[0])
{
sData = sList.Substring(iPos[0] + 1, iPos[1] - iPos[0] - 1);
ayList.Add(sData);
if (sList.Length > iPos[1])
{
sList = sList.Substring(iPos[1] + 1);
iPos[0] = sList.IndexOf('{');
iPos[1] = sList.IndexOf('}');
}
else { break; }
}
return ayList;
}
/// <summary>
/// 返回“年月日小时分秒_4位随机数”
/// </summary>
/// <returns></returns>
static public string getRandIdByTime()
{
string sId, sVal;
int iVal;
DateTime cur = DateTime.Now;
sId = cur.Year.ToString();
iVal = cur.Month;
if (iVal < 10) { sId += "0" + iVal.ToString(); }
else { sId += iVal.ToString(); }
iVal = cur.Day;
if (iVal < 10) { sId += "0" + iVal.ToString(); }
else { sId += iVal.ToString(); }
iVal = cur.Hour;
if (iVal < 10) { sId += "0" + iVal.ToString(); }
else { sId += iVal.ToString(); }
iVal = cur.Minute;
if (iVal < 10) { sId += "0" + iVal.ToString(); }
else { sId += iVal.ToString(); }
iVal = cur.Second;
if (iVal < 10) { sId += "0" + iVal.ToString(); }
else { sId += iVal.ToString(); }
iVal = cur.Millisecond;
sVal = iVal.ToString();
while (sVal.Length < 3)
{
sVal = "0" + sVal;
}
sVal = "_" + sVal;
sId += sVal;
Random autoRand = new Random(iVal);
sVal = autoRand.Next(10000).ToString();
while (sVal.Length < 4)
{
sVal = "0" + sVal;
}
sVal = "_" + sVal;
sId += sVal;
return sId;
}
/// <summary>
/// 按空格分解字符串
/// </summary>
/// <param name="sInput"></param>
/// <returns></returns>
static public List<string> SpliteRowData(string sInput)
{
List<string> ayRet = new List<string>();
int i;
string sText = "", str;
for (i = 0; i < sInput.Length; i++)
{
str = sInput.Substring(i, 1);
if (str == " ")
{
sText = sText.Trim();
if (sText.Length > 0)
{
ayRet.Add(sText);
}
sText = "";
}
else
{
sText = sText + str;
}
}
sText = sText.Trim();
if (sText.Length > 0)
{
ayRet.Add(sText);
}
return ayRet;
}
static public List<string> SpliteString(string sInput, string sSplitWord)
{
List<string> ayRet = new List<string>();
if (sInput.IndexOf(sSplitWord) < 0)
{
ayRet.Add(sInput);
}
else
{
int i, iLen = sSplitWord.Length;
string sText;
i = sInput.IndexOf(sSplitWord);
while (i >= 0)
{
if (i > 0)
{
sText = sInput.Substring(0, i);
ayRet.Add(sText);
}
sInput = sInput.Substring(i + iLen);
i = sInput.IndexOf(sSplitWord);
}
if (sInput.Length > 0) { ayRet.Add(sInput); }
}
return ayRet;
}
static public void getAllChildContrl(System.Windows.Forms.Control ctrlRoot, ref List<System.Windows.Forms.Control> ayChild)
{
string sTag;
foreach (System.Windows.Forms.Control ctrl in ctrlRoot.Controls)
{
if (ctrl.Tag != null)
{
sTag = ctrl.Tag.ToString().Trim();
if (sTag.Length > 0)
{
ayChild.Add(ctrl);
}
}
if (ctrl.Controls.Count > 0)
{
getAllChildContrl(ctrl, ref ayChild);
}
}
}
static public List<System.Windows.Forms.Control> getAllFormControl(System.Windows.Forms.Form theForm)
{
string sTag;
int i;
System.Windows.Forms.Control ctrlChild;
List<System.Windows.Forms.Control> ayRet = new List<Control>();
foreach (System.Windows.Forms.Control ctrl in theForm.Controls)
{
if (ctrl.Tag != null)
{
sTag = ctrl.Tag.ToString().Trim();
if (sTag.Length > 0)
{
ayRet.Add(ctrl);
}
}
if (ctrl.Controls.Count > 0)
{
List<System.Windows.Forms.Control> ayChild = new List<Control>();
getAllChildContrl(ctrl, ref ayChild);
for (i = 0; i < ayChild.Count; i++)
{
ctrlChild = ayChild[i];
ayRet.Add(ctrlChild);
}
}
}
return ayRet;
}
static public void ExchangeItem(ListView lstTable,int iIndex1,int iIndex2)
{
ListViewItem itm1 = lstTable.Items[iIndex1];
ListViewItem itm2 = lstTable.Items[iIndex2];
int i;
string[] sText = new string[2];
string[] sTag = new string[2];
System.Drawing.Color iColor1=itm1.ForeColor;
System.Drawing.Color iColor2=itm2.ForeColor;
System.Drawing.Color iBColor1=itm1.BackColor;
System.Drawing.Color iBColor2=itm2.BackColor;
sText[0] = itm1.Text;
sText[1] = itm2.Text;
sTag[0] = itm1.Tag.ToString();
sTag[1] = itm2.Tag.ToString();
itm1.Text = sText[1];
itm2.Text = sText[0];
itm1.Tag = sTag[1];
itm2.Tag = sTag[0];
itm1.ForeColor=iColor2;
itm2.ForeColor=iColor1;
itm1.BackColor=iBColor2;
itm2.BackColor=iBColor1;
for (i = 1; i < lstTable.Columns.Count; i++)
{
sText[0] = itm1.SubItems[i].Text;
sText[1] = itm2.SubItems[i].Text;
itm1.SubItems[i].Text = sText[1];
itm2.SubItems[i].Text = sText[0];
}
itm2.Selected = true;
itm2.Focused = true;
itm1.Selected = false;
itm1.Focused = false;
itm2.EnsureVisible();
}
static public bool fequ(double dVal1,double dVal2)
{
bool bRet = false;
if (Math.Abs(dVal1 - dVal2) < 0.000000001) { bRet = true; }
return bRet;
}
static public bool IsIPConnect(string sIp)
{
bool bRet = true;
Ping cp = new Ping();
PingReply pr;
pr = cp.Send(sIp);
if (pr.Status != IPStatus.Success)
{
bRet = false;
}
return bRet;
}
static public void ExchangeObject(ref object obj1, ref object obj2)
{
object obj = obj1;
obj1 = obj2;
obj2 = obj;
}
static private bool IsDataRowInOrder(DataRow dr1,DataRow dr2,List<string> aySortCol,List<int> aySortType)
{
bool bRet = true;
int i,iSortType,iCompare;
string sCol;
string[] sCell = new string[2];
for (i=0;i<aySortCol.Count && i<aySortType.Count;i++)
{
sCol = aySortCol[i];
iSortType = aySortType[i];
sCell[0] = dr1[sCol].ToString();
sCell[1] = dr2[sCol].ToString();
iCompare=string.Compare(sCell[0],sCell[1],true);
if (iSortType==1) {
//升序
if (iCompare<0) {
bRet = true;
break;
}
else if (iCompare>0) {
bRet = false;
break;
}
}
else if (iSortType==2) {
//降序
if (iCompare < 0)
{
bRet = false;
break;
}
else if (iCompare > 0)
{
bRet = true;
break;
}
}
else { break; }
}
return bRet;
}
static public void ExchangeDaraRow(ref DataRow dr1,ref DataRow dr2)
{
int i;
string[] sVal = new string[2];
for (i=0;i<dr1.Table.Columns.Count && i<dr2.Table.Columns.Count;i++) {
sVal[0] = dr1[i].ToString();
sVal[1] = dr2[i].ToString();
dr1[i] = sVal[1];
dr2[i] = sVal[0];
}
}
/// <summary>
/// 排序表
/// </summary>
/// <param name="tblData">表</param>
/// <param name="aySortCol">排序列</param>
/// <param name="aySortType">排序方式,1升序/2降序</param>
static public void SortDataTable(ref DataTable tblData,List<string> aySortCol,List<int> aySortType)
{
bool bLoop=true;
int n;
DataRow[] dr=new DataRow[2];
while (bLoop) {
bLoop = false;
for (n=0;n<tblData.Rows.Count-1;n++) {
dr[0] = tblData.Rows[n];
dr[1] = tblData.Rows[n + 1];
bLoop = !IsDataRowInOrder(dr[0], dr[1], aySortCol, aySortType);
if (bLoop) {
ExchangeDaraRow(ref dr[0], ref dr[1]);
break;
}
}
}
}
/// <summary>
/// 为ligerComboBox生成data表达式
/// </summary>
/// <param name="varData"></param>
/// <param name="ayText"></param>
/// <param name="ayId"></param>
/// <returns></returns>
static public string ToJScriptData(string varData,List<string> ayText, List<string> ayId)
{
string sScript = "";
if (ayText != null)
{
int i;
string sText, sId,sItem;
sScript = "var " + varData + "=[";
for (i = 0; i < ayText.Count; i++)
{
sText = sId = ayText[i];
if (ayId != null)
{
if (i < ayId.Count) { sId = ayId[i]; }
}
sItem = "{text:'" + sText + "',id:'" + sId + "'}";
if (i == 0)
{
sScript += sItem;
}
else
{
sScript += "," + sItem;
}
}
sScript += "];";
}
return sScript;
}
///<summary>
///得到随机字符.
///</summary>
///<param name="intLength">Length of the int.</param>
///<param name="booNumber">if set to <c>true</c> [boo number].</param>
///<param name="booSign">if set to <c>true</c> [boo sign].</param>
///<param name="booSmallword">if set to <c>true</c> [boo smallword].</param>
///<param name="booBigword">if set to <c>true</c> [boo bigword].</param>
///<returns></returns>
static public string getRandomizer(int intLength, bool booNumber, bool booSign, bool booSmallword, bool booBigword)
{
//定义
Random ranA = new Random();
int intResultRound = 0;
int intA = 0;
string strB = "";
while (intResultRound < intLength)
{
//生成随机数A,表示生成类型
//1=数字,2=符号,3=小写字母,4=大写字母
intA = ranA.Next(1, 5);
//如果随机数A=1,则运行生成数字
//生成随机数A,范围在0-10
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 1 && booNumber)
{
intA = ranA.Next(0, 10);
strB = intA.ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果随机数A=2,则运行生成符号
//生成随机数A,表示生成值域
//1:33-47值域,2:58-64值域,3:91-96值域,4:123-126值域
if (intA == 2 && booSign == true)
{
intA = ranA.Next(1, 5);
//如果A=1
//生成随机数A,33-47的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 1)
{
intA = ranA.Next(33, 48);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果A=2
//生成随机数A,58-64的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 2)
{
intA = ranA.Next(58, 65);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果A=3
//生成随机数A,91-96的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 3)
{
intA = ranA.Next(91, 97);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果A=4
//生成随机数A,123-126的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 4)
{
intA = ranA.Next(123, 127);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
}
//如果随机数A=3,则运行生成小写字母
//生成随机数A,范围在97-122
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 3 && booSmallword == true)
{
intA = ranA.Next(97, 123);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果随机数A=4,则运行生成大写字母
//生成随机数A,范围在65-90
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 4 && booBigword == true)
{
intA = ranA.Next(65, 89);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
}
return strB;
}
//随机字符串生成器的主要功能如下:
//1、支持自定义字符串长度
//2、支持自定义是否包含数字
//3、支持自定义是否包含小写字母
//4、支持自定义是否包含大写字母
//5、支持自定义是否包含特殊符号
//6、支持自定义字符集
///<summary>
///生成随机字符串
///</summary>
///<param name="length">目标字符串的长度</param>
///<param name="useNum">是否包含数字,1=包含,默认为包含</param>
///<param name="useLow">是否包含小写字母,1=包含,默认为包含</param>
///<param name="useUpp">是否包含大写字母,1=包含,默认为包含</param>
///<param name="useSpe">是否包含特殊字符,1=包含,默认为不包含</param>
///<param name="custom">要包含的自定义字符,直接输入要包含的字符列表</param>
///<returns>指定长度的随机字符串</returns>
static public string GetRnd(int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom)
{
byte[] b = new byte[4];
new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
Random r = new Random(BitConverter.ToInt32(b, 0));
string s = null, str = custom;
if (useNum == true) { str += "0123456789"; }
if (useLow == true) { str += "abcdefghijklmnopqrstuvwxyz"; }
if (useUpp == true) { str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
if (useSpe == true) { str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
for (int i = 0; i < length; i++)
{
s += str.Substring(r.Next(0, str.Length - 1), 1);
}
return s;
}
static public int strcmpi(string str1, string str2)
{
return string.Compare(str1, str2, true);
}
static public void SlideToGif(string sFileSld, string sFileGif, int iWidth, int iHeight)
{
System.IO.MemoryStream ms;
System.Drawing.Bitmap bitmap;
if (File.Exists(sFileSld))
{
BitmapSlide bmpSlide = new BitmapSlide();
bmpSlide.m_Background = System.Drawing.Color.Black;
bmpSlide.ReadSlide(sFileSld);
bmpSlide.reDrawSlide(iWidth, iHeight, out bitmap);
ms = new System.IO.MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
File.WriteAllBytes(sFileGif, ms.ToArray());
}
}
static public DialogResult InputMessageBox(string sCaption, ref string sResult)
{
dlgInput dlg = new dlgInput();
dlg.m_Caption = sCaption;
dlg.m_Text = sResult;
DialogResult nRet = dlg.ShowDialog();
if (nRet == DialogResult.OK)
{
sResult = dlg.m_Text;
}
return nRet;
}
static public string GetJsonData(JsonData data, string sKey, string sDefaultValue)
{
string sResult=sDefaultValue;
try
{
sResult = data[sKey].ToString();
}
catch (System.Exception ex)
{
}
return sResult;
}
static public void DrawImgBorder(System.Windows.Forms.PictureBox img, System.Drawing.Color cBorderColor, int iBorderWidth)
{
Graphics g;
Pen myPen = new Pen(cBorderColor, iBorderWidth);
Point pt;
Size sz;
Single x1, y1;
pt = img.Location;
sz = img.Size;
x1 = iBorderWidth / 2;
y1 = iBorderWidth / 2;
g = img.CreateGraphics();
g.DrawRectangle(myPen, x1, y1, sz.Width - iBorderWidth, sz.Height - iBorderWidth);
}
static public void GetCombSelectList(System.Windows.Forms.ComboBox cmb, ref List<string> ayList)
{
string sText;
int i;
if (cmb.SelectedIndex < 0)
{
sText = cmb.Text;
if (ayList.IndexOf(sText) < 0) { ayList.Add(sText); }
}
for (i = 0; i < cmb.Items.Count; i++)
{
sText = cmb.Items[i].ToString();
if (ayList.IndexOf(sText) < 0) { ayList.Add(sText); }
}
}
static public string doubletoDu(double dVal)
{
string sResult, sTmp;
double du, dd, dm, ds;
du = dVal * 180 / Math.PI;
dm = 60 * (60 * (du - Math.Floor(du)) - Math.Floor(60 * (du - Math.Floor(du)))); //秒
ds = Math.Floor(60 * (du - Math.Floor(du))); //分
dd = Math.Floor(du); //度
if (fequ(dm, 60))
{
dm = 0;
ds = ds + 1;
if (fequ(ds, 60))
{
ds = 0;
dd = dd + 1;
}
}
sTmp=string.Format("{0:0}°", dd);
sResult = sTmp;
if ((!fequ(ds, 0)) && (!fequ(dm, 0)))
{
sTmp=string.Format("{0:#}′{1:#}″", ds, dm);
}
else if ((fequ(ds, 0)) && (!fequ(dm, 0)))
{
sTmp=string.Format("{0:#}′{1:#}″", ds, dm);
}
else if ((!fequ(ds, 0)) && (fequ(dm, 0)))
{
sTmp=string.Format("{0:#}′", ds);
}
else { sTmp = ""; }
sResult = sResult + sTmp;
return sResult;
}
static public int GetTextDataFromClipboard(out string sData, out string sError)
{
int nRet = 1;
IDataObject data = new DataObject();
sError = "";
sData = "";
try
{
data = System.Windows.Forms.Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Text))
{
sData = (string)data.GetData(DataFormats.Text);
nRet = 0;
}
}
catch (System.Exception ex)
{
sError = ex.Message;
}
return nRet;
}
static public int SetTextDataToClipboard(string sData, out string sError)
{
int nRet = 1;
sError = "";
try
{
Type myType = sData.GetType();