unit U_ZdyAttachment;

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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmZdyAttachment = 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;
    Label3: TLabel;
    Name: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    Code: TEdit;
    Label2: TLabel;
    Salesman: TEdit;
    ToolButton5: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Tv2Column1: TcxGridDBColumn;
    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 NameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();

  public
    fkhType:string;
    fywy,canshu1:string;

  end;

var
  frmZdyAttachment: TfrmZdyAttachment;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}



procedure TfrmZdyAttachment.InitGrid();
begin
  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from BS_Company_Main A left join BS_Company_Sub B  ');
    sql.Add(' on A.CoID=B.CoID and B.IsDefault=1 where A.CoType=''客户'' and A.Valid=''Y'' ' );
    if trim(canshu1)='业务员' then
    sql.Add(' and A.Salesman='+quotedstr(trim(dname)) );
  //  ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;


procedure TfrmZdyAttachment.FormDestroy(Sender: TObject);
begin
  frmZdyAttachment:=nil;
end;

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

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

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

procedure TfrmZdyAttachment.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 TfrmZdyAttachment.NameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmZdyAttachment.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'客户资料列表');
end;

procedure TfrmZdyAttachment.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_HZ.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmZdyAttachment.ToolButton5Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmZdyAttachment.Tv2DblClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  ModalResult:=1;
end;

end.


