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

📄 base_inner.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Base_Inner;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Panel, ActnList, ExtCtrls, ComCtrls, ToolWin, AdOdb, Db, DBGridEH,
  StdCtrls,Grids,Base_Condition,Base_Detail,ExtPrintReport,pr_PrintReportType,
  Sys_Condition,Sys_SortOrder, Sys_QuickLocate, Sys_SetColumn, Menus, Mask,
  jpeg;

Type
  TFrm_Base_Inner = Class(TFrm_Base_Panel)
    ToolButton1: TToolButton;
    TlBtn_Filter: TToolButton;
    TlBtn_Order: TToolButton;
    ToolButton9: TToolButton;
    TlBtn_Preview: TToolButton;
    TlBtn_Print: TToolButton;
    TlBtn_Excel: TToolButton;
    ToolButton13: TToolButton;
    AdoQry_Main: TAdoQuery;
    DataSource: TDataSource;
    Lbl_OrderTitle: TLabel;
    Lbl_ConditionTitle: TLabel;
    Lbl_Condition: TLabel;
    Lbl_Order: TLabel;
    DBGridEh: TDBGridEh;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ExtPrintReport: TExtPrintReport;
    TlBtn_Locate: TToolButton;
    PopuPmenu: TPopuPmenu;
    HideColumn: TMenuItem;
    procedure Act_OrderExecute(Sender: TObject);
    procedure Act_FilterExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Act_SetColumnExecute(Sender: TObject);
    procedure Act_LocateExecute(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure HideColumnClick(Sender: TObject);
  private
    { Private declarations }
    procedure SetReport;//报表打印参数设置
    procedure GetTransValue(FieldName,OldValue:String;var NewValue:String);//打印转换过程
  protected
    { protected declarations }
    OrderByFields:String;//当前排序字段信息  认大小写
    SelectFromSQL:String;//存放类似select...from...的SQL语句
    Condition:String;//存放 Where 后的条件
    ConditionUserDefine:String;//存放 Where 后的条件
    Frm_Sys_SortOrder:TFrm_Sys_SortOrder;//用于引用排序条件窗体;
    Frm_Sys_QuickLocate:TFrm_Sys_QuickLocate; //用于引用快速定位设置窗体;
    Frm_Sys_SetColumn:TFrm_Sys_SetColumn;//用于引用设置DBGridEh显示列窗体;

    procedure GetData; virtual;//由于SQL的改变,用此过程重新SQL一下
    procedure InitReport; virtual;//设置报表表头属性
    //子类重载,设置打印数据的转换过程
    procedure SetColumnsStyle(ItemIndex:Integer;FieldName:String); virtual;
    //子类重载,返回删除一行记录的SQL语句
  public
    { Public declarations }
    //初始化Form过程,子类一般都要重载   
    Frm_Sys_Condition:TFrm_Base_Condition;//用于引用条件窗体;
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);virtual;
  end;
  TAdoQueryExpress=Class(TAdoQuery)
  Public
    Property CommandTimeOut;
  end;


var
  Frm_Base_Inner: TFrm_Base_Inner;

implementation

uses Sys_Global;

{$R *.DFM}

procedure TFrm_Base_Inner.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_Inner.Act_OrderExecute(Sender: TObject);
var
  BookMArk:TBookMArk;
begin//排序字段设定处理过程
  inherited;
  if DBGridEh.DataSource.DataSet.Active=True then
  begin
    Frm_Sys_SortOrder.InitForm(DBGridEH,OrderByFields);;
    if(Frm_Sys_SortOrder.ShowModal=mrOk)then
    begin
      OrderByFields:=Frm_Sys_SortOrder.OrderFields;
      Lbl_Order.Caption:=Frm_Sys_SortOrder.OrderCaption;
      BookMArk:=AdoQry_Main.GetBookmArk;
      AdoQry_Main.Sort:=OrderByFields;
      AdoQry_Main.GotoBookmArk(BookMArk);
      AdoQry_Main.FreeBookMArk(BookMArk);
    end;
  end;
end;

procedure TFrm_Base_Inner.GetData;
begin//由于SQL的改变,用此过程重新SQL一下
  if SelectFromSQL<>'' then
  with AdoQry_Main do
  begin
    DisableControls;
    Close;
    SQL.clear;
    SQL.Text:=SelectFromSQL;
    if(Condition<>'')then
    begin
      if(ConditionUserDefine<>'')then
        SQL.Text:=SQL.Text+' Where '+Condition+' and '+ConditionUserDefine
      else
        SQL.Text:=SQL.Text+' Where '+Condition;
    end
    else if(ConditionUserDefine<>'')then
      SQL.Text:=SQL.Text+' Where '+ConditionUserDefine;
    Open;
    Sort:=OrderByFields;
    EnableControls;
  end;
end;

procedure TFrm_Base_Inner.Act_FilterExecute(Sender: TObject);
var
 TableName:string;
begin//数据过滤处理过程
  inherited;
  TableName:= '#'+self.Name   ;
  if Frm_Sys_Condition=nil then
    Frm_Sys_Condition:=TFrm_Sys_Condition.Create(Application);
  Frm_Sys_Condition.SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6);
  Frm_Sys_Condition.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
  Frm_Sys_Condition.SetDBConnect(DBConnect);

  if Frm_Sys_Condition is TFrm_Sys_Condition then
    TFrm_Sys_Condition(Frm_Sys_Condition).SetSrcGrid(DBGridEh,TableName);

  Frm_Sys_Condition.FatherForm:=Self;
  if Frm_Sys_Condition.Showmodal=mrOk then
  begin
    Condition:=Frm_Sys_Condition.Condition;
    Lbl_Condition.Caption:=Frm_Sys_Condition.ConditionHint;
    GetData;
  end;
end;

procedure TFrm_Base_Inner.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin//善后处理,释放资源
  inherited;
  try
    AdoQry_tmp.Close;
    AdoQry_tmp.SQL.clear;
    AdoQry_tmp.SQL.Text :='Drop Table '+ '#'+self.Name+','+'#'+self.Name+'Chb';
    AdoQry_tmp.ExecSQL;
  except
  end;
  if Frm_Sys_Condition<>nil then
    Frm_Sys_Condition.Release;
  if Frm_Sys_SortOrder<>nil then
    Frm_Sys_SortOrder.Release;
  if Frm_Sys_QuickLocate<>nil then
    Frm_Sys_QuickLocate.Release;
  if Frm_Sys_SetColumn<>nil then
    Frm_Sys_SetColumn.Release;
  Action:=CaFree;
end;

procedure TFrm_Base_Inner.Act_SetColumnExecute(Sender: TObject);
begin//显示列设置处理过程
  inherited;       
  Frm_Sys_SetColumn.SetUserParam(Param1,Param2,Param3,Param4,Param5,Param6);
  Frm_Sys_SetColumn.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
  Frm_Sys_SetColumn.SetDBConnect(DBConnect);
  Frm_Sys_SetColumn.SetSrcGrid(DBGridEH,self.Name);
  Frm_Sys_SetColumn.ShowModal;
end;

procedure TFrm_Base_Inner.Act_LocateExecute(Sender: TObject);
begin//快速定位处理过程
  inherited;
  Frm_Sys_QuickLocate.SetSrcGrid(DBGridEh);
  Frm_Sys_QuickLocate.Showmodal;
  if Frm_Sys_QuickLocate.ModalResult=mrok then
  begin
    AdoQry_Main.Locate(Frm_Sys_QuickLocate.LocateFieldName,Frm_Sys_QuickLocate.LocateFieldValue,[loPArtialKey]);
  end;
end;

procedure TFrm_Base_Inner.SetReport;
var
  i,j:integer;
begin
  if DBGridEh.DataSource.DataSet.Active=False then
    Abort;
  ExtPrintReport.DataSet :=nil;
  ExtPrintReport.Headers.clear;
  i:=0;
  with ExtPrintReport do
  begin
    for j:=0 to DBGridEH.Columns.Count-1 do
      if DBGridEH.Columns[j].Visible then
      begin//只打印可视的数据
        Headers.Add;
        Headers.Items[i].Caption :=DBGridEH.Columns[j].Title.Caption;
        Headers.Items[i].FieldName :=DBGridEH.Columns[j].FieldName;
        Headers.Items[i].DisplayWidth:=(DBGridEH.Columns[j].Width div (DBGridEH.Canvas.TextWidth(' ')));
        Headers.Items[i].Alignment :=DBGridEH.Columns[j].Alignment;
        if((DBGridEh.Columns[j].PickList.Count>0)and
          (DBGridEh.Columns[j].KeyList.Count>0))
          or(DBGridEh.Columns[j].Field.DataType in [ftFloat])then
        begin//定义了PickList或显示格式的传递一个转换过程
          Headers.Items[i].style:=dstransform;
          Headers.Items[i].TransformFunction:=GetTransValue;
        end
        else//通知子类
          SetColumnsStyle(i,DBGridEH.Columns[j].FieldName);
        inc(i);
      end;
    DataSet:=DBGridEh.DataSource.DataSet;
    InitReport;
  end;
end;

procedure TFrm_Base_Inner.Act_PreviewExecute(Sender: TObject);
begin//预览
  SetReport;
  ExtPrintReport.preview;
end;

procedure TFrm_Base_Inner.Act_PrintExecute(Sender: TObject);
begin//打印
  SetReport;
  ExtPrintReport.print(self);
end;

procedure TFrm_Base_Inner.SetColumnsStyle(ItemIndex:Integer;FieldName:String);
begin
end;

procedure TFrm_Base_Inner.InitReport;
begin//定义表头
  inherited;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select SysParamValueC '+
                       'From SysParam '+
                       'where SysParamCode=''Name0''';//Name0是使用本系统的客户的名称
  AdoQry_Tmp.Open;
  ExtPrintReport.Title1:=AdoQry_Tmp.fieldbyname('SysParamValueC').AsString;

  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select ReportName1,ISOCode1 '+
                       'From ReportCtrl '+
                       'where SysMenuId='+MenuId;
  AdoQry_Tmp.Open;
  ExtPrintReport.Title2:=AdoQry_Tmp.fieldbyname('ReportName1').AsString;
  ExtPrintReport.SubTitle1:=AdoQry_Tmp.fieldbyname('ISOCode1').AsString;

  ExtPrintReport.Subtitle2:=Lbl_Condition.Caption;//过滤条件}
end;

procedure TFrm_Base_Inner.FormCreate(Sender: TObject);
var
  StrTemp:String;
begin//,------>/   创建必要窗体
  inherited;
  TAdoQueryExpress(AdoQry_Main).CommandTimeOut:=0;
  StrTemp:=Lbl_Condition.Caption;
  while pos(',',StrTemp)<>0 do
    StrTemp[pos(',',StrTemp)]:='/';
  Lbl_Condition.Caption:=StrTemp;
  StrTemp:=Lbl_Order.Caption;
  while pos(',',StrTemp)<>0 do
    StrTemp[pos(',',StrTemp)]:='/';
  Lbl_Order.Caption:=StrTemp;
  Frm_Sys_SortOrder:=TFrm_Sys_SortOrder.Create(Application);
  Frm_Sys_QuickLocate:=TFrm_Sys_QuickLocate.Create(Application);
  Frm_Sys_SetColumn:=TFrm_Sys_SetColumn.Create(Application);
end;

procedure TFrm_Base_Inner.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
var i:integer;
    sqltext:string;
begin//设置数据库连接
  inherited;
  SetDBConnect(AdOConnection);
  AdoQry_Main.Connection:=AdOConnection;
  for i:=0 to toolBar.ControlCount-1 do
   if (Ttoolbutton(toolBar.controls[i]).action = act_SetColumn) and (act_SetColumn.Enabled and act_SetColumn.Visible) then
     begin
       sqltext:='select top 1 * from Sys_SetColumn '
               +' where formName='+quotedstr(self.Name)
               +'  and  useEmployeeCode='+quotedstr(userCode);
       Executesql(AdoQry_tmp,sqltext,0);
       if AdoQry_tmp.RecordCount<>0 then
       dbgrideh.FrozenCols:=AdoQry_tmp.fieldbyname('frozencols').asinteger;
     end;   
end;

procedure TFrm_Base_Inner.HideColumnClick(Sender: TObject);
begin //输出Excel
  inherited;
  if(DBGridEh.SelectedIndex>=0)then
    DBGridEh.Columns[DBGridEh.SelectedIndex].Visible:=False;
end;

end.

⌨️ 快捷键说明

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