-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathucommon.pas
More file actions
1756 lines (1553 loc) · 41.6 KB
/
ucommon.pas
File metadata and controls
1756 lines (1553 loc) · 41.6 KB
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
{
功能:Delphi 通用函数库
作者:孙威威
}
unit uCommon;
interface
uses
DB, ADODB,comobj,Dialogs,Variants,inifiles,Forms,windows,shellapi,
sysutils,classes,registry,Tlhelp32;
const
sTplConnectionString='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'+'Jet OLEDB:Database Password=%s;';
type
//自定义的记录集
getrs=class(tObject)
private
public
eof:boolean;
sql:string;
rs:tAdoQuery;
ds:tDataSource;
constructor Create(sql:string;ado_conn:tadoconnection=nil);
destructor Destroy;
function getRecordCount:integer;
property recordCount:integer read getRecordCount;
procedure addnew;
procedure update;
procedure delete;
function value(k:string):string;overload;
function v(k:string):string;overload;
function vdbl(k:string):Double;overload;
function vint(k:string):Integer;overload;
function value(i:integer):string;overload;
procedure field(k:string;v:string);overload;
procedure field(k:string;v:Integer);overload;
procedure field(k:string;v:Double);overload;
procedure next;
procedure close;
end;
//初始化
procedure init;
//存取配置参数(在数据库中)
function reg(key:string;v:string=''):string;
procedure speak(s: string);
function year(dt:tdatetime):integer;
//读写INI配置文件
function ini(key:string;v:string=''):string;
//弹出信息提示框
procedure msgbox(msg:variant);
function GetPart(StrSource,StrBegin,StrEnd:string):string;
//替换字符串
function replace(a,b,c:string):string;
//弹出确认提示框
function confirm(str:string):boolean;
procedure msgerr(str:string);
//过滤字符串为安全字符
function sqlstr(s:string):string;
function py(Value: string): string;
//对tStrings进行排序
procedure sortStrings(stringList:TStrings);
function sqlValue(sql:string;ado_conn:TAdoConnection=nil):string;
function sqlValueCache(sql:string;ado_conn:TAdoConnection=nil):string;
function sv(sql:string;ado_conn:TAdoConnection=nil):string;
function svc(sql:string;ado_conn:TAdoConnection=nil):string;
procedure q(sql:string;ado_conn:TAdoConnection=nil);
procedure q_(sql:string;ado_conn:TAdoConnection=nil);
function num2min_sec_dot(sec:integer):string;
function getSexStr(s:string):string;
function getNjNum(s: string): string;
function getNjStr(s: string): string;
//字符串转化为整数
function cint(str:string):integer;
function isnum(str:string):boolean;
function isint(str:string):boolean;
function cstr(s:integer):string; overload;
function cstr(s:double): string; overload;
function pct(a,b:string):string;overload;
function pct(a,b:double):string;overload;
function pct(a,b:integer):string;overload;
function num2gb(i:integer): string;
function instr(a,b:string):boolean;
//字符串转化为浮点数
function cdbl(str:string):double;
//增加到自动运行(注册表)
function RegAddToRun(Name,Value:string):Boolean;
//取得系统内串口
function GetSysCom():tstrings;
//读文本文件
function readTextFile(fileName:string):tStrings;
//写文本文件
procedure writeTextFile(content:string;filename:string);
//写日志
procedure log(strFile:string;strLog:string);
function wait(MaxWaitTime: Cardinal): Boolean;
//解密字串
//把字符串Str编码为Base64字符串返回
function StrToBase64(const Str: string): string;
//把Base64字符串解码为字符串返回
function Base64ToStr(const Base64: string): string;
function num2min_sec(ss:string):string;
function jm(ss:string):string;
{*******Base64内部调用********}
//将SourceSize长度的源Source编码为Base64字符串返回
function Base64Encode(const Source; SourceSize: Integer): string; overload;
//将Source从StartPos开始的Size长度的内容源编码为Base64,写入流Dest。Size=0文件结束
procedure Base64Encode(Source, Dest: TStream; StartPos: Int64 = 0; Size: Int64 = 0); overload;
//按给定的编码源Source和长度Size计算并返回解码缓冲区实际所需长度
function Base64DecodeBufSize(const Source; Size: Integer): Integer;
//将Base64编码字符串Source解码存放在Buf中,返回解码长度
function Base64Decode(const Source: string; var Buf): Integer; overload;
//将Source从StartPos开始的Size长度的Base64编码内容解码,写入流Dest。Size=0文件结束
procedure Base64Decode(Source, Dest: TStream; StartPos: Int64 = 0; Size: Int64 = 0); overload;
{*******Base64内部调用********}
function StrEncode(ss: string): string;
function StrDecode(ss: string): string;
function RunDosCommand(Command: string): string;
var
cn:tAdoConnection;
path:string;
const py__: array[216..247] of string = (
{216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + 'QMBSGZSCYJSYYZPG' +
{216}'KBZGYCYWYKGKLJSW' + 'KPJQHYZ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BBLBLCZQR' + 'PPXJCGLZCSHLTOLJ' + 'NMDDDLNGKAQHQH',
{242}'JHYKHEZNMSHRP QQ' + 'JCHGMFPRXHJGDYCH' + 'GHLYRZQLCYQJNZSQ' +
{242}'TKQJYMSZSWLCFQQQ' + 'XYFGGYPTQWLMCRNF' + 'KKFSYYLQBMQAMM',
{243}'MYXCTPSHCPTXXZZS' + 'MPHPSHMCLMLDQFYQ' + 'XSZYJDJJZZHQPDSZ' +
{243}'GLSTJBCKBXYQZJSG' + 'PSXQZQZRQTBDKYXZ' + 'KHHGFLBCSMDLDG',
{244}'DZDBLZYYCXNNCSYB' + 'ZBFGLZZXSWMSCCMQ' + 'NJQSBDQSJTXXMBLT' +
{244}'XZCLZSHZCXRQJGJY' + 'LXZFJPHYXZQQYDFQ' + 'JJLZZNZJCDGZYG',
{245}'CTXMZYSCTLKPHTXH' + 'TLBJXJLXSCDQXCBB' + 'TJFQZFSLTJBTKQBX' +
{245}'XJJLJCHCZDBZJDCZ' + 'JDCPRNPQCJPFCZLC' + 'LZXBDMXMPHJSGZ',
{246}'GSZZQLYLWTJPFSYA' + 'SMCJBTZYYCWMYTCS' + 'JJLQCQLWZMALBXYF' +
{246}'BPNLSFHTGJWEJJXX' + 'GLLJSTGSHJQLZFKC' + 'GNNDSZFDEQFHBS',
{247}'AQTGYLBXMMYGSZLD' + 'YDQMJJRGBJTKGDHG' + 'KBLQKBDMBYLXWCXY' +
{247}'TTYBKMRTJZXQJBHL' + 'MHMJJZMQASLDCYXY' + 'QDLQCAFYWYXQHZ');
function f0j1(a: double): double;
function round45(dd: double): double;
procedure log_sys(s: string);
function g(sql: string;ado_conn:TAdoConnection=nil): getrs;
function len(s: string): integer;
Function getHDDSN(): string;
function getSysSN():string;
function getSYSSerial(s:string):string;
function m2s(vm:Double):integer;
function s2m(vs:integer):double;
function KillTask(ExeFileName: string): integer;
function isDate(str: string): boolean;
procedure showInfoWin(str: string);
function md5_(s: string): string;
procedure showFrm(strFormName: string);
function CompactDatabase(AFileName,APassWord:string):boolean;
procedure ShowPhpRpt(strRptName:string);
procedure check1024;
function leftstr(s:string;i:integer):string;
function replace_common(s: string): string;
function mz(n: integer): string;
procedure add_taskbar_menu;
function cdate(sTime:String):TDateTime;
implementation
const
Base64_Chars: array[0..63] of char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
type
Base64Proc = function(const Source; var Buf; SourceSize: Integer): Integer;
function jm(ss:string):string;
var
i:integer;
begin
for i:=1 to length(ss) do ss[i]:=chr((ord(ss[i]) xor i)-133);
result:=ss;
end;
function RunDosCommand(Command: string): string;
var
hReadPipe: THandle;
hWritePipe: THandle;
SI: TStartUpInfo;
PI: TProcessInformation;
SA: TSecurityAttributes;
// SD : TSecurityDescriptor;
BytesRead: DWORD;
Dest: array[0..1023] of char;
CmdLine: array[0..512] of char;
TmpList: TStringList;
Avail, ExitCode, wrResult: DWORD;
osVer: TOSVERSIONINFO;
tmpstr: AnsiString;
begin
osVer.dwOSVersionInfoSize := Sizeof(TOSVERSIONINFO);
GetVersionEX(osVer);
if osVer.dwPlatformId = VER_PLATFORM_WIN32_NT then
begin
// InitializeSecurityDescriptor(@SD, SECURITY_DESCRIPTOR_REVISION);
// SetSecurityDescriptorDacl(@SD, True, nil, False);
SA.nLength := SizeOf(SA);
SA.lpSecurityDescriptor := nil; //@SD;
SA.bInheritHandle := True;
CreatePipe(hReadPipe, hWritePipe, @SA, 0);
end
else
CreatePipe(hReadPipe, hWritePipe, nil, 1024);
try
FillChar(SI, SizeOf(SI), 0);
SI.cb := SizeOf(TStartUpInfo);
SI.wShowWindow := SW_HIDE;
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.dwFlags := SI.dwFlags or STARTF_USESTDHANDLES;
SI.hStdOutput := hWritePipe;
SI.hStdError := hWritePipe;
StrPCopy(CmdLine, Command);
if CreateProcess(nil, CmdLine, nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil, SI, PI) then
begin
ExitCode := 0;
while ExitCode = 0 do
begin
wrResult := WaitForSingleObject(PI.hProcess, 500);
if PeekNamedPipe(hReadPipe, @Dest[0], 1024, @Avail, nil, nil) then
begin
if Avail > 0 then
begin
TmpList := TStringList.Create;
try
FillChar(Dest, SizeOf(Dest), 0);
ReadFile(hReadPipe, Dest[0], Avail, BytesRead, nil);
TmpStr := Copy(Dest, 0, BytesRead - 1);
TmpList.Text := TmpStr;
Result := tmpstr;
finally
TmpList.Free;
end;
end;
end;
if wrResult <> WAIT_TIMEOUT then ExitCode := 1;
end;
GetExitCodeProcess(PI.hProcess, ExitCode);
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
end;
finally
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
end;
end;
function num2min_sec(ss:string):string;
var
s1,s2,s3:string;
begin
if ss='' then
begin
result:='';
exit;
end;
if instr(ss,'.') then
begin
s1:=ss;
s2:=copy(s1,0,pos('.',s1)-1);
s3:=copy(s1,pos('.',s1)+1,2);
if length(s3)=1 then s3:=s3+'0';
result:=s2+'′'+s3+'″';
end
else
begin
result:=ss+'′00″';
end;
end;
procedure sortStrings(stringList:TStrings);
var
I, J, P,L,R: Integer;
vot:string;
begin
L:=0;
R:=stringlist.Count-1;
repeat
I := L;
J := R;
P := (L + R) shr 1;
repeat
vot := stringList.Strings[P];
while CompareStr(vot,stringList.Strings[I]) < 0 do Inc(I);
while CompareStr(vot,stringList.Strings[J]) > 0 do Dec(J);
if I <= J then
begin
vot := stringList.Strings[I];
stringList.Strings[I] := stringList.Strings[J];
stringList.Strings[J] := vot;
if P = I then
P := J
else if P = J then
P := I;
Inc(I);
Dec(J);
end;
until I > J;
if L < J then Sortstrings(stringList);
L := I;
until I >= R;
end;
function GetSysCom():tstrings;
var
i: integer;
Reg: TRegistry;
RegStr: string;
tmpList,list: TStrings;
begin
list:=tstringlist.Create;
RegStr := '\HARDWARE\DEVICEMAP\SERIALCOMM';
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey(RegStr, False) then
begin
tmpList := TStringList.Create;
Reg.GetValueNames(tmpList);
for i := 0 to tmpList.Count - 1 do
begin
if tmpList.Strings[i]<>'Winachsf0' then list.Add(Reg.ReadString(tmpList.Strings[i]));
end;
freeAndnil(tmpList);
end;
freeAndnil(Reg);
result:=list;
end;
{原读取文本文件}
function readTextFile(fileName:string):tStrings;
var
list:tStrings;
begin
list:=tStringList.Create;
list.LoadFromFile(fileName);
result:=list;
end;
procedure writeTextFile(content:string;filename:string);
var
list:tStrings;
begin
list:=tStringList.Create;
list.Text:=content;
list.SaveToFile(filename);
list.Free;
end;
function RegAddToRun(Name,Value:string):Boolean;
var
Reg:TRegistry;
Values:string;
begin
Result:=False;
try
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('software\microsoft\windows\currentversion\run\',False);
Values:=Reg.ReadString(Name);
if Values<>Value then
begin
Reg.WriteString(Name,Value);
Result:=True;
end;
finally
Reg.Free;
end;
except
end;
end;
procedure log(strFile:string;strLog:string);
var
f:text;
begin
end;
{关闭计算机}
function WinExit(iFlags: integer) : Boolean;
{
0:注销
1:关闭计算机
2:重新启动计算机
4:强制注销(不保存状态)
8:关闭电源
16:注销
}
function SetPrivilege (sPrivilegeName: string; bEnabled: Boolean) : Boolean;
var
TPPrev,TP: TTokenPrivileges;
Token : THandle;
dwRetLen : DWORD;
begin
result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token);
TP.PrivilegeCount := 1;
if LookupPrivilegeValue (nil, PChar (sPrivilegeName), TP.Privileges[0].LUID) then
begin
if bEnabled then TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else TP.Privileges[0].Attributes := 0;
dwRetLen := 0;
result := AdjustTokenPrivileges(Token, False, TP, SizeOf (TPPrev), TPPrev,dwRetLen);
end;
CloseHandle(Token);
end;
begin
Result:=False;
if SetPrivilege ('SeShutdownPrivilege', true) then
begin
if ExitWindowsEx(iFlags, 0) then result:=True;
SetPrivilege ('SeShutdownPrivilege', False);
end
end;
function StrEncode(ss: string): string;
var
i:integer;
crc:byte;
begin
result:='';
for i:=1 to Length(ss) do
begin
result:=result+inttohex(Ord(ss[i]) xor i*2,2);
end;
crc:=0;
for i:=1 to Length(Result) do
begin
crc:=crc+ord(result[i]);
end;
result:=result+inttohex(crc,2);
end;
function StrDecode(ss: string): string;
var
i:integer;
crc:Byte;
begin
ss:=UpperCase(ss);
if Length(ss) mod 2<>0 then
begin
result:='';
Exit;
end;
for i:=1 to Length(ss)-2 do crc:=crc+ord(ss[i]);
if cint('$'+copy(ss,Length(ss)-1,2))<>crc then
begin
result:='';
Exit;
end;
result:='';
for i:=1 to (Length(ss)-2) div 2 do
begin
result:=result+chr(cint('$'+copy(ss,i*2-1,2)) xor i*2);
end;
end;
procedure init;
var
connstr:string;
begin
connstr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+sysutils.ExtractFilePath(application.exename)+'/db.mdb;Jet OLEDB:Database Password=;';
cn:=tAdoConnection.Create(nil);
cn.ConnectionString:=connstr;
cn.KeepConnection:=true;
cn.LoginPrompt:=False;
try
cn.Open();
except
msgerr('系统初始化失败');
Application.Terminate;
ExitProcess(0);
end;
end;
function wait(MaxWaitTime: Cardinal): Boolean;
var
I:Integer;
WaitedTime:Cardinal;
begin
WaitedTime:=0;
while WaitedTime<MaxWaitTime do
begin
SleepEx(100,False);
Inc(WaitedTime,100);
Application.ProcessMessages ;
end
end;
function replace(a,b,c:string):string;
begin
result:=stringreplace(a,b,c,[rfReplaceAll, rfIgnoreCase]);
end;
function cint(str:string):integer;
var
e:integer;
begin
if str='' then
result:=0
else
val(str,result,e);
end;
function isnum(str:string):boolean;
var
b:boolean;
begin
try
strtofloat(str);
b:=true;
except
b:=false;
end;
result:=b;
end;
function isint(str:string):boolean;
var
b:boolean;
begin
try
strtoint(str);
b:=true;
except
b:=false;
end;
result:=b;
end;
function cstr(s:integer):string;
begin
result:=inttostr(s);
end;
function cstr(s:double): string; overload;
begin
result:=floattostr(s);
end;
function pct(a,b:string):string;overload;
var
x1,x2:double;
begin
x1:=cdbl(a);
x2:=cdbl(b);
result:=pct(x1,x2);
end;
function pct(a,b:integer):string;overload;
var
x1,x2:double;
begin
x1:=cdbl(cstr(a));
x2:=cdbl(cstr(b));
result:=pct(x1,x2);
end;
function pct(a,b:double):string;overload;
begin
try
result:=format('%2.2f',[(a/b)*100])+'%';
except
result:='0.00%';
end;
end;
function num2gb(i:integer): string;
begin
if i=0 then result:='零';
if i=1 then result:='一';
if i=2 then result:='二';
if i=3 then result:='三';
if i=4 then result:='四';
if i=5 then result:='五';
if i=6 then result:='六';
if i=7 then result:='七';
if i=8 then result:='八';
if i=9 then result:='九';
end;
function instr(a,b:string):boolean;
begin
result:=(pos(b,a)>0);
end;
function cdbl(str:string):double;
begin
try
result:=strtofloat(str);
except
result:=0.0;
end;
end;
procedure q(sql:string;ado_conn:TAdoConnection=nil);
begin
try
if ado_conn=nil then
cn.Execute(sql)
else
ado_conn.Execute(sql);
except
on e:exception do
begin
log('sql.err.log',sql);
msgerr('SQL错误:'+#13#10#13#10+sql+#13#10+e.Message);
end;
end;
end;
procedure q_(sql:string;ado_conn:TAdoConnection=nil);
begin
try
if ado_conn=nil then
cn.Execute(sql)
else
ado_conn.Execute(sql);
except
end;
end;
function num2min_sec_dot(sec:integer):string;
var
imin,isec:integer;
ssec:string;
begin
result:='0';
if sec<=0 then exit;
imin:=sec div 60;
isec:=sec mod 60;
ssec:=cstr(isec);
if isec<10 then ssec:='0'+cstr(isec);
result:=cstr(imin)+'.'+ssec;
end;
function sqlValue(sql:string;ado_conn:TAdoConnection=nil):string;
begin
result:='';
with g(sql,ado_conn) do
begin
if not eof then result:=rs.fields[0].AsString;
close;
end;
end;
function sqlValueCache(sql:string;ado_conn:TAdoConnection=nil):string;
begin
end;
function svc(sql:string;ado_conn:TAdoConnection=nil):string;
var
s:string;
begin
s:=sv(sql);
result:=s;
end;
function sv(sql:string;ado_conn:TAdoConnection=nil):string;
begin
result:=sqlValue(sql,ado_conn);
end;
function getSexStr(s:string):string;
begin
result:=s;
if s='1' then result:='男';
if s='2' then result:='女';
end;
function getNjNum(s: string): string;
begin
result:=s;
if s='小一' then result:='11';
if s='小二' then result:='12';
if s='小三' then result:='13';
if s='小四' then result:='14';
if s='小五' then result:='15';
if s='小六' then result:='16';
if s='初一' then result:='21';
if s='初二' then result:='22';
if s='初三' then result:='23';
if s='高一' then result:='31';
if s='高二' then result:='32';
if s='高三' then result:='33';
if s='大一' then result:='41';
if s='大二' then result:='42';
if s='大三' then result:='43';
if s='大四' then result:='44';
end;
function getNjStr(s: string): string;
begin
result:=s;
if s='11' then result:='小一';
if s='12' then result:='小二';
if s='13' then result:='小三';
if s='14' then result:='小四';
if s='15' then result:='小五';
if s='16' then result:='小六';
if s='21' then result:='初一';
if s='22' then result:='初二';
if s='23' then result:='初三';
if s='31' then result:='高一';
if s='32' then result:='高二';
if s='33' then result:='高三';
if s='41' then result:='大一';
if s='42' then result:='大二';
if s='43' then result:='大三';
if s='44' then result:='大四';
end;
function confirm(str:string):boolean;
begin
result:=(messagebox(GetActiveWindow(),pchar(str),pchar(application.Title),MB_ICONASTERISK or MB_OKCANCEL)=1);
end;
procedure msgerr(str:string);
begin
messagebox(GetActiveWindow(),pchar(replace((str),'\n',#13#10)),'错误',mb_iconerror);
end;
function sqlstr(s:string):string;
begin
result:=replace(s,'''','''''');
result:=replace(result,'--','--');
end;
function reg(key:string;v:string=''):string;
var
str:string;
begin
if v='' then
str:=sv('select v from reg where k='''+sqlstr(key)+''' ')
else
begin
q('delete from reg where k='''+sqlstr(key)+''' ');
q('insert into reg (k,v) values ('''+sqlstr(key)+''','''+sqlstr(v)+''') ');
end;
if str=null then str:='';
result:=str;
end;
function ChnPy(Value: array of char): Char;
begin
Result := #0;
case Byte(Value[0]) of
176:
case Byte(Value[1]) of
161..196: Result := 'A';
197..254: Result := 'B';
end; {case}
177:
Result := 'B';
178:
case Byte(Value[1]) of
161..192: Result := 'B';
193..205: Result := 'C';
206: Result := 'S'; //参
207..254: Result := 'C';
end; {case}
179:
Result := 'C';
180:
case Byte(Value[1]) of
161..237: Result := 'C';
238..254: Result := 'D';
end; {case}
181:
Result := 'D';
182:
case Byte(Value[1]) of
161..233: Result := 'D';
234..254: Result := 'E';
end; {case}
183:
case Byte(Value[1]) of
161: Result := 'E';
162..254: Result := 'F';
end; {case}
184:
case Byte(Value[1]) of
161..192: Result := 'F';
193..254: Result := 'G';
end; {case}
185:
case Byte(Value[1]) of
161..253: Result := 'G';
254: Result := 'H';
end; {case}
186:
Result := 'H';
187:
case Byte(Value[1]) of
161..246: Result := 'H';
247..254: Result := 'J';
end; {case}
188..190:
Result := 'J';
191:
case Byte(Value[1]) of
161..165: Result := 'J';
166..254: Result := 'K';
end; {case}
192:
case Byte(Value[1]) of
161..171: Result := 'K';
172..254: Result := 'L';
end; {case}
193:
Result := 'L';
194:
case Byte(Value[1]) of
161..231: Result := 'L';
232..254: Result := 'M';
end; {case}
195:
Result := 'M';
196:
case Byte(Value[1]) of
161..194: Result := 'M';
195..254: Result := 'N';
end; {case}
197:
case Byte(Value[1]) of
161..181: Result := 'N';
182..189: Result := 'O';
190..254: Result := 'P';
end; {case}
198:
case Byte(Value[1]) of
161..217: Result := 'P';
218..254: Result := 'Q';
end; {case}
199:
Result := 'Q';
200:
case Byte(Value[1]) of
161..186: Result := 'Q';
187..245: Result := 'R';
246..254: Result := 'S';
end; {case}
201..202:
Result := 'S';
203:
case Byte(Value[1]) of
161..249: Result := 'S';
250..254: Result := 'T';
end; {case}
204:
Result := 'T';
205:
case Byte(Value[1]) of
161..217: Result := 'T';
218..254: Result := 'W';
end; {case}
206:
case Byte(Value[1]) of
161..243: Result := 'W';
244..254: Result := 'X';
end; {case}
207..208:
Result := 'X';
209:
case Byte(Value[1]) of
161..184: Result := 'X';
185..254: Result := 'Y';
end; {case}
210..211:
Result := 'Y';
212:
case Byte(Value[1]) of
161..208: Result := 'Y';
209..254: Result := 'Z';
end; {case}
213..215: