unit U_BankMoneyQCInPut;

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, BtnEdit;

type
  TfrmBankMoneyQCInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    ToolButton4: TToolButton;
    Label4: TLabel;
    Note: TEdit;
    Label11: TLabel;
    BKNO: TBtnEditC;
    Label13: TLabel;
    HuMingJC: TEdit;
    Label12: TLabel;
    YuMoneyMJ: TEdit;
    Label1: TLabel;
    YuMoneyRMB: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    CRTime: TDateTimePicker;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure BKNOBtnUpClick(Sender: TObject);
    procedure BKNOBtnDnClick(Sender: TObject);
  private
    { Private declarations }

    procedure InitData();
    function  SaveData():Boolean;

  public
    { Public declarations }
    FMainId:String;

  end;

var
  frmBankMoneyQCInPut: TfrmBankMoneyQCInPut;

implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_GSListBankSel;

{$R *.dfm}



procedure TfrmBankMoneyQCInPut.InitData();
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    SQL.Clear;
    sql.Add(' select A.*,B.BankNo,B.BankName,B.HuMingJC ');
    sql.Add('  from YS_Money_CR A');
    sql.Add(' left join KH_Sub_Bank B on A.BKNO=B.BKNO');
    sql.Add(' left join KH_Main C on B.KHMainId=C.KHMainId');
    sql.Add(' where YFID='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQueryMain,Panel1,2);
  SCSHDataNew(ADOQueryMain,Panel1,0);
end;


procedure TfrmBankMoneyQCInPut.FormDestroy(Sender: TObject);
begin
  frmBankMoneyQCInPut:=nil;
end;

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

procedure TfrmBankMoneyQCInPut.TBCloseClick(Sender: TObject);
begin
  Close;
end;
procedure TfrmBankMoneyQCInPut.FormShow(Sender: TObject);
begin
  CRTime.Date:=SGetServerDate(ADOQueryTemp);
  if Trim(FMainId)<>'' then
  begin
    InitData();
  end;
end;

function TfrmBankMoneyQCInPut.SaveData():Boolean;
var
  maxId:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(FMainId)+'''');
      Open;
    end;
    FMainId:=Trim(ADOQueryCmd.fieldbyname('YFID').AsString);
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOQueryCmd,maxId,'YU','YS_Money_CR',4,1)=False then
      begin
        Result:=False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！','提示',0);
        Exit;
      end;
    end else
    begin
      maxId:=FMainId;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_CR where YFID='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
        FieldByName('ChkStatusP').Value:='已审核';
      end else
      begin
        Edit;
      end;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='账户期初余额登记';
      FieldByName('CRFlag').Value:='账户流水';
      FieldByName('QtyFlag').Value:=1;
      RTSetsavedata(ADOQueryCmd,'YS_Money_CR',Panel1,2);
      Post;
    end;
    FMainId:=Trim(maxId);
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBankMoneyQCInPut.ToolButton4Click(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  if Trim(BKNO.Text)='' then
  begin
    Application.MessageBox('收款账号编号不能为空!','提示',0);
    Exit;
  end;
  if Trim(YuMoneyMJ.Text)='' then
  begin
    if Trim(YuMoneyRMB.Text)='' then
    begin
      Application.MessageBox('余额不能为空!','提示',0);
      Exit;
    end;
  end;
  if Trim(YuMoneyMJ.Text)<>'' then
  begin
    if TryStrToFloat(YuMoneyMJ.Text,FReal)=False then
    begin
      Application.MessageBox('美金余额非法数字!','提示',0);
      Exit;
    end;
  end;
  if Trim(YuMoneyRMB.Text)<>'' then
  begin
    if TryStrToFloat(YuMoneyRMB.Text,FReal)=False then
    begin
      Application.MessageBox('人民币余额非法数字!','提示',0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要保存数据吗？','提示',32+4)<>IDYES then Exit;
  if SaveData() then
  begin
    Application.MessageBox('保存成功!','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmBankMoneyQCInPut.BKNOBtnUpClick(Sender: TObject);
begin
  try
    frmGSListBankSel:=TfrmGSListBankSel.Create(Application);
    with frmGSListBankSel do
    begin
      if ShowModal=1 then
      begin
        BKNO.Text:=Trim(frmGSListBankSel.CDS_HZ3.fieldbyname('BKNO').AsString);
        BKNO.TxtCode:=Trim(frmGSListBankSel.CDS_HZ.fieldbyname('KHNO').AsString);
        HuMingJC.Text:=Trim(frmGSListBankSel.CDS_HZ3.fieldbyname('HuMingJC').AsString);
      end;
    end;
  finally
    frmGSListBankSel.Free;
  end;
end;

procedure TfrmBankMoneyQCInPut.BKNOBtnDnClick(Sender: TObject);
begin
  BKNO.Text:='';
  BKNO.TxtCode:='';
  HuMingJC.Text:='';
end;

end.
