unit U_YF_Money_Sub;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, DB, ADODB, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxCurrencyEdit, BtnEdit, StdCtrls, ExtCtrls;

type
  TFrmYF_Money_Sub = class(TForm)
    ToolBar1: TToolBar;
    TSAVE: TToolButton;
    Tclose: TToolButton;
    Panel1: TPanel;
    Label11: TLabel;
    Label9: TLabel;
    Label8: TLabel;
    Label5: TLabel;
    Label2: TLabel;
    note: TMemo;
    CRTime: TDateTimePicker;
    CRType: TBtnEditA;
    OutMoney: TcxCurrencyEdit;
    ADOQueryTMP: TADOQuery;
    ADOQueryCMD: TADOQuery;
    Label1: TLabel;
    InMoney: TcxCurrencyEdit;
    CRZY: TEdit;
    Label3: TLabel;
    FactoryName: TBtnEditA;
    Label4: TLabel;
    TOFactoryName: TBtnEditA;
    OrderNo: TBtnEditA;
    Label6: TLabel;
    procedure TcloseClick(Sender: TObject);
    procedure TSAVEClick(Sender: TObject);
    procedure CRTypeBtnClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FactoryNameBtnClick(Sender: TObject);
    procedure TOFactoryNameBtnClick(Sender: TObject);
    procedure OrderNoBtnClick(Sender: TObject);
  private
    procedure savedata();
    procedure initdata();
    { Private declarations }
  public
    fkeyNo: string;
    { Public declarations }
  end;

var
  FrmYF_Money_Sub: TFrmYF_Money_Sub;

implementation

uses U_ZDYHelpSel, U_ZDYHelp,U_Fun, U_ProductOrderNewList,U_DataLink;

{$R *.dfm}

procedure TFrmYF_Money_Sub.initdata();
begin
  with adoquerycmd do
  begin
    close;
    sql.clear;
    sql.Add('select * from YF_Money_LL ');
    sql.Add('where LLNO='+quotedstr(trim(fkeyNo)) );
    open;
    if not isempty then
    begin
      SCSHDataNew(adoquerycmd,Panel1,0);
    end;
  end;
end;

procedure TFrmYF_Money_Sub.savedata();
var
  fid:string;
begin
  try
    ADOQueryCMD.Connection.BeginTrans;
    if Trim(fkeyNo)='' then
    begin
      if GetLSNo(ADOQueryCMD,fkeyNo,'YL','YF_Money_LL',3,1)=False then
      begin
        ADOQueryCMD.Connection.RollbackTrans;
        Application.MessageBox('取流水号失败!','提示');
        Exit;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('delete from YF_Money_LL where fromMainID='''+Trim(fkeyNo)+''' ');
      execsql;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from YF_Money_LL where LLNO='''+Trim(fkeyNo)+''' ');
      Open;
      if isempty then
      begin
        append;
        fieldbyname('filler').Value:=trim(Dname);
      //  fieldbyname('filltime').Value:=SGetServerDate10(adoqueryTmp);
      end
      else
      begin
        edit;
        fieldbyname('chker').Value:=trim(Dname);
        fieldbyname('chkTime').Value:=SGetServerDate10(adoqueryTmp);
      end;
      SSetsaveSqlNew(ADOQueryCmd,'YF_Money_LL',Panel1,0);
      FieldByName('LLNO').Value:=Trim(fkeyNo);
      fieldbyname('inMoney').Value:=strtofloatdef(trim(inMoney.Text),0);
      fieldbyname('OutMoney').Value:=strtofloatdef(trim(OutMoney.Text),0);
      fieldbyname('status').Value:='0';
      Post;
    end;
    IF trim(CRType.Text)='账户互转' then
    begin
      if GetLSNo(ADOQueryCMD,fid,'YL','YF_Money_LL',3,1)=False then
      begin
        ADOQueryCMD.Connection.RollbackTrans;
        Application.MessageBox('取流水号失败!','提示');
        Exit;
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        SQL.Add('select * from YF_Money_LL where LLNO='''+Trim(fid)+''' ');
        Open;
        if isempty then
        begin
          append;
          fieldbyname('filler').Value:=trim(Dname);
      //  fieldbyname('filltime').Value:=SGetServerDate10(adoqueryTmp);
        end
        else
        begin
          edit;
          fieldbyname('chker').Value:=trim(Dname);
          fieldbyname('chkTime').Value:=SGetServerDate10(adoqueryTmp);
        end;
        SSetsaveSqlNew(ADOQueryCmd,'YF_Money_LL',Panel1,0);
        FieldByName('LLNO').Value:=Trim(fid);
        fieldbyname('factoryName').Value:=trim(TOfactoryName.Text);
        fieldbyname('TOfactoryName').Value:=trim(factoryName.Text);
        fieldbyname('inMoney').Value:=strtofloatdef(trim(OutMoney.Text),0);
        fieldbyname('OutMoney').Value:=strtofloatdef(trim(InMoney.Text),0);
        fieldbyname('status').Value:='0';
        fieldbyname('fromMainID').Value:=trim(fkeyNo);
        Post;
      end;
    end;
    ADOquerycmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  except
    ADOquerycmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TFrmYF_Money_Sub.TcloseClick(Sender: TObject);
begin
  close;
end;

procedure TFrmYF_Money_Sub.TSAVEClick(Sender: TObject);
begin
  savedata();
end;

procedure TFrmYF_Money_Sub.CRTypeBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(self);
    with frmZDYHelp do
    begin
      flag:='XJZZFLAG';
      flagname:='转账类型定义';
      if showmodal=1 then
      begin
        CRType.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  InMoney.Enabled:=true;
  IF trim(CRType.Text)='账户互转' then
  begin
    InMoney.Text:='';
    InMoney.Enabled:=false;
  end;
end;

procedure TFrmYF_Money_Sub.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  action:=cafree;
end;

procedure TFrmYF_Money_Sub.FormDestroy(Sender: TObject);
begin
  FrmYF_Money_Sub:=nil;
end;

procedure TFrmYF_Money_Sub.FormShow(Sender: TObject);
begin
  CRTime.DateTime:=SGetServerDate10(adoqueryTmp);
  initData();
end;

procedure TFrmYF_Money_Sub.FormCreate(Sender: TObject);
begin
  Panel1.Align:=alclient;
end;

procedure TFrmYF_Money_Sub.FactoryNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(self);
    with frmZDYHelp do
    begin
      flag:='XJLLFLAG';
      flagname:='账户类型定义';
      if showmodal=1 then
      begin
        FactoryName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmYF_Money_Sub.TOFactoryNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(self);
    with frmZDYHelp do
    begin
      flag:='XJLLFLAG';
      flagname:='账户类型定义';
      if showmodal=1 then
      begin
        TOFactoryName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmYF_Money_Sub.OrderNoBtnClick(Sender: TObject);
begin
  try
    frmProductOrderNewList:=TfrmProductOrderNewList.Create(Application);
    with frmProductOrderNewList do
    begin
     // DParameters1:='高权限';
      //frmProductOrderList.v1Column4.Visible:=True;
      if ShowModal=1 then
      begin
        self.OrderNo.Text:=Order_Main.fieldbyname('OrderNo').asstring;
      end;
    end;
  finally
    frmProductOrderNewList.Free;
  end;
end;

end.
