unit U_ZdyAttachCP_HX;

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_HX = 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;
    ZdyName: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    ZdyCode: TEdit;
    Label2: TLabel;
    DEFstr5: TComboBox;
    OpenDialog1: TOpenDialog;
    defNote1: TEdit;
    Label4: TLabel;
    defnote2: TEdit;
    Label5: TLabel;
    zjm: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    defnote5: TEdit;
    Label10: TLabel;
    defstr2: TEdit;
    TSsel: TToolButton;
    ToolBar2: TToolBar;
    ToolButton9: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource1: TDataSource;
    CDS_Sub: TClientDataSet;
    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 FormCreate(Sender: TObject);
    procedure ZdyCodeKeyPress(Sender: TObject; var Key: Char);
    procedure TSselClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton9Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();

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

var
  frmZdyAttachCP_HX: TfrmZdyAttachCP_HX;
implementation
uses
  U_DataLink,U_Fun,U_Fun10,U_ZDYHelp, U_FjList_RZ;

{$R *.dfm}

procedure TfrmZdyAttachCP_HX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select  ATID,ZdyName,ZdyCode,DEFstr1,DEFstr2,defNote1,Mrate,defNote2,defNote5,DEFstr3,DEFstr5,DEFstr4,');
      sql.Add(' DEFstr6,DEFstr7,DEFstr8,Note,DEFstr4,DEFstr5,defflt1,Filler,FillTime,  ');
      sql.Add(' zdyNameZ=(select Top 1 zdyNameZ from KH_Zdy_Attachment X where X.zdyName=A.zdyName and Type=''KHName''),');
      sql.Add(' zjm=dbo.getpinyin(ZdyName) ');
      sql.Add(' from KH_Zdy_Attachment A where Type=''CPHX'' ');
      sql.Add(' order by zdyName');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
    SCreateCDS20(ADOQueryMain,CDS_Sub);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmZdyAttachCP_HX.FormDestroy(Sender: TObject);
begin
  frmZdyAttachCP_HX:=nil;
end;

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

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

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

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


procedure TfrmZdyAttachCP_HX.FormCreate(Sender: TObject);
begin
  canshu1:=trim(DParameters1);
end;

procedure TfrmZdyAttachCP_HX.ZdyCodeKeyPress(Sender: TObject;
  var Key: Char);
begin
  if Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered:=False;
        Close;
        SQL.Clear;
        sql.Add(' select  ATID,ZdyName,ZdyCode,DEFstr1,DEFstr2,defNote1,Mrate,defNote2,defNote5,DEFstr3,DEFstr5,DEFstr4,');
        sql.Add(' DEFstr6,DEFstr7,DEFstr8,Note,DEFstr4,DEFstr5,defflt1,Filler,FillTime,  ');
        sql.Add(' zdyNameZ=(select Top 1 zdyNameZ from KH_Zdy_Attachment X where X.zdyName=A.zdyName and Type=''KHName''),');
        sql.Add(' ZJM=dbo.getpinyin(ZdyName) ');
        sql.Add(' from KH_Zdy_Attachment A where Type=''CPHX'' ');
        sql.Add(' and A.ZdyCode like '''+'%'+trim(ZdyCode.Text)+'%'+'''');
        sql.Add(' order by zdyName');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_HZ);
      SInitCDSData20(ADOQueryMain,CDS_Sub);
    finally;
      ADOQueryMain.EnableControls;
    end;
  end;
end;

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

procedure TfrmZdyAttachCP_HX.Tv2CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  InitCDSToCDS(CDS_HZ,CDS_Sub);
end;

procedure TfrmZdyAttachCP_HX.ToolButton9Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then exit;
  CDS_Sub.Delete;
end;

end.


