⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base_entry_detail.pas

📁 一个MRPII系统源代码版本
💻 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 + -