unit U_BankInput;

interface

uses
  Windows, Messages, StrUtils, 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, cxDropDownEdit, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxDateRanges, dxBarBuiltInMenu, U_BaseList, cxContainer, dxCore,
  cxDateUtils, cxImage, cxDBEdit, IdExplicitTLSClientServerBase, cxMemo,
  U_BaseInput, System.ImageList, Vcl.ImgList, cxImageList, dxSkinsCore,
  dxSkinsDefaultPainters;

type
  TfrmBankInput = class(TfrmBaseInput)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ToolButton3: TToolButton;
    ScrollBox1: TScrollBox;
    Label6: TLabel;
    BankName: TcxTextEdit;
    GSTT: TcxTextEdit;
    Label3: TLabel;
    Label1: TLabel;
    GSDZ: TcxTextEdit;
    Label4: TLabel;
    BankDeposit: TcxTextEdit;
    Label5: TLabel;
    BankCardNo: TcxTextEdit;
    Label8: TLabel;
    YHDZ: TcxTextEdit;
    Label7: TLabel;
    YHDM: TcxTextEdit;
    Label9: TLabel;
    BankNo: TcxTextEdit;
    Label10: TLabel;
    Currency: TComboBox;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CoareaBtnDnClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
    function SaveData(): Boolean;
  public
    fFlileFlag: string;
    fkhType: string;
    { Public declarations }
    FCOID: string;
  end;

var
  frmBankInput: TfrmBankInput;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, getpic, U_YWYSel;

{$R *.dfm}

procedure TfrmBankInput.InitGrid();
begin
  try

    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * from BS_Bank where  BKID=''' + Trim(FCOID) + '''');
      Open;
    end;
    SCSHData(ADOQueryMain, ScrollBox1, 2);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBankInput.FormDestroy(Sender: TObject);
begin
  inherited;
  frmBankInput := nil;
end;

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

procedure TfrmBankInput.TBCloseClick(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmBankInput.FormShow(Sender: TObject);
begin
  inherited;
  InitGrid();

end;

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

function TfrmBankInput.SaveData(): Boolean;
var
  MaxId, MaxSubId, FCoCode, FCCID, MaxCFID: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FCOID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, MaxId, 'BK', 'BS_Bank', 4, 1) = False then
      begin
        Result := False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;

    end
    else
    begin
      MaxId := Trim(FCOID);
    end;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BS_Bank where BKID=''' + Trim(FCOID) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FCOID) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('BKID').Value := Trim(MaxId);
      RTSetsavedata(ADOQueryCmd, 'BS_Bank', ScrollBox1, 2);
      Post;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    FCCID := Trim(MaxSubId);
    Result := True;
  except
    Result := false;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;
end;

procedure TfrmBankInput.ToolButton3Click(Sender: TObject);
begin

  if SaveData() then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
  end;
end;

procedure TfrmBankInput.CoareaBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

end.

