unit U_GXGL_List_CX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit;

type
  TfrmGXGL_List_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    Label5: TLabel;
    SYRName: TEdit;
    Label1: TLabel;
    PSName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2PSName: TcxGridDBColumn;
    v2PSSH: TcxGridDBColumn;
    v2PSNote: TcxGridDBColumn;
    v2SYRName: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    vSJPSName: TcxGridDBColumn;
    Label2: TLabel;
    SJPSName: TEdit;
    Label3: TLabel;
    PSNo: TEdit;
    v2PSNo: TcxGridDBColumn;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    cxSplitter1: TcxSplitter;
    DataSource2: TDataSource;
    CDS_Tree: TClientDataSet;
    ADOQueryTree: TADOQuery;
    v2Ssel: TcxGridDBColumn;
    ADOQuery1: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ZdyNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxDBTreeList1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
    procedure initTree();

  public
    fDEFstr5:string;
  end;

var
  frmGXGL_List_CX: TfrmGXGL_List_CX;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}
procedure TfrmGXGL_List_CX.initTree();
var
  i:Integer;
begin
  try
    ADOQueryTree.DisableControls;
    with ADOQueryTree do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from GX_Dept order by DPlevel,DPOrder,DPName');
      Open;
    end;
    SCreateCDS20(ADOQueryTree,CDS_Tree);
    SInitCDSData20(ADOQueryTree,CDS_Tree);
    cxDBTreeList1.Items[0].Expand(True);
  finally
    ADOQueryTree.EnableControls;
  end;
end;

procedure TfrmGXGL_List_CX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add(' exec P_View_GXList :DPID');
      Parameters.ParamByName('DPID').Value:=Trim(CDS_Tree.fieldbyname('DPID').AsString);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  ToolButton2.Click;
end;


procedure TfrmGXGL_List_CX.FormDestroy(Sender: TObject);
begin
  frmGXGL_List_CX:=nil;
end;

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

procedure TfrmGXGL_List_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('供应商资料',Tv2,'客户自定义');
  Close;
end;
procedure TfrmGXGL_List_CX.FormShow(Sender: TObject);
begin
  ReadCxGrid('供应商资料',Tv2,'客户自定义');
  initTree();
  InitGrid();
end;

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

procedure TfrmGXGL_List_CX.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmGXGL_List_CX.ZdyNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmGXGL_List_CX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
    TcxGridToExcel(self.Caption,cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'供应商资料列表');
end;

procedure TfrmGXGL_List_CX.cxDBTreeList1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGXGL_List_CX.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.Locate('Ssel',true,[])=False then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  ModalResult:=1;
end;

end.


