unit U_UserModuleNameList;   //

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, cxCalendar, cxButtonEdit, cxDropDownEdit,
  DBClient, Menus, cxSplitter, cxTextEdit, RM_Common, RM_Class,
  RM_GridReport, RM_System, RM_Dataset, RM_e_Xls, dxPSGlbl, dxPSUtl,
  dxPSEngn, dxPrnPg, dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider,
  dxPSFillPatterns, dxPSEdgePatterns, dxPSCore, dxPScxCommon, dxPScxGridLnk,
  cxPC;

type
  TfrmUserModuleNameList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Panel1: TPanel;
    CDS_Main: TClientDataSet;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1ShortName: TcxGridDBColumn;
    v1UnitName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Quantity: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource3: TDataSource;
    ClientDataSet3: TClientDataSet;
    cxGridPopupMenu3: TcxGridPopupMenu;
    Panel2: TPanel;
    Label1: TLabel;
    FormName: TEdit;
    Panel3: TPanel;
    Label2: TLabel;
    DFormName: TEdit;
    Panel4: TPanel;
    Label3: TLabel;
    UserId: TEdit;
    Label4: TLabel;
    FormNameNote: TEdit;
    Label5: TLabel;
    DPName: TEdit;
    Label6: TLabel;
    UserName: TEdit;
    Label7: TLabel;
    UDPName: TEdit;
    Label8: TLabel;
    UFormName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure UserIdChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxPageControl1Change(Sender: TObject);
  private
    canshu1,canshu2:String;
    procedure InitGrid();
    procedure InitForm();

    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmUserModuleNameList: TfrmUserModuleNameList;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmUserModuleNameList.FormDestroy(Sender: TObject);
begin
  frmUserModuleNameList:=nil;
end;

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

procedure TfrmUserModuleNameList.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
  canshu2:=Trim(DParameters2);
end;

procedure TfrmUserModuleNameList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('员工模块列表',Tv1,'系统管理');
  WriteCxGrid('部门模块列表',Tv2,'系统管理');
  WriteCxGrid('模块列表',Tv3,'系统管理');
end;

procedure TfrmUserModuleNameList.InitGrid();
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    sql.Clear;
    if cxPageControl1.ActivePageIndex=0 then
    begin
      SQL.Add(' exec P_View_ModuleName ');
    end else
    if cxPageControl1.ActivePageIndex=1 then
    begin
      SQL.Add(' exec P_View_DeptModuleName ');
    end else
    if cxPageControl1.ActivePageIndex=2 then
    begin
      SQL.Add(' exec P_View_UserModuleName ');
    end;
    Open;
  end;
  SCreateCDS(ADOQueryMain,CDS_Main);
  SInitCDSData(ADOQueryMain,CDS_Main);
end;

procedure TfrmUserModuleNameList.InitForm();
begin
  ReadCxGrid('员工模块列表',Tv1,'系统管理');
  ReadCxGrid('部门模块列表',Tv2,'系统管理');
  ReadCxGrid('模块列表',Tv3,'系统管理');
  cxPageControl1.ActivePageIndex:=0;
  //InitGrid();
end;

procedure TfrmUserModuleNameList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  if cxPageControl1.ActivePageIndex=0 then
    SDofilter(ADOQueryMain,SGetFilters(Panel2,1,2))
  else if cxPageControl1.ActivePageIndex=1 then
    SDofilter(ADOQueryMain,SGetFilters(Panel3,1,2))
  else if cxPageControl1.ActivePageIndex=2 then
    SDofilter(ADOQueryMain,SGetFilters(Panel4,1,2));
  SCreateCDS(ADOQueryMain,CDS_Main);
  SInitCDSData(ADOQueryMain,CDS_Main);
end;

procedure TfrmUserModuleNameList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  if cxPageControl1.ActivePageIndex=0 then
    TcxGridToExcel('模块列表',cxGrid3)
  else if cxPageControl1.ActivePageIndex=1 then
    TcxGridToExcel('部门模块列表',cxGrid2)
  else if cxPageControl1.ActivePageIndex=2 then
    TcxGridToExcel('员工模块列表',cxGrid1);
end;

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



procedure TfrmUserModuleNameList.UserIdChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  if cxPageControl1.ActivePageIndex=0 then
    SDofilter(ADOQueryMain,SGetFilters(Panel2,1,2))
  else if cxPageControl1.ActivePageIndex=1 then
    SDofilter(ADOQueryMain,SGetFilters(Panel3,1,2))
  else if cxPageControl1.ActivePageIndex=2 then
    SDofilter(ADOQueryMain,SGetFilters(Panel4,1,2));
  SCreateCDS(ADOQueryMain,CDS_Main);
  SInitCDSData(ADOQueryMain,CDS_Main);
end;

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


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

end.
