unit U_ZdyAttachCP_Type_sel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ComObj,
  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, Menus, cxLookAndFeelPainters, cxButtons;

type

  FdDy=record
               inc: integer; //客户端套接字句柄
               FDdys:string[32]; //客户端套接字
               FdDysName:string[32]; //客户端套接字
       end;
  TfrmZdyAttachCP_Type_sel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    CPName: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    ZdyCode: TEdit;
    Label2: TLabel;
    DEFstr5: TComboBox;
    OpenDialog1: TOpenDialog;
    CPNo: TEdit;
    Label4: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    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 CPNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();

  public
        fkhType:string;
    dFdDy: array[0..20] of FdDy; //客户端连接数组
  end;

var
  frmZdyAttachCP_Type_sel: TfrmZdyAttachCP_Type_sel;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}



procedure TfrmZdyAttachCP_Type_sel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select * from CP_Type order by CPNo');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmZdyAttachCP_Type_sel.FormDestroy(Sender: TObject);
begin
  frmZdyAttachCP_Type_Sel:=nil;
end;

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

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

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

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


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

procedure TfrmZdyAttachCP_Type_sel.Tv2DblClick(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;
  self.ModalResult:=1;
end;

end.


