unit U_BankMoneyGYSInPut;

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
  TfrmBankMoneyGYSInPut = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton4: TToolButton;
    Label4: TLabel;
    Note: TEdit;
    Label12: TLabel;
    JSMoney: TEdit;
    Label3: TLabel;
    CRTime: TDateTimePicker;
    FactoryName: TBtnEditC;
    Label5: TLabel;
    Label6: TLabel;
    YFName: TBtnEditC;
    Label7: TLabel;
    ADOQueryMain: TADOQuery;
    CRType1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    CRType2: TEdit;
    Label10: TLabel;
    ConNo: TEdit;
    Label11: TLabel;
    CRType4: TEdit;
    Label8: TLabel;
    CRType3: TEdit;
    CRType5: TEdit;
    Label9: TLabel;
    Label13: TLabel;
    CRType6: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure FactoryNameBtnUpClick(Sender: TObject);
    procedure FactoryNameBtnDnClick(Sender: TObject);
    procedure YFNameBtnUpClick(Sender: TObject);
    procedure YFNameBtnDnClick(Sender: TObject);
    procedure CRType1Click(Sender: TObject);
    procedure CRType2Click(Sender: TObject);
    procedure CRType4Click(Sender: TObject);
    procedure CRType3Click(Sender: TObject);
    procedure CRType5Click(Sender: TObject);
    procedure CRType6Click(Sender: TObject);
  private
    { Private declarations }
    FKType:string;
    procedure InitData();
    function  SaveData():Boolean;

  public
    { Public declarations }
    FMainId:String;

  end;

var
  frmBankMoneyGYSInPut: TfrmBankMoneyGYSInPut;

implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_GSListBankSel,U_GYSListSelJJ;

{$R *.dfm}



procedure TfrmBankMoneyGYSInPut.InitData();
var
  FFYFName:String;
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;
  FFYFName:=Trim(ADOQueryMain.fieldbyname('FKType').AsString);

  SCSHDataNew(ADOQueryMain,Panel1,2);
  SCSHDataNew(ADOQueryMain,Panel1,0);
  if FFYFName='自付' then
  begin
     CRType1.text:='√';
     CRType2.Text:='';
     CRType3.Text:='';
     CRType4.Text:='';
     CRType5.Text:='';
     CRType6.Text:='';
  end
  else if FFYFName='供应商垫付' then
  begin
     CRType1.Text:='';
     CRType2.Text:='√';
     CRType3.Text:='';
     CRType4.Text:='';
     CRType5.Text:='';
     CRType6.Text:='';
  end
  else if FFYFName='扣款' then
  begin
     CRType1.Text:='';
     CRType2.Text:='';
     CRType3.Text:='';
     CRType4.Text:='√';
     CRType5.Text:='';
     CRType6.Text:='';
  end
  else if FFYFName='补税点' then
  begin
     CRType1.Text:='';
     CRType2.Text:='';
     CRType3.Text:='√';
     CRType4.Text:='';
     CRType5.Text:='';
     CRType6.Text:='';
  end
  else if FFYFName='本公司代付' then
  begin
     CRType1.Text:='';
     CRType2.Text:='';
     CRType3.Text:='';
     CRType4.Text:='';
     CRType5.Text:='√';
     CRType6.Text:='';
  end
  else if FFYFName='冲红' then
  begin
     CRType1.Text:='';
     CRType2.Text:='';
     CRType3.Text:='';
     CRType4.Text:='';
     CRType5.Text:='';
     CRType6.Text:='√';
  end;
end;


procedure TfrmBankMoneyGYSInPut.FormDestroy(Sender: TObject);
begin
  frmBankMoneyGYSInPut:=nil;
end;

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

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

function TfrmBankMoneyGYSInPut.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:='未审核';
        FieldByName('Filler').Value:=Trim(DName);
      end else
      begin
        Edit;
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('YFID').Value:=Trim(maxId);

      FieldByName('CRType').Value:='供应商费用管理';
      FieldByName('CRFlag').Value:='费用管理';
      FieldByName('BZType').Value:='￥';
      if Trim(CRType1.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType1.Hint);
        FieldByName('QtyFlag').Value:=0;
      end else
      if Trim(CRType2.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType2.Hint);
        FieldByName('QtyFlag').Value:=1;
      end else
      if Trim(CRType3.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType3.Hint);
        FieldByName('QtyFlag').Value:=1;
      end else
      if Trim(CRType4.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType4.Hint);
        FieldByName('QtyFlag').Value:=-1;
      end else
      if Trim(CRType5.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType5.Hint);
        FieldByName('QtyFlag').Value:=-1;
      end else
      if Trim(CRType6.Text)<>'' then
      begin
        FieldByName('FKType').Value:=Trim(CRType6.Hint);
        FieldByName('QtyFlag').Value:=-1;
      end;
      FieldByName('FactoryNo').Value:=Trim(FactoryName.TxtCode);
      RTSetsavedata(ADOQueryCmd,'YS_Money_CR',Panel1,2);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate YS_Money_CR Set Money=JSMoney where YFID='''+Trim(maxId)+'''');
      ExecSQL;
    end;
    FMainId:=Trim(maxId);
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!','提示',0);
  end;
end;

procedure TfrmBankMoneyGYSInPut.ToolButton4Click(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.SetFocus;
  if Trim(FactoryName.Text)='' then
  begin
      Application.MessageBox('供应商不能为空!','提示',0);
      Exit;
  end;
  if Trim(JSMoney.Text)<>'' then
  begin
    if TryStrToFloat(JSMoney.Text,FReal)=False then
    begin
      Application.MessageBox('金额非法数字!','提示',0);
      Exit;
    end;
    {if StrToFloat(JSMoney.Text)<0 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 TfrmBankMoneyGYSInPut.FactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmGYSListSelJJ:=TfrmGYSListSelJJ.Create(Application);
    with frmGYSListSelJJ do
    begin
      frmGYSListSelJJ.canshu2:='高权限';
      if ShowModal=1 then
      begin
        FactoryName.Text:=Trim(frmGYSListSelJJ.CDS_HZ.fieldbyname('KHNameJC').AsString);
        FactoryName.TxtCode:=Trim(frmGYSListSelJJ.CDS_HZ.fieldbyname('KHNO').AsString);
      end;
    end;
  finally
    frmGYSListSelJJ.Free;
  end;
end;

procedure TfrmBankMoneyGYSInPut.FactoryNameBtnDnClick(Sender: TObject);
begin
  FactoryName.Text:='';
end;

procedure TfrmBankMoneyGYSInPut.YFNameBtnUpClick(Sender: TObject);
begin
   try
      frmZDYHelp:=TfrmZDYHelp.Create(Application);
      with frmZDYHelp do
      begin
        flag:='YFNameGYS';
        flagname:='项目摘要';
        if ShowModal=1 then
        begin
          YFName.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
end;

procedure TfrmBankMoneyGYSInPut.YFNameBtnDnClick(Sender: TObject);
begin
  yfname.Text:='';
end;

procedure TfrmBankMoneyGYSInPut.CRType1Click(Sender: TObject);
begin
  CRType1.Text:='√';
  CRType2.Text:='';
  CRType3.Text:='';
  CRType4.Text:='';
  CRType5.Text:='';
  CRType6.Text:='';
  FKType:='自付';
end;

procedure TfrmBankMoneyGYSInPut.CRType2Click(Sender: TObject);
begin
  CRType1.Text:='';
  CRType2.Text:='√';
  CRType3.Text:='';
  CRType4.Text:='';
  CRType5.Text:='';
  CRType6.Text:='';
  FKType:='供应商垫付';
end;

procedure TfrmBankMoneyGYSInPut.CRType4Click(Sender: TObject);
begin
  CRType1.Text:='';
  CRType2.Text:='';
  CRType3.Text:='';
  CRType4.Text:='√';
  CRType5.Text:='';
  CRType6.Text:='';
  FKType:='扣款';
end;

procedure TfrmBankMoneyGYSInPut.CRType3Click(Sender: TObject);
begin
  CRType1.Text:='';
  CRType2.Text:='';
  CRType3.Text:='√';
  CRType4.Text:='';
  CRType5.Text:='';
  CRType6.Text:='';
  FKType:='补税点';
end;

procedure TfrmBankMoneyGYSInPut.CRType5Click(Sender: TObject);
begin
  CRType1.Text:='';
  CRType2.Text:='';
  CRType3.Text:='';
  CRType4.Text:='';
  CRType5.Text:='√';
  CRType6.Text:='';
  FKType:='本公司代付';
end;

procedure TfrmBankMoneyGYSInPut.CRType6Click(Sender: TObject);
begin
  CRType1.Text:='';
  CRType2.Text:='';
  CRType3.Text:='';
  CRType4.Text:='';
  CRType5.Text:='';
  CRType6.Text:='√';
  FKType:='冲红';
end;

end.
