unit U_ZdyAttachKH;

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, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
  dxSkinscxPCPainter, cxNavigator;

type
  TfrmZdyAttachkh = 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;
    KHNameJC: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    KHNo: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1KHNo: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1KHLXR: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    cxGrid1Level1: 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 KHNameJCChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
  end;

var
  frmZdyAttachkh: TfrmZdyAttachkh;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmZdyAttachkh.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('select *,zjm=dbo.getpinyin(KHName)  ');
      sql.Add(' from KH_Main A  ');
      sql.Add(' where isnull(KHFlag,'''')=''KH'' and isnull(Valid,'''')=''Y''');
      Open;
    end;

    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  ToolButton2.Click;
end;

procedure TfrmZdyAttachkh.FormDestroy(Sender: TObject);
begin
  frmZdyAttachkh := nil;
end;

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

procedure TfrmZdyAttachkh.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('供应商资料', Tv1);
  Close;
end;

procedure TfrmZdyAttachkh.FormShow(Sender: TObject);
begin
  ReadCxGrid('供应商资料', Tv1);
  InitGrid();
end;

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

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

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

end.

