unit U_GSList_CX;

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, cxPC, cxDropDownEdit, Menus, BtnEdit;

type
  TfrmGSList_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Tadd: TToolButton;
    DS_HZ3: TDataSource;
    CDS_HZ3: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Column1: TcxGridDBColumn;
    cxGYSName: TcxGridDBColumn;
    cxGridDBGYSNameZC: TcxGridDBColumn;
    B1GYSFZRen: TcxGridDBColumn;
    cxGridDBGYSTel: TcxGridDBColumn;
    V1SHStatus: TcxGridDBColumn;
    V1GYSCodeFW: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    PopupMenu1: TPopupMenu;
    MainEdit: TMenuItem;
    MainView: TMenuItem;
    TBFJUp1: TPopupMenu;
    BankEdit: TMenuItem;
    BankDel: TMenuItem;
    BankView: TMenuItem;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    V3BankType: TcxGridDBColumn;
    V3BankName: TcxGridDBColumn;
    V3BankNo: TcxGridDBColumn;
    V3Column3: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    TBAddBank: TMenuItem;
    V3Column1: TcxGridDBColumn;
    V1Column2: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Panel1: TPanel;
    V1Column3: TcxGridDBColumn;
    V3Column4: TcxGridDBColumn;
    V3Column5: 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 cxTabControl1Change(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure BankDelClick(Sender: TObject);
    procedure TV3DblClick(Sender: TObject);
    procedure TaddClick(Sender: TObject);
    procedure TV3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }
    ColorInt:Integer;
    procedure InitGrid();
    procedure setstatus();
    procedure InitGridBankMain();
    procedure InitGridBankMainID(FID:String);
  public
    canshu1,canshu2,FGYSType,XZKHTYpe:string;
  end;

var
  frmGSList_CX: TfrmGSList_CX;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp,U_FjList;

{$R *.dfm}
procedure TfrmGSList_CX.setstatus();
begin
  
end;

procedure TfrmGSList_CX.InitGrid();
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    SQL.Clear;
    sql.Add(' select A.* ');
    sql.Add(',SDQty=(select Count(*) from TP_File TF where TF.WBID=A.KHMainId and TF.TFType=''公司资料''  )');
    sql.Add(' from KH_Main A ');
    sql.add(' where isnull(KHFlag,'''')=''GS'' and isnull(Valid,'''')=''Y''  ');
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid='''+Trim(CDS_HZ.fieldbyname('KHMainid').asstring)+''' and isnull(Valid,'''')=''Y''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_HZ3);
  SInitCDSData20(ADOQueryTemp,CDS_HZ3);
end;

procedure TfrmGSList_CX.FormDestroy(Sender: TObject);
begin
  //frmGSList:=nil;
end;

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

procedure TfrmGSList_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('GS1',Tv1,'公司账户管理');
  WriteCxGrid('GS3',Tv3,'公司账户管理');
  Close;
end;
procedure TfrmGSList_CX.FormShow(Sender: TObject);
begin
  ReadCxGrid('GS1',Tv1,'公司账户管理');
  ReadCxGrid('GS3',Tv3,'公司账户管理');
  setstatus();
  InitGrid();
end;

procedure TfrmGSList_CX.TBRafreshClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmGSList_CX.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  InitGrid();
end;

procedure TfrmGSList_CX.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitGridBankMain();
end;

procedure TfrmGSList_CX.InitGridBankMain();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid='''+Trim(CDS_HZ.fieldbyname('KHMainid').asstring)+'''');
    if CDS_HZ.IsEmpty then
    begin
      sql.Add(' and 1=2');
    end else
    begin
      sql.Add(' and valid=''Y'' ');
    end;
    sql.Add(' order by XH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_HZ3);
  SInitCDSData20(ADOQueryTemp,CDS_HZ3);
end;
procedure TfrmGSList_CX.InitGridBankMainID(FID:String);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid='''+Trim(FID)+'''');
    if CDS_HZ.IsEmpty then
    begin
      sql.Add(' and 1=2');
    end else
    begin
      sql.Add(' and valid=''Y'' ');
    end;
    sql.Add(' order by XH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_HZ3);
  SInitCDSData20(ADOQueryTemp,CDS_HZ3);
end;


procedure TfrmGSList_CX.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  FName:string;
begin
  if CDS_HZ.IsEmpty then Exit;
  FName:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if Trim(FName)='SDQty' then
  begin
    if CDS_HZ.IsEmpty then Exit;
    try
      frmFjList:=TfrmFjList.Create(Application);
      with frmFjList do
      begin
        fkeyNO:=Trim(CDS_HZ.fieldbyname('KHMainid').AsString);
        fType:='公司资料';
        if Self.Caption='公司账户资料查询*' then
        begin
          fstatus:=1;
        end else
        begin
          fstatus:=0;
        end;

        if ShowModal=1 then
        begin

        end;
      end;
    finally
      frmFjList.Free;
    end;
  end
  else
  begin
    if cxGrid3.Visible=false then
    begin
      ModalResult:=1;
    end;
  end;
end;

procedure TfrmGSList_CX.BankDelClick(Sender: TObject);
begin
  IF CDS_HZ3.IsEmpty then exit;
 
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Sub_Bank Set Valid=''N'',DelTime=getdate(),Deler='''+Trim(DName)+''',DelerCode='''+Trim(DCode)+'''');
    sql.add('where BKID='''+Trim(CDS_HZ3.fieldbyname('BKID').AsString)+'''');
    ExecSQL;
  end;
  CDS_HZ3.Delete;
end;

procedure TfrmGSList_CX.TV3DblClick(Sender: TObject);
begin
  Tadd.Click;
end;

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

procedure TfrmGSList_CX.TV3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TADD.Click;
end;

end.


