?? base_entry_detail.pas
字號:
unit Base_Entry_Detail;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Dialog, StdCtrls, Db, AdODB, ExtCtrls, Mask, DBCtrls, ExtEdit;
Type
TFrm_Base_Entry_Detail = Class(TFrm_Base_Dialog)
Pnl_Add: TPanel;
procedure FormActivate(Sender: TObject);
procedure AllChange(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure btn_okClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure OnEnter(Sender: TObject);
private
{ Private declarations }
EnableControls:String;
procedure Save;
protected
{ protected declarations }
ShowFlag{窗口彈出時=False},Changed{控件有改動時=True}:Boolean;
FormCaption:String;
ExtendCaption:Boolean;
Status:String;//標識當前狀況'Add','Edit','ReadOnly'
SetFocus_Control:TWinControl;//增加時要聚焦的控件,一般是最上面的那個
//初始化Form上的各控件時會被調用,這時應該把AdoQry_Maintain 中各字段的值
//賦給Form上相應的Control 中
AdoQry_Head:TAdoQuery;//數據庫維護對象
AdoQry_Body:TAdoQuery;//數據庫維護對象
procedure InitControls; virtual;
//虛擬函數,要把數據保存到數據庫庫中時調用,用于把控件之值保存到數據庫庫中,
//這時還必須給AdoQry_Maintain各字段賦值
procedure SaveBodyData; virtual;
//設置各種狀態下那些控件Enable
procedure SetStatus(CurrentStatus:String;var EnableControls:String); virtual;
public
{ Public declarations }
Modified:Boolean;//單據被修改時=True
//初始化參數,不必重載
procedure InitForm(AdOConnection: TAdOConnection;FormStatus:String;
HeadAdoQuery,BodyAdoQuery:TAdoQuery);virtual;
end;
var
Frm_Base_Entry_Detail: TFrm_Base_Entry_Detail;
implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Base_Entry_Detail.FormActivate(Sender: TObject);
begin//窗口彈出時
ShowFlag:=False;
InitControls;
ShowFlag:=True;
btn_ok.Enabled:=False;
inherited;
end;
procedure TFrm_Base_Entry_Detail.AllChange(Sender: TObject);
begin//缺省onChange事件處理過程
inherited;
btn_ok.Enabled:=True;
Changed:=True;
end;
procedure TFrm_Base_Entry_Detail.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin//處理pageup,pagedown按鍵
inherited;
if(Status<>'Add')then
if(Key=VK_PRIOR)or(Key=VK_NEXT)then
begin
if(btn_ok.Enabled)and(DispInfo('數據有改動,需要保存嗎?',2)='y')then
begin
Changed:=False;
inherited btn_okClick(Sender);
Save;
end;
if Key=VK_PRIOR then
AdoQry_Body.Prior
else
AdoQry_Body.Next;
InitControls;
Btn_ok.Enabled:=False;
Key:=0;
end;
end;
procedure TFrm_Base_Entry_Detail.btn_okClick(Sender: TObject);
begin//
Changed:=False;
inherited;
Save;
if Status='Add' then
begin
DispInfo('當前數據已經保存,可以繼續增加!',3);
InitControls;
btn_ok.Enabled:=False;
end
else
ModalResult:=mrOk;
end;
procedure TFrm_Base_Entry_Detail.InitControls;
var
i:Integer;
Control:TControl;
AcControl:TWinControl;
NotifyEvent:TNotifyEvent;
begin//給窗體上控件賦值時可重載本過程
if GetOnExitEvent(ActiveControl,NotifyEvent) then
Control:=ActiveControl
else
Control:=nil;
AcControl:=ActiveControl;
ActiveControl:=btn_Cancel;
EnableControls:='';
SetStatus(Status,EnableControls);
if(Status='PArtEdit')or((Status<>'PArtEdit')and(EnableControls<>''))then
begin
for i:=0 to ControlCount-1 do
begin
if(not(Controls[i] is TLabel))and
(not(Controls[i] is TPanel))and
(not(Controls[i] is TButton))and
(Pos(Controls[i].Name+',',EnableControls)=0)then
Controls[i].Enabled:=False
else
Controls[i].Enabled:=True;
end;
end
else
for i:=0 to ControlCount-1 do
begin
if(not(Controls[i] is TLabel))and
(not(Controls[i] is TPanel))and
(not(Controls[i] is TButton))then
Controls[i].Enabled:=True;
end;
if (AcControl<>nil)and(AcControl.Enabled) then
ActiveControl:=AcControl;
if((Status='Add')or(not ShowFlag))and(SetFocus_Control<>nil)
and(SetFocus_Control.Enabled) then
SetFocus_Control.SetFocus;
if Control<>nil then
SetOnExitEvent(Control,NotifyEvent);
if FormCaption='' then
FormCaption:=Caption;
if Status='Add' then
begin
if ExtendCaption then
Caption:=FormCaption+'-[新增]';
// Pnl_Add.Caption:='增加';
end
else
begin
if ExtendCaption then
Caption:=FormCaption+'-[修改]';
// Pnl_Add.Caption:='修改';
end;
end;
procedure TFrm_Base_Entry_Detail.Save;
begin//數據保存過程
if(Status='Add')then
begin
AdoQry_Body.Append;
end
else
begin
AdoQry_Body.Edit;
end;
SaveBodyData;
Modified:=True;
end;
procedure TFrm_Base_Entry_Detail.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
if AdoQry_Body.State=dsInsert then
AdoQry_Body.Cancel
else if AdoQry_Body.State=dsEdit then
AdoQry_Body.Post;
end;
procedure TFrm_Base_Entry_Detail.SaveBodyData;
begin
end;
procedure TFrm_Base_Entry_Detail.InitForm(AdOConnection: TAdOConnection;
FormStatus:String;HeadAdoQuery,BodyAdoQuery:TAdoQuery);
begin//定義數據庫連接,窗體狀態
SetDBConnect(AdOConnection);
Status:=FormStatus;
AdoQry_Head:=HeadAdoQuery;
AdoQry_Body:=BodyAdoQuery;
end;
procedure TFrm_Base_Entry_Detail.FormCreate(Sender: TObject);
var
i:integer;
begin//定義缺省onexit,onChange事件處理函數
inherited;
ExtendCaption:=True;
for i:=0 to ControlCount-1 do
begin
SetOnChangeEvent(Controls[i],AllChange);
SetOnEnterEvent(Controls[i],OnEnter);
end;
end;
procedure TFrm_Base_Entry_Detail.SetStatus(CurrentStatus: String;
var EnableControls: String);
begin
end;
procedure TFrm_Base_Entry_Detail.OnEnter(Sender: TObject);
begin
Changed:=False;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -