unit U_ModulePromptList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxPC,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, 
   dxDateRanges, dxBarBuiltInMenu, U_BaseList;

type
  TfrmModulePromptList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column1: TcxGridDBColumn;
    Panel2: TPanel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    fDConString_link1: string;
    procedure InitGrid();
    procedure InitForm();
    procedure InitDllEvt(FromFile: string; FormID: Integer; Para: string; FormType: Integer; Title: string; Def1: string; Def2: string; Def3: string; Def4: string; Def5: string; Def6: string; Def7: string; Def8: string; Def9: string; Def10: string);
    { Private declarations }
  public
    { Public declarations }
    userID, username: string;
  end;

var
  frmModulePromptList: TfrmModulePromptList;

implementation

uses
  U_DataLink, U_RTFun;

type
  TMyF = function(App: TApplication; //主应用程序 (对Delphi而言)
    FormH: HWND;       //创建窗口的父窗口句柄 (对PB而言)
    FormID: Integer;   //要调用dll中功能窗体的Id号; 如果只有一个功能窗口，FormID默认为0
    Language: Integer; //0=Delphi; 1=PB
    WinStyle: Integer; //0=子窗口; 1：普通窗口 (PB中都为普通窗口)
    UID: PChar;        //用户Id
    UName: PChar;      //用户名
    Para: PChar; Title: PChar; Defstr1: PChar; Defstr2: PChar; Defstr3: PChar; Defstr4: PChar; Defstr5: PChar; Defstr6: PChar; Defstr7: PChar; Defstr8: PChar; Defstr9: PChar; Defstr10: PChar; Datalink: PChar): HWND; stdcall;

var
  TP: FARPROC;
  Tf: TMyF;
{$R *.dfm}

procedure TfrmModulePromptList.FormDestroy(Sender: TObject);
begin
  inherited;
  frmModulePromptList := nil;
end;

procedure TfrmModulePromptList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmModulePromptList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('工作列表', Tv1, '我的管家');
end;

procedure TfrmModulePromptList.InitGrid();
begin
  try
    //DCode:='ADMIN';
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      SQL.Add(' exec P_Chk_Tishi :DName,:DCode');
      Parameters.ParamByName('DName').Value := Trim(DName);
      Parameters.ParamByName('DCode').Value := Trim(DCode);
      //ShowMessage(DName+DCode);
      ExecSQL;
      Open;
    end;
    SCreateCDS(ADOQueryMain, Order_Main);
    SInitCDSData(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;

end;

procedure TfrmModulePromptList.InitForm();
begin
  fDConString_link1 := Trim(DConString);
  ReadCxGrid('工作列表', Tv1, '我的管家');
  InitGrid();
end;

procedure TfrmModulePromptList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmModulePromptList.FormShow(Sender: TObject);
begin
  inherited;
  InitForm();
end;

procedure TfrmModulePromptList.cxPageControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmModulePromptList.InitDllEvt(FromFile: string; FormID: Integer; Para: string; FormType: Integer; Title: string; Def1: string; Def2: string; Def3: string; Def4: string; Def5: string; Def6: string; Def7: string; Def8: string; Def9: string; Def10: string);
var
  Th: HMODULE;
begin
  Th := LoadLibrary(PChar(FromFile));
  if Th > 0 then
  begin
    TP := GetProcAddress(Th, 'GetDllForm');
    if TP <> nil then
    begin
      Tf := TMyF(Tp);
      Tf(Application, 0, FormID, 0, FormType, PChar(DCode), PChar(DName), PChar(Para), PChar(Title), PChar(Def1), PChar(Def2), PChar(Def3), PChar(Def4), PChar(Def5), PChar(Def6), PChar(Def7), PChar(Def8), PChar(Def9), PChar(Def10), pchar(fDConString_link1));
    end;
  end
  else
  begin
    Application.MessageBox(PChar('打不开文件' + FromFile + '！'), '错误', MB_ICONERROR);
  end;
end;

procedure TfrmModulePromptList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from SY_ModuleSub where ModuleId=''' + Trim(Order_Main.fieldbyname('ModuleId').AsString) + '''');
    sql.Add(' and  ModuleSubId=''' + Trim(Order_Main.fieldbyname('ModuleSubId').AsString) + '''');
//    ShowMessage(SQL.Text);
    Open;
  end;

  if not ADOQueryTemp.IsEmpty then
  begin
    InitDllEvt(Trim(ADOQueryTemp.FieldByName('formFile').AsString), ADOQueryTemp.FieldByName('FormID').AsInteger, Trim(ADOQueryTemp.FieldByName('FormPara').AsString), ADOQueryTemp.FieldByName('FormType').AsInteger, Trim(ADOQueryTemp.FieldByName('Formname').AsString), Trim(ADOQueryTemp.FieldByName('FormPara1').AsString), Trim(ADOQueryTemp.FieldByName('FormPara2').AsString), Trim(ADOQueryTemp.FieldByName('FormPara3').AsString), Trim(ADOQueryTemp.FieldByName('FormPara4').AsString), Trim(ADOQueryTemp.FieldByName
      ('FormPara5').AsString), Trim(ADOQueryTemp.FieldByName('FormPara6').AsString), Trim(ADOQueryTemp.FieldByName('FormPara7').AsString), Trim(ADOQueryTemp.FieldByName('FormPara8').AsString), Trim(ADOQueryTemp.FieldByName('FormPara9').AsString), Trim(ADOQueryTemp.FieldByName('FormPara10').AsString));
  end;

end;

end.

