unit U_CompanyBankSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, U_BaseHelp, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  System.ImageList, U_BaseInput, cxContainer, cxImageList,
  dxScrollbarAnnotations, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmCompanyBankSel = class(TfrmBaseHelp)
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    ADOConnection1: TADOConnection;
    Panel1: TPanel;
    Label1: TLabel;
    GPM_1: TcxGridPopupMenu;
    ImageList1: TImageList;
    TV1Column2: TcxGridDBColumn;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    BankName: TcxTextEdit;
    cxImageList_bar: TcxImageList;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TV1DblClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure CoNamePropertiesChange(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCoCode: string;
    { Public declarations }
  end;

var
  frmCompanyBankSel: TfrmCompanyBankSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmCompanyBankSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    application.MessageBox('网络连接失败！', '提示信息');
  end;
end;

procedure TfrmCompanyBankSel.CoNamePropertiesChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  end;

end;

procedure TfrmCompanyBankSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  ToolBar1.SetFocus;

  Action := cahide;
end;

procedure TfrmCompanyBankSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*   ');
      sql.Add('from Bs_Company_Bank A  ');
      sql.Add('inner join Bs_Company  B on A.CoID=B.CoID ');
      sql.Add(' where B.CoCode=''' + Trim(FCoCode) + '''');

      Open;
    end;

    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmCompanyBankSel.FormShow(Sender: TObject);
begin
  inherited;

  InitGrid();

  ReadCxGrid(Trim(self.Caption), TV1, '自定义数据');
end;

procedure TfrmCompanyBankSel.TBCloseClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmCompanyBankSel.TBSaveClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), TV1, '自定义数据');

end;

procedure TfrmCompanyBankSel.ToolButton1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  ModalResult := 1;
end;

procedure TfrmCompanyBankSel.TV1DblClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmCompanyBankSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmCompanyBankSel := nil;
end;

end.

