📄 danwei.pas
字号:
unit DanWei;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask, DBCtrls, ExtCtrls, Db, Dbgrids;
type
TDanWeiForm = class(TForm)
Label2: TLabel;
Label10: TLabel;
Label3: TLabel;
ButtonOk: TButton;
ButtonCancel: TButton;
Label4: TLabel;
DBEdit1: TDBEdit;
DBEdit3: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
Panel1: TPanel;
Label1: TLabel;
EditCompCode: TEdit;
ButtonLocate: TButton;
procedure ButtonCancelClick(Sender: TObject);
procedure ButtonOkClick(Sender: TObject);
procedure ButtonLocateClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DanWeiForm: TDanWeiForm;
implementation
uses huaxia, ErrorHit, Zulin, HeiMingDanWei;
{$R *.DFM}
procedure TDanWeiForm.ButtonCancelClick(Sender: TObject);
begin
Close;
end;
procedure TDanWeiForm.ButtonOkClick(Sender: TObject);
begin
Try
If (huaxiaData.QueryComp.State=DsInsert) or (huaxiaData.QueryComp.State=DsEdit) Then
huaxiaData.QueryComp.post;
huaxiaData.QueryComp.Close;
HuaXiaData.QueryCar.FieldByName('lease_comp_code').AsString:=DanweiForm.EditCompCode.text;
HuaXiaData.QueryCar.Edit;
Except
On E:Exception Do
Begin
ShowMessage('数据库连接失败,请检验网络连接是否正常');
Exit;
End;
End;
end;
procedure TDanWeiForm.ButtonLocateClick(Sender: TObject);
begin
Try
If EditCompCode.Text<>'' Then
Begin
With HuaXiaData.QueryComp Do
Begin
Close;
Unprepare;
With Sql Do
Begin
Clear;
Add('Select * From lease_comp_info ');
Add('Where lease_comp_code=:Comp_Code');
End;
RequestLive:=True;
ParamByName('Comp_code').AsString:=DanweiForm.EditCompCode.text;
prepare;
Open;
End;
If HuaXiaData.QueryComp.RecordCount=0 Then
Begin
HuaXiaData.QueryComp.Append;
HuaXiaData.QueryComp.FieldByName('lease_comp_code').AsString:=DanweiForm.EditCompCode.text;
End
Else
If HuaXiaData.QueryComp.RecordCount=1 Then
Begin
HuaXiaData.QueryComp.Edit;
HuaXiaData.QueryComp.FieldByName('lease_comp_code').AsString:=DanweiForm.EditCompCode.text;
End
End
Else
Begin
ErrorForm.ShowModal;
ActiveControl:=ButtonCancel;
End;
Except
On E:Exception Do
Begin
ShowMessage('数据库连接失败,请检验网络连接是否正常');
Exit;
End;
End;
end;
procedure TDanWeiForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
If key=#13 then { 判断是按执行键}
If Not(ActiveControl Is TDbgrid) Then
Begin { 不是在TDbgrid控件内}
key:=#0;
perform(WM_NEXTDLGCTL,0,0);{移动到下一个控件}
End Else
If (ActiveControl Is TDbgrid) Then{是在 TDbgrid 控件内}
Begin
With TDbgrid(ActiveControl) Do
If Selectedindex<(FieldCount-1) Then
Selectedindex:=Selectedindex+1{ 移动到下一字段}
Else Selectedindex:=0;
End;
end;
procedure TDanWeiForm.FormActivate(Sender: TObject);
begin
Try
Try
EditCompCode.Text:=HuaXiaData.QueryCar.FieldByName('lease_comp_code').AsString;
Except
EditCompCode.Text:='';
End;
With HuaXiaData.QueryComp Do
Begin
Close;
Unprepare;
With Sql Do
Begin
Clear;
Add('Select * From lease_comp_info ');
Add('Where lease_comp_code=:comp_code');
End;
RequestLive:=True;
ParamByName('comp_code').AsString:=DanweiForm.EditCompCode.text;
prepare;
Open;
End;
If HuaXiaData.QueryComp.RecordCount=1 Then
HuaXiaData.QueryComp.Edit
Else
Begin
HuaXiaData.QueryComp.Close;
ActiveControl:=EditCompCode;
End;
Except
On E:Exception Do
Begin
ShowMessage('数据库连接失败,请检验网络连接是否正常');
Exit;
End;
End;
end;
procedure TDanWeiForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Try
If (huaxiaData.QueryComp.State=DsInsert) or (huaxiaData.QueryComp.State=DsEdit) Then
Begin
If MessageDlg('保存以上单位信息吗?', mtConfirmation, [mbYes, mbNo],0)=mrYes Then
Begin
HuaXiaData.QueryComp.Post;
HuaXiaData.QueryCar.Edit;
HuaXiaData.QueryCar.FieldByName('lease_way').AsString:='单位';
HuaXiaData.QueryCar.FieldByName('lease_comp_code').AsString:=DanweiForm.EditCompCode.text;
HuaXiaData.QueryCar.Edit;
Zulin.ShowFlag:=3;
End
Else
Begin
HuaXiaData.QueryCar.Edit;
HuaXiaData.QueryCar.FieldByName('lease_way').AsString:='个人';
ZuLinForm.DBComboBoxWay.Text:='个人';
HuaXiaData.QueryCar.Edit;
Zulin.ShowFlag:=2;
HuaXiaData.QueryComp.Cancel;
End;
End
Else
Begin
HuaXiaData.QueryCar.Edit;
HuaXiaData.QueryCar.FieldByName('lease_way').AsString:='个人';
Zulin.ShowFlag:=2;
HuaXiaData.QueryCar.Edit;
End;
huaxiaData.QueryComp.Close;
With HuaXiaData.QueryHei Do
Begin
Close;
Unprepare;
With Sql Do
Begin
Clear;
Add('Select * From bad_comp Where lease_comp_code=:Id_code and tag=:flag');
End;
RequestLive:=True;
ParamByName('Id_code').AsString:=DanweiForm.EditCompCode.text;
ParamByName('flag').AsString:='1';
prepare;
Open;
End;
If HuaXiaData.QueryHei.RecordCount=0 Then
Begin
With HuaXiaData.QueryHei Do
Begin
Close;
Unprepare;
With Sql Do
Begin
Clear;
Add('Select * From bad_comp Where lease_comp_name=:name and tag=:flag');
End;
RequestLive:=True;
ParamByName('name').AsString:=DanWeiForm.DBEdit1.text;
ParamByName('flag').AsString:='1';
prepare;
Open;
End;
End;
If HuaXiaData.QueryHei.RecordCount>0 Then
Begin
HeiMingDanWeiForm.ShowModal;
End;
Except
On E:Exception Do
Begin
ShowMessage('数据库连接失败,请检验网络连接是否正常');
Exit;
End;
End;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -