unit U_PBCKCMSel;

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
  TfrmPBCKCMSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column6: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    Label1: TLabel;
    CodeName: TEdit;
    v2Column1: TcxGridDBColumn;
    v2Column3: 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 CoNameChange(Sender: TObject);
    procedure Tv2DblClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
  end;

var
  frmPBCKCMSel: TfrmPBCKCMSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmPBCKCMSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select CodeName,Spec,MF,KZ from CK_PB_CR where Valid=''Y'' ');
      sql.Add(' group by CodeName,Spec,MF,KZ having SUM(Qty*CRQtyFlag)>0 ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmPBCKCMSel.FormDestroy(Sender: TObject);
begin
  frmPBCKCMSel := nil;
end;

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

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

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

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

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

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

end.

