📄 usyspub.pas
字号:
if not DaiMaAndMingCheng then
TStr1.Free;
end;
function NontoNumber(strtmp:string):string;
begin
Result:=strtmp;
if Trim(strtmp)='' then
Result:='0';
end;
function BooleantoNumber(strtmp:Boolean):string;
begin
if strtmp then
Result:='1'
else
Result:='0';
end;
function NumbertoBoolean(nNumber:integer):Boolean;
begin
if nNumber=1 then
Result:=True
else
Result:=False;
end;
{释放指针的空间}
procedure disposepoint(mytreeview:Ttreeview);
var
r:integer;
begin
for r:=0 to mytreeview.Items.Count-1 do
begin
if assigned(mytreeview.Items.Item[r].Data) then
dispose(mytreeview.Items.Item[r].Data);
end;
mytreeview.Items.Clear;
end;
function EncryptString( input:string ):string;
const
keyword=255;
var
i:integer;
begin
for i:=1 to length(input) do
input[i]:=Chr(Ord(input[i]) xor keyword);
Result:=input;
end;
procedure SetActionState( var ActList:TActionList;state:integer);
var
i:integer;
Action:TAction;
strsql :string;
bSucc:boolean;
begin
{try
strsql := 'select gnmc,kjbs,kjky from pgx,pgn where pgngnxh = gnxh ';
strsql := strsql + ' and pgzgzxh = ' + floattostr( dGZXH ) + ' and gnfq = ' + floattostr( dMKXH );
case State of
0:
begin
for i:=0 to ActList.ActionCount-1 do //所有功能都不可用
begin
Action:=TAction(ActList.Actions[i]);
Action.Enabled:=False;
end;
end;
2:
begin
RunSQL( dm.m_clADOQry_Temp, strsql, 0 );
for i:=0 to ActList.ActionCount-1 do
begin
bSucc := true;
dm.m_clADOQry_Temp.First;
while not dm.m_clADOQry_Temp.Eof and bSucc do
begin
if trim( dm.m_clADOQry_Temp.FieldByName('gnmc').AsString ) = trim( TAction( ActList.Actions[i] ).Caption ) then
begin
bSucc := false;
if dm.m_clADOQry_Temp.FieldByName('KJKY').AsInteger = 1 then
TAction( ActList.Actions[i] ).Enabled := true
else
TAction( ActList.Actions[i] ).Enabled := false;
if dm.m_clADOQry_Temp.FieldByName('KJBS').AsInteger = 1 then
TAction( ActList.Actions[i] ).Visible := true
else
TAction( ActList.Actions[i] ).Visible := false;
end;
if trim( TAction( ActList.Actions[i] ).Caption ) = '本系统功能' then
TAction( ActList.Actions[i] ).Visible := false;
dm.m_clADOQry_Temp.Next;
end;
end;
end;
3: //超级用户
begin
for i:=0 to ActList.ActionCount-1 do
begin
Action:=TAction(ActList.Actions[i]);
Action.Enabled:=True;
end;
end;
end;
except
end; }
end;
function ReadSysParameters():boolean;
var
bSucc:boolean;
strsql:string;
begin
try
bSucc := false;
strSysDate := getSysDate();
dMKXH := 1;
strsql := ' select * from pcs';
RunSQL( dm.m_clADOQry_Temp, strsql , 0 );
while not dm.m_clADOQry_Temp.Eof do
begin
if ( trim( dm.m_clADOQry_Temp.FieldByName('SZBM').AsString ) = 'KXM' ) and
( trim( dm.m_clADOQry_Temp.FieldByName('ZDMC').AsString ) = 'JMCD' ) then
nJMCD := dm.m_clADOQry_Temp.FieldByName('ZDSZ').AsInteger;
dm.m_clADOQry_Temp.Next;
end;
bSucc := true;
except
bSucc := false;
end;
Result :=bSucc;
end;
function BuildBHStr( nStart:integer; nLen:integer ):string;
var
strtmp:String;
i:integer;
begin
strtmp := '';
for i := 1 to nLen do
strtmp := strtmp + '0';
strtmp := strtmp + inttostr( nStart );
strtmp := RightStr( strtmp , nLen );
Result := strtmp;
end;
function BuildTableBHStr( Strtmp:string;strAdd:string; nLen:integer ):string;
var
strTemp:string;
nstrlen,nstrAddlen,i,ntmp:integer;
begin
strTemp:='';
nstrlen:=length(Strtmp);
nstrAddlen:=length(strAdd);
if nstrlen<nlen then
begin
ntmp:=(nLen-nstrlen) div nstrAddlen;
for i:=1 to ntmp do
strTemp:=strTemp+strAdd;
Result := strTemp+Strtmp;
end
else
begin
Result := Strtmp;
end;
end;
function BuildTable(ADOQry_Temp: TADOQuery;StrTable:string;strZDM:STRING;strADD:String;nlen:integer):string;
var
strSQL,strbh:STRING;
begin
strSQL:='SELECT MAX('+strZDM+')+1 AS BH FROM '+ StrTable;
RunSQL( ADOQry_Temp, strSQL , 0 );
strbh:=Trim(ADOQry_Temp.FieldByName('BH').AsString );
Result:=BuildTableBHStr(strbh,strADD,nlen);
end;
function BuildTableDJBH(ADOQry_Temp: TADOQuery;StrTable:string;strZDM:STRING;strADD:String):string;
var
strSQL,strbh,strDate,strTmp,strEnd:STRING;
nbh:integer;
begin
strDate:=copy(GetSysDate(),3,6);
strSQL:='SELECT MAX('+strZDM+') AS BH FROM '+ StrTable+' where '+strZDM+' like '+''''+strADD+strDate+'%'+'''';
RunSQL( ADOQry_Temp, strSQL , 0 );
strbh:=Trim(ADOQry_Temp.FieldByName('BH').AsString );
if strbh<>'' then
begin
strTmp:=copy(strbh,10,6);
nbh:=strtoint(strTmp)+1;
strEnd:=BuildTableBHStr(inttostr(nbh),'0',6);
Result:=strADD+strDate+'-'+strEnd;
end
else
Result:=strADD+strDate+'-000001';
end;
procedure BuildJMStr( var AdoQrJM:TADOQuery; strZWZF:string; var strPYJM:string; var strWBJM:string; nMaxLen :integer );
var
strzf:string;
nLen,ntmp,i:Integer;
begin
try
strPYJM := '';
strWBJM := '';
strZWZF := trim( strZWZF );
nLen := Length( strZWZF );
ntmp := 1;
while nLen >= ntmp + 1 do
begin
strzf := midstr( strZWZF, ntmp, 1 );
if ord( strZWZF[ntmp] ) > 127 then
begin
strzf := midstr( strZWZF, ntmp, 2 );
if AdoQrJM.Locate('ZWZF',strzf, [loCaseInsensitive] ) then
begin
strPYJM := strPYJM + trim( AdoQrJM.fieldByName('PYBM').AsString );
strWBJM := strWBJM + trim( AdoQrJM.fieldByName('WBBM').AsString );
end;
end
else
begin
if ord( strZWZF[ntmp] ) < 123 then
begin
strPYJM := strPYJM + strzf;
strWBJM := strWBJM + strzf;
end;
ntmp := ntmp - 1;
nLen := nLen + 1;
end;
ntmp := ntmp + 2;
end;
if length( strPYJM ) > nMaxLen then
strPYJM := midstr( strPYJM, 1, nMaxLen );
if length( strWBJM ) > nMaxLen then
strWBJM := midstr( strWBJM, 1, nMaxLen );
except
end;
end;
function GetYear(Date: TDate): Integer;
var
y, m, d: WORD;
begin
DecodeDate(Date, y, m, d);
Result := y;
end;
function GetMonth(Date: TDate): Integer;
var
y, m, d: WORD;
begin
DecodeDate(Date, y, m, d);
Result := m;
end;
function GetDay(Date: TDate): Integer;
var
y, m, d: WORD;
begin
DecodeDate(Date, y, m, d);
Result := d;
end;
//得到本月的第一一天
function dateBeginOfMonth(D: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(D, Year, Month, Day);
Result := EncodeDate(Year, Month, 1);
end;
//得到本月的最后一天
function dateEndOfMonth(D: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(D, Year, Month, Day);
if Month = 12 then
begin
Inc(Year);
Month := 1;
end else
Inc(Month);
Result := EncodeDate(Year, Month, 1) - 1;
end;
//得到本年的最后一天
function dateEndOfYear(D: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(D, Year, Month, Day);
Result := EncodeDate(Year, 12, 31);
end;
//得到两个日期相隔的天数
function DaysBetween(Date1, Date2: TDateTime): integer;
begin
Result := Trunc(Date2) - Trunc(Date1) + 1;
if Result < 0 then Result := 0;
end;
//字符转化成十六进制
function StrToHex(AStr: string): string;
var
I : Integer;
// Tmp: string;
begin
Result := '';
For I := 1 to Length(AStr) do
begin
Result := Result + Format('%2x', [Byte(AStr[I])]);
end;
I := Pos(' ', Result);
While I <> 0 do
begin
Result[I] := '0';
I := Pos(' ', Result);
end;
end;
//十六进制转化成字符
function HexToStr(AStr: string): string;
var
I : Integer;
CharValue: Word;
begin
Result := '';
for I := 1 to Trunc(Length(Astr)/2) do
begin
Result := Result + ' ';
CharValue := TransChar(AStr[2*I-1])*16 + TransChar(AStr[2*I]);
Result[I] := Char(CharValue);
end;
end;
function TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result := Ord(AChar) - Ord('0')
else
Result := 10 + Ord(AChar) - Ord('A');
end;
//字符串加密函数
function Encrypt(const S: String; Key: Word): String;
var
I : Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
if Result[I] = Chr(0) then
Result[I] := S[I];
end;
Result := StrToHex(Result);
end;
//字符串解密函数
function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * C1 + C2; //保证Key的正确性
end
else
begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * C1 + C2;
end;
end;
end;
{Public Way end}
{TCustomException start}
procedure TCustomException.SetErrMsg( pErrMsg:string );
begin
m_pErrMsg := pErrMsg;
end;
procedure TCustomException.ShowErrMsg();
begin
showmessage( m_pErrMsg );
end;
{TCustomException end}
{TtestException start}
procedure TtestException.DivData( ncs, nbc:integer );
var
e:TCustomException;
begin
if nbc = 0 then
begin
try
e:=TCustomException.Create;
e.SetErrMsg( '除数不能为零' );
except
e.Free;
end;
raise e;
end;
end;
{TtestException end}
{TMyField Start}
constructor TMyField.create();
begin
m_strFieldData := '';
m_dFieldData := 0;
m_nKey := 0;
m_nGerm := 0;
m_strFieldName := '';
end;
procedure TMyField.SetField( strFieldName:string; etype:TDataFieldType; nkey, nGerm:integer );
begin
m_eDataFieldType := etype;
m_strFieldName := strFieldName;
m_nKey := nkey;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -