📄 u_dbpublicpack.pas
字号:
StrSql:='Select GetDate() As DbCurrentDateTime';
SQL.Add(StrSql);
Open;
If Not Eof Then
Begin
Result:=FieldByName('DbCurrentDateTime').AsDateTime;
End;
End;
Except
On E:EOleException Do
Begin
Beep();Beep();
//MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
ADOQuery.Free;
End;
//判断是否可以登录
Function CheckLogin(ADOConnection:TADOConnection;LoginTableName:String;LoginUserCode:String;LoginUserPassWord:String):Integer;
Var
ADOQuery:TADOQuery;
SqlStr:String;
begin
Try
ADOQuery:=TADOQuery.Create(Nil);
ADOQuery.Connection:=ADOConnection;
With ADOQuery Do
Begin
Close;
Sql.Clear;
SqlStr:='Select * From '+LoginTableName;
SqlStr:=SqlStr+' Where UserCode=:UserCode';
If LoginUserPassWord='' Then
SqlStr:=SqlStr+' And UserPassword Is Null'
Else
SqlStr:=SqlStr+' And UserPassword=:UserPassWord';
Sql.Add(SqlStr);
Parameters.ParamByName('UserCode').Value:=LoginUserCode;
If LoginUserPassWord<>'' Then
Parameters.ParamByName('UserPassword').Value:=LoginUserPassWord;
Open;
If Not Eof Then
Result:=1
Else
Begin
MessageDLG('用户名或用户密码不对,请重新输入!',MTWarning,[mbok],0);
Result:=0;
End;
End;
Except
On E:EOleException Do
Begin
Beep();Beep();
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
ADOQuery.Free;
End;
//判断是否可以登录
Function CheckLogin(DBConnectionString,LoginTableName:String;LoginUserCode:String;LoginUserPassWord:String):Integer;
Var
ADOQuery:TADOQuery;
SqlStr:String;
begin
Try
ADOQuery:=TADOQuery.Create(Nil);
ADOQuery.ConnectionString:=DBConnectionString;
With ADOQuery Do
Begin
Close;
Sql.Clear;
SqlStr:='Select * From '+LoginTableName;
SqlStr:=SqlStr+' Where UserCode=:LoginUserCode';
SqlStr:=SqlStr+' And UserPassword=:LoginUserPassWord';
Sql.Add(SqlStr);
Parameters.ParamByName('LoginUserCode').Value:=LoginUserCode;
Parameters.ParamByName('UserPassword').Value:=LoginUserPassWord;
Open;
If Not Eof Then
Result:=1
Else
Begin
Beep();Beep();
MessageDLG('用户代码或用户密码不对,请重新输入!',MTWarning,[mbok],0);
Result:=0;
End;
End;
Except
On E:EOleException Do
Begin
Beep();Beep();
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
ADOQuery.Free;
End;
//插入新记录
Function InsertRec(ADOTable:TADOTable;ControlMod:TPanel):Boolean;
Var
Count:Integer;
Begin
Try
With ADOTable Do
Begin
Insert;
For Count:=0 To ControlMod.ControlCount-1 Do
Begin
If Controlmod.Controls[Count].Tag=0 Then
Continue;
If Controlmod.controls[Count] is TEdit Then
Fields[(Controlmod.Controls[Count] as TEdit).Tag-1].AsString:=(Controlmod.Controls[Count] as TEdit).Text;
If (Controlmod.controls[Count] is TComboBox) Then
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-1].AsString:=(Controlmod.Controls[Count] as TComboBox).Text;
If (Controlmod.controls[Count] is TMemo) Then
Fields[(Controlmod.Controls[Count] as TMemo).Tag-1].AsString:=(Controlmod.Controls[Count] as TMemo).Text;
If (Controlmod.controls[Count] is TSpinEdit) Then
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-1].AsInteger:=(Controlmod.Controls[Count] as TSpinEdit).Value;
If (Controlmod.Controls[Count] is TDateTimePicker) Then
Begin
If (Controlmod.Controls[Count] as TDateTimePicker).Checked Then
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].AsDateTime:=(Controlmod.Controls[Count] as TDateTimePicker).DateTime;
End;
End;
Post;
Result:=True;
End;
Except
On E:EOleException Do
Begin
Result:=False;
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
End;
//插入新记录
Function InsertRec(ADOQuery:TADOQuery;ControlMod:TPanel;IsHaveAutoID:Boolean):Boolean;
Var
Count,Jump:Integer;
Begin
if IsHaveAutoID then
Jump := 0
else
Jump :=1 ;
Try
With ADOQuery Do
Begin
Insert;
For Count:=0 To Controlmod.ControlCount-1 Do
Begin
If Controlmod.Controls[Count].Tag=0 Then
Continue;
If Controlmod.Controls[Count] is TEdit Then
begin
if Trim((Controlmod.Controls[Count] as TEdit).Text) = '' then
Fields[(Controlmod.Controls[Count] as TEdit).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TEdit).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TEdit).Text;
end;
If (Controlmod.Controls[Count] is TComboBox) Then
begin
if Trim((Controlmod.Controls[Count] as TComboBox).Text) = '' then
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-Jump].Value := Null
else
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TComboBox).Text;
end;
If (Controlmod.Controls[Count] is TMemo) Then
begin
if Trim((Controlmod.Controls[Count] as TMemo).Text) = '' then
Fields[(Controlmod.Controls[Count] as TMemo).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TMemo).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TMemo).Text;
end;
If (Controlmod.controls[Count] is TSpinEdit) Then
begin
if Trim((Controlmod.Controls[Count] as TSpinEdit).Text)='' then
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-Jump].AsInteger:=(Controlmod.Controls[Count] as TSpinEdit).Value;
end;
If (Controlmod.Controls[Count] is TDateTimePicker) Then
Begin
If (Controlmod.Controls[Count] as TDateTimePicker).Checked Then
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].AsDateTime:=(Controlmod.Controls[Count] as TDateTimePicker).DateTime
else
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].Value:=Null;
End;
End;
Post;
Result:=True;
End;
Except
On E:EOleException Do
Begin
Result:=False;
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
End;
//修改表记录
Function UpdateRec(ADOTable:TADOTable;ControlMod:TPanel):Boolean;
Var
Count:Integer;
Begin
Try
With ADOTable Do
Begin
If Eof Then
Exit;
Edit;
For Count:=0 To ControlMod.ControlCount-1 Do
Begin
If Controlmod.Controls[Count].Tag=0 Then
Continue;
If Controlmod.controls[Count] is TEdit Then
Fields[(Controlmod.Controls[Count] as TEdit).Tag-1].AsString:=(Controlmod.Controls[Count] as TEdit).Text;
If (Controlmod.controls[Count] is TComboBox) Then
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-1].AsString:=(Controlmod.Controls[Count] as TComboBox).Text;
If (Controlmod.controls[Count] is TMemo) Then
Fields[(Controlmod.Controls[Count] as TMemo).Tag-1].AsString:=(Controlmod.Controls[Count] as TMemo).Text;
If (Controlmod.controls[Count] is TSpinEdit) Then
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-1].AsInteger:=(Controlmod.Controls[Count] as TSpinEdit).Value;
If (Controlmod.Controls[Count] is TDateTimePicker) Then
Begin
If (Controlmod.Controls[Count] as TDateTimePicker).Checked Then
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].AsDateTime:=(Controlmod.Controls[Count] as TDateTimePicker).DateTime;
End;
End;
Post;
Result:=True;
End;
Except
On E:EOleException Do
Begin
Result:=False;
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
End;
//修改表记录
Function UpdateRec(ADOQuery:TADOQuery;ControlMod:TPanel;IsHaveAutoID:Boolean):Boolean;
Var
Count,Jump:Integer;
Begin
if IsHaveAutoID then
Jump := 0
else
Jump :=1 ;
Try
With ADOQuery Do
Begin
If Eof Then
Exit;
Edit;
For Count:=0 To ControlMod.ControlCount-1 Do
Begin
If Controlmod.Controls[Count].Tag=0 Then
Continue;
If Controlmod.Controls[Count] is TEdit Then
begin
if Trim((Controlmod.Controls[Count] as TEdit).Text) = '' then
Fields[(Controlmod.Controls[Count] as TEdit).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TEdit).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TEdit).Text;
end;
If (Controlmod.Controls[Count] is TComboBox) Then
begin
if Trim((Controlmod.Controls[Count] as TComboBox).Text) = '' then
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-Jump].Value := Null
else
Fields[(Controlmod.Controls[Count] as TComboBox).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TComboBox).Text;
end;
If (Controlmod.Controls[Count] is TMemo) Then
begin
if Trim((Controlmod.Controls[Count] as TMemo).Text) = '' then
Fields[(Controlmod.Controls[Count] as TMemo).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TMemo).Tag-Jump].AsString:=(Controlmod.Controls[Count] as TMemo).Text;
end;
If (Controlmod.controls[Count] is TSpinEdit) Then
begin
if Trim((Controlmod.Controls[Count] as TSpinEdit).Text)='' then
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-Jump].Value:=Null
else
Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-Jump].AsInteger:=(Controlmod.Controls[Count] as TSpinEdit).Value;
end;
If (Controlmod.Controls[Count] is TDateTimePicker) Then
Begin
If (Controlmod.Controls[Count] as TDateTimePicker).Checked Then
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].AsDateTime:=(Controlmod.Controls[Count] as TDateTimePicker).DateTime
else
Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-Jump].Value:=Null;
End;
End;
Post;
Result:=True;
End;
Except
On E:EOleException Do
Begin
Result:=False;
MessageDLG('Error:'+E.Message,MtWarning,[MBOK],0);
End;
End;
End;
//删除表记录
Function DeleteRec(ADOTable:TAdoTable;ControlMod:TPanel):Boolean;
Var
Count:Integer;
Begin
Try
With ADOTable do
Begin
If Eof Then
Exit;
Delete;
If Not Eof Then
Begin
For Count:=0 To Controlmod.ControlCount-1 Do
Begin
If Controlmod.Controls[Count].Tag=0 Then
Continue;
If Controlmod.Controls[Count] is TEdit Then
(Controlmod.Controls[Count] as TEdit).Text:=Fields[(Controlmod.Controls[Count] as TEdit).Tag-1].AsString;
If (Controlmod.Controls[Count] is TComboBox) Then
(Controlmod.Controls[Count] as TComboBox).Text:=Fields[(Controlmod.Controls[Count] as TComboBox).Tag-1].AsString;
If (Controlmod.Controls[Count] is TMemo) Then
(Controlmod.Controls[Count] as TMemo).Text:=Fields[(Controlmod.Controls[Count] as TMemo).Tag-1].AsString;
If (Controlmod.controls[Count] is TSpinEdit) Then
(Controlmod.Controls[Count] as TSpinEdit).Value:=Fields[(Controlmod.Controls[Count] as TSpinEdit).Tag-1].AsInteger;
If (Controlmod.Controls[Count] is TDateTimePicker) Then
Begin
If Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].IsNull Then
Begin
(Controlmod.Controls[Count] as TDateTimePicker).Checked:=False;
End
Else
Begin
(Controlmod.Controls[Count] as TDateTimePicker).Checked:=True;
(Controlmod.Controls[Count] as TDateTimePicker).DateTime:=Fields[(Controlmod.Controls[Count] as TDateTimePicker).Tag-1].AsDateTime;
End;
End;
End;
End
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -