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

📄 base_entry_body.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Base_Entry_Body;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Panel, ActnList, ExtCtrls, ComCtrls, ToolWin, AdOdb, Db, DBGridEH,
  StdCtrls,Grids,Base_Condition,Sys_SortOrder,Sys_Condition,Base_Entry_Detail,ExtPrintReport, DBCtrls,
  pr_PrintReportType, jpeg;

Type
  TFrm_Base_Entry_Body = Class(TFrm_Base_Panel)
    TlBtn_InsertLine: TToolButton;
    TlBtn_Modify: TToolButton;
    TlBtn_DeleteLine: TToolButton;
    TlBtn_Preview: TToolButton;
    TlBtn_Print: TToolButton;
    TlBtn_Excel: TToolButton;
    AdoQry_Body: TAdoQuery;
    DataSource: TDataSource;
    DBGridEh: TDBGridEh;
    ToolButton2: TToolButton;
    ToolButton4: TToolButton;
    TlBtn_Locate: TToolButton;
    Act_None: TAction;
    ToolButton1: TToolButton;
    ToolButton5: TToolButton;
    ToolButton3: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ExtPrintReport: TExtPrintReport;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    procedure Act_ModifyExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure AllChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Act_InsertLineExecute(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure DBGridEhDblClick(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure OnEnter(Sender: TObject);
    procedure Act_FilterExecute(Sender: TObject);
    procedure Act_OrderExecute(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
  private
    { Private declarations }
    EnableControls:String;
    
    procedure AllCheck;
    procedure FormInitControls; 
    procedure SetReport;
    procedure GetTransValue(FieldName,OldValue:String;var NewValue:String);
  protected
    { protected declarations }
    //窗体OnShow{窗体刚弹出时}时ShowFlag=False,否则ShowFlag:=True;
    OrderByFields:String;//当前排序字段信息  认大小写
    ShowFlag,Changed:Boolean;
    //窗体标题,基类会在其后再加上如:'新增/修改/查询'的字样
    //(当ExtendCaption=True[默认]时是这样的)
    FormCaption:String;
    ExtendCaption:Boolean;
    //标识当前Form状态
    //修改Edit -->AllEdit[可插入,删除行]全部可改,
    //修改Edit -->PArtEdit部分可改[不可插入,删除行],ReadOnly只读
    //新增Add  -->新增Add[可插入,删除行]
    //查询Query-->ReadOnly只读
    Frm_Sys_Condition:TFrm_Base_Condition;//用于引用条件窗体;
    Frm_Sys_SortOrder:TFrm_Sys_SortOrder;//用于引用排序设置窗体;
    Status:String;
    //数据库维护对象[表头]
    AdoQry_Head:TAdoQuery;
    //增加时要聚焦的控件,一般是最上面的那个,子类在InitControls的inherited之前设置
    SetFocus_Control:TWinControl;
    //用于引用弹出窗体;基类可据此进行控制
    //设置各种状态下那些控件Enable,
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,
      EnableControls:String); virtual;
    //初始化Form上所有控件  
    procedure InitControls; virtual;
    //把表头控件值写入缓存,不要Post
    procedure SaveHeadData; virtual;
    //把表头缓存写入数据库,事务处理+SQL语句
    procedure SaveData; virtual;
    //设置报表表头属性
    procedure InitReport; virtual;
    //子类重载,设置打印数据的转换过程
    procedure SetColumnsStyle(ItemIndex:Integer;FieldName:String); virtual;
  public
    { Public declarations }
    //初始化参数(TAdOConnection) 变量   
    Frm_Entry_Detail:TFrm_Base_Entry_Detail;
    procedure InitForm(AdOConnection:TAdOConnection;FormStatus:String;
      AdoQuery:TAdoQuery); virtual;
  end;
  TAdoQueryExpress=Class(TAdoQuery)
  Public
    Property CommandTimeOut;
  end;



var
  Frm_Base_Entry_Body: TFrm_Base_Entry_Body;

implementation

uses Sys_Global;

{$R *.DFM}
procedure TFrm_Base_Entry_Body.GetTransValue(FieldName,OldValue:String;var NewValue:String);
var
  i:integer;
begin
  NewValue:=OldValue;
  if DBGridEh<>nil then
    for i:=0 to DBGridEh.Columns.Count-1 do
      if(DBGridEh.Columns[i].FieldName=FieldName)then
      begin
        if(DBGridEh.Columns[i].Field.DataType in [ftFloat])
          and(TFloatField(DBGridEh.Columns[i].Field).DisplayFormat<>'')
          and(OldValue<>'')then
        begin//转换定义了格式显示的数据
          NewValue:=FormatFloat(TFloatField(DBGridEh.Columns[i].Field).DisplayFormat,StrToFloat(OldValue));
        end
        else if DBGridEh.Columns[i].KeyList.IndexOf(OldValue)<>-1 then
        begin//转换有pickList,keyList对应关系的数据
          NewValue:=DBGridEh.Columns[i].PickList.Strings[DBGridEh.Columns[i].
            KeyList.IndexOf(OldValue)];
        end;
        break;
      end;
end;

procedure TFrm_Base_Entry_Body.Act_ModifyExecute(Sender: TObject);
begin//
  inherited;
  //焦点定位在当前行
  ActiveControl:=DBGridEh;
  //表头控件值写入缓存,有利于第三窗体通过AdoQry_Head取值
  SaveHeadData;
  //子类没定义弹出窗体,或者表体没有数据都不能进行修改的
  if(Frm_Entry_Detail<>nil)and(not AdoQry_Body.IsEmpty)then
  begin
    //参数传入,弹出窗体子类使用这些参数,就像使用全局变量一样
    Frm_Entry_Detail.SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6);
    Frm_Entry_Detail.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
    //是否修改 状态传入
    Frm_Entry_Detail.Modified:=Act_Save.Enabled;
    //修改状态
    if (Status='Add')or(Status='AllEdit') then
      Frm_Entry_Detail.InitForm(DBConnect,'AllEdit',AdoQry_Head,AdoQry_Body)
    else
      Frm_Entry_Detail.InitForm(DBConnect,'PArtEdit',AdoQry_Head,AdoQry_Body);
    Frm_Entry_Detail.ShowModal;
    //是否修改 状态传出
    Act_Save.Enabled:=Frm_Entry_Detail.Modified;
  end;
end;

procedure TFrm_Base_Entry_Body.InitForm(AdOConnection:TAdOConnection;
  FormStatus:String;AdoQuery:TAdoQuery);
begin//定义数据库连接
  inherited;
  SetDBConnect(AdOConnection);
  AdoQry_Body.Connection:=AdOConnection;
  Status:=FormStatus;
  AdoQry_Head:=AdoQuery;
end;

procedure TFrm_Base_Entry_Body.SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);
begin
  inherited;
end;

procedure TFrm_Base_Entry_Body.InitControls;
var
  i:Integer;
  Control:TControl;
  AcControl:TWinControl;
  NotifyEvent:TNotifyEvent;
begin//控件值初始化
  if GetOnExitEvent(ActiveControl,NotifyEvent) then
    Control:=ActiveControl
  else
    Control:=nil;
  AcControl:=ActiveControl;
  ActiveControl:=ControlBar;
  EnableControls:='';
  SetStatus(Status,Status,EnableControls);
  if(Status='Query')then
    Status:='ReadOnly'
  else if(Status='Edit')then
    Status:='AllEdit';
  if(Status='ReadOnly')then
    EnableControls:='';
  if(Status<>'Add')then
    for i:=0 to Pnl_Head.ControlCount-1 do
    begin
      if(not(Pnl_Head.Controls[i] is TLabel))and
        (Pos(Pnl_Head.Controls[i].Name+',',EnableControls)=0)then
        Pnl_Head.Controls[i].Enabled:=False
      else
        Pnl_Head.Controls[i].Enabled:=True;
    end
  else
    for i:=0 to Pnl_Head.ControlCount-1 do
    begin
      if(not(Pnl_Head.Controls[i] is TLabel))then
        Pnl_Head.Controls[i].Enabled:=True;
    end;

  if (Status='PArtEdit')then
  begin
    Act_InsertLine.Enabled:=False;
    Act_DeleteLine.Enabled:=False;
    Act_Modify.Enabled:=True;
    Act_Hint.Enabled:=True;
  end
  else if(Status='Add')or(Status='AllEdit')then
  begin
    Act_InsertLine.Enabled:=True;
    Act_DeleteLine.Enabled:=True;
    Act_Modify.Enabled:=True;
    Act_Hint.Enabled:=True;
  end
  else if Status='ReadOnly' then
  begin
    Act_InsertLine.Enabled:=False;
    Act_DeleteLine.Enabled:=False;
    Act_Modify.Enabled:=False;
    Act_Hint.Enabled:=False;
  end;
  if (AcControl<>nil)and(AcControl.Enabled) then
    ActiveControl:=AcControl;
  if (SetFocus_Control<>nil)and(SetFocus_Control.Enabled) then
    ActiveControl:=SetFocus_Control;
  if Control<>nil then
    SetOnExitEvent(Control,NotifyEvent);
  if ShowFlag=False then
    Act_New.Enabled:=False;

  if FormCaption='' then
    FormCaption:=Caption;
  if ExtendCaption then
  begin
    if(Status='Add')then
    begin
      Caption:=FormCaption+'-[新增]';
      Pnl_Title.Caption:=FormCaption;
    end
    else if(Status='PArtEdit')or(Status='AllEdit')then
    begin
      Caption:=FormCaption+'-[修改]';
      Pnl_Title.Caption:=FormCaption;
    end
    else if(Status='ReadOnly')then
    begin
      Caption:=FormCaption+'-[查询]';
      Pnl_Title.Caption:=FormCaption;
    end;
  end;
end;

procedure TFrm_Base_Entry_Body.FormCreate(Sender: TObject);
var
  i:Integer;
begin//
  inherited;
  TAdoQueryExpress(AdoQry_Body).CommandTimeOut:=0;
  ExtendCaption:=True;//允许扩展标题"新增/查询/修改"
  for i:=0 to Pnl_Head.ControlCount-1 do
  begin//给Pnl_Head上没有定义OnChange处理的控件使其OnChange:=AllChange;
    SetOnChangeEvent(Pnl_Head.Controls[i],AllChange);
    SetOnEnterEvent(Pnl_Head.Controls[i],OnEnter);
  end;
  Frm_Sys_SortOrder:=TFrm_Sys_SortOrder.Create(Application);
end;

procedure TFrm_Base_Entry_Body.FormDestroy(Sender: TObject);
begin//释放空间
  inherited;
  if Frm_Sys_Condition<>nil then
    Frm_Sys_Condition.Release;
  if Frm_Entry_Detail<>nil then
    Frm_Entry_Detail.Release;
  if Frm_Sys_SortOrder<>nil then
    Frm_Sys_SortOrder.Release;
end;

procedure TFrm_Base_Entry_Body.SaveHeadData;
begin
end;

procedure TFrm_Base_Entry_Body.AllChange(Sender: TObject);
begin//窗体上控件值改变时
  inherited;
  Act_Save.Enabled:=True;
  Changed:=True;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -