unit U_YSCRPB_ZHYH;

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;

type
  TfrmYSCRPB_ZHYH = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    YFName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxYFName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    VSRMoney: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    Label7: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    CheckBox1: TCheckBox;
    Tchk: TToolButton;
    Tnochk: TToolButton;
    cxTabControl1: TcxTabControl;
    v2BankName: TcxGridDBColumn;
    TZDSC: TToolButton;
    Label11: TLabel;
    Label13: TLabel;
    Label5: TLabel;
    Note: TEdit;
    ADOQuery1: TADOQuery;
    Label3: TLabel;
    Label9: TLabel;
    FactoryName: TEdit;
    v2CRFlag: TcxGridDBColumn;
    v2IFSC: TcxGridDBColumn;
    Label8: TLabel;
    v2ZCMoney: TcxGridDBColumn;
    Label10: TLabel;
    IFSC: TComboBox;
    CRFlag: TComboBox;
    TSsel: TToolButton;
    v2YEMoney: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v2FKTaiTou: TcxGridDBColumn;
    Label4: TLabel;
    FKTaiTou: TEdit;
    BankName: TComboBox;
    v2BZType: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CRFlagChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure cxGridDBColumn8PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2PSPropertiesEditValueChanged(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2KPMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure v2ComTaitouPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TZDSCClick(Sender: TObject);
    procedure VBZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column5PropertiesChange(Sender: TObject);
    procedure v2ConNoHZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2GYSNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2BankNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure TSselClick(Sender: TObject);
    procedure VSRMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure v2ZCMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure v2FKTaiTouPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2BZTypePropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function  SaveData():Boolean;
    procedure SetStatus();

  public

    fflag:integer;
    { Public declarations }
    RKFlag,FCYID,canshu1,canshu2,canshu3:String;
    fmanage:string;

  end;

var
  frmYSCRPB_ZHYH: TfrmYSCRPB_ZHYH;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_ProductOrderNewList, U_ProductOrderList,
  U_ZdyAttachment, U_SXCKNewList, U_SXCKNewList_SK,U_JYOrderCon_CX,
  U_ZdyAttachGYS,U_FKCR;

{$R *.dfm}
procedure TfrmYSCRPB_ZHYH.SetStatus();
var i:integer;
begin
  Tchk.Enabled:=false;
  TNochk.Enabled:=false;
  for i:=0 to tv2.ColumnCount-1 do
  begin
    IF uppercase(tv2.Columns[i].DataBinding.FieldName)<>'SSEL' then
    tv2.Columns[i].Options.Editing:=false;
  end;
    if cxTabControl1.TabIndex=0 then
    begin
      Tchk.Enabled:=true;
      for i:=0 to tv2.ColumnCount-1 do
      begin
        tv2.Columns[i].Options.Editing:=true;
      end;
    end;
    if cxTabControl1.TabIndex=1 then
    begin
      TNochk.Enabled:=true;
    end;
    if cxTabControl1.TabIndex=2 then
    begin
    end;
end;

procedure TfrmYSCRPB_ZHYH.InitGrid();
var FMoney,FUSDMoney:double;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select Sum(Money*QtyFlag) YEMoney ');
      sql.add('from YF_Money_CR A ');
      sql.add('where CRTime<'''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+'''');
      sql.add(' and CRType=''其他款项'' ');
      if trim(CanShu3)<>'' then
      begin
        sql.add(' and (CRFlag='''+trim(CanShu3)+''' or YFName=''退款'')');
      end
      else
      begin
        if CRFlag.Text<>'' then
        sql.add(' and CRFlag='''+trim(CRFlag.Text)+''' ');
      end;
      if BankName.Text<>'' then
      sql.add(' and BankName like '''+'%'+trim(BankName.Text)+'%'+'''');
      if IFSC.Text<>'' then
      sql.add(' and (case when isnull((select Top 1 Y.YFID from YF_Money_CR Y where Y.SZYFID=A.YFID and Y.CRtype in (''付款登记'',''收款登记'')),'''')='''' then '''' else ''是'' end) like '''+'%'+trim(IFSC.Text)+'%'+'''');
      if YFName.Text<>'' then
      sql.add(' and YFName like '''+'%'+trim(YFName.Text)+'%'+'''');
      if Note.Text<>'' then
      sql.add(' and Note like '''+'%'+trim(Note.Text)+'%'+'''');
      if FactoryName.Text<>'' then
      sql.add(' and FactoryName like '''+'%'+trim(FactoryName.Text)+'%'+'''');
      if FKTaiTou.Text<>'' then
      sql.add(' and FKTaiTou like '''+'%'+trim(FKTaiTou.Text)+'%'+'''');
      open;
    end;
    FMoney:=ADOQueryMain.fieldbyname('YEMoney').asfloat;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add('select A.*');
      sql.add(',IFSC=(case when isnull((select Top 1 Y.YFID from YF_Money_CR Y where Y.SZYFID=A.YFID and Y.CRtype in (''付款登记'',''收款登记'')),'''')='''' then '''' else ''是'' end)');
      sql.add(',SRMoney=(case when A.CRFlag=''收'' then A.Money else 0 end)');
      sql.add(',ZCMoney=(case when isnull(A.CRFlag,'''')<>''收'' then A.Money else 0 end)');
      sql.add(',cast(0 as decimal(18,2)) YEMoney');
      sql.Add(' from YF_Money_CR A');
      sql.Add(' where A.CRType=''其他款项''  ');
      sql.add(' and A.CRTime>='''+FormatDateTime('yyyy-MM-dd',begdate.DateTime)+'''');
      sql.add(' and A.CRTime<'''+FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1)+'''');
      if trim(CanShu3)<>'' then
      begin
        sql.add(' and (CRFlag='''+trim(CanShu3)+''' or YFName=''退款'')');
      end
      else
      begin
        if CRFlag.Text<>'' then
        sql.add(' and CRFlag='''+trim(CRFlag.Text)+''' ');
      end;
      if BankName.Text<>'' then
      sql.add(' and BankName like '''+'%'+trim(BankName.Text)+'%'+'''');
      if IFSC.Text<>'' then
      sql.add(' and (case when isnull((select Top 1 Y.YFID from YF_Money_CR Y where Y.SZYFID=A.YFID and Y.CRtype in (''付款登记'',''收款登记'')),'''')='''' then '''' else ''是'' end) like '''+'%'+trim(IFSC.Text)+'%'+'''');
      if YFName.Text<>'' then
      sql.add(' and YFName like '''+'%'+trim(YFName.Text)+'%'+'''');
      if Note.Text<>'' then
      sql.add(' and Note like '''+'%'+trim(Note.Text)+'%'+'''');
      if FactoryName.Text<>'' then
      sql.add(' and FactoryName like '''+'%'+trim(FactoryName.Text)+'%'+'''');
      if FKTaiTou.Text<>'' then
      sql.add(' and FKTaiTou like '''+'%'+trim(FKTaiTou.Text)+'%'+'''');
      sql.add(' order by A.CRTime,SRMoney desc');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    with CDS_HZ do
    begin
      append;
      fieldbyname('Ssel').AsBoolean:=false;
      fieldbyname('CRTime').Value:=begdate.DateTime;
      fieldbyname('YFName').Value:='上月结转';
      fieldbyname('YEMoney').Value:=FMoney;
      post;
    end;
    with ADOQueryMain do
    begin
      first;
      while not eof do
      begin
        with CDS_HZ do
        begin
          append;
          fieldbyname('Ssel').AsBoolean:=false;
          fieldbyname('CRTime').Value:=ADOQueryMain.fieldbyname('CRTime').AsDateTime;
          fieldbyname('BankName').Value:=ADOQueryMain.fieldbyname('BankName').AsString;
          fieldbyname('BZType').Value:=ADOQueryMain.fieldbyname('BZType').AsString;
          fieldbyname('IFSC').Value:=ADOQueryMain.fieldbyname('IFSC').AsString;
          fieldbyname('CRFlag').Value:=ADOQueryMain.fieldbyname('CRFlag').AsString;
          fieldbyname('FactoryName').Value:=ADOQueryMain.fieldbyname('FactoryName').AsString;
          fieldbyname('YFName').Value:=ADOQueryMain.fieldbyname('YFName').AsString;
          fieldbyname('SRMoney').Value:=ADOQueryMain.fieldbyname('SRMoney').AsFloat;
          fieldbyname('ZCMoney').Value:=ADOQueryMain.fieldbyname('ZCMoney').AsFloat;
          fieldbyname('Note').Value:=ADOQueryMain.fieldbyname('Note').AsString;
          fieldbyname('YFID').Value:=ADOQueryMain.fieldbyname('YFID').AsString;
          fieldbyname('FKTaiTou').Value:=ADOQueryMain.fieldbyname('FKTaiTou').AsString;
          FMoney:=FMoney+ADOQueryMain.fieldbyname('SRMoney').AsFloat-ADOQueryMain.fieldbyname('ZCMoney').AsFloat;
          fieldbyname('YEMoney').Value:=FMoney;
          post;
        end;
        next;
      end;
    end;
    Label13.Caption:='0';
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYSCRPB_ZHYH.InitGridHZ();
begin

end;

procedure TfrmYSCRPB_ZHYH.FormDestroy(Sender: TObject);
begin
  frmYSCRPB_ZHYH:=nil;
end;

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

procedure TfrmYSCRPB_ZHYH.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收款登记1232',Tv2,'财务管理');
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('delete CK_YP_CR where isnull(CRTime,'''')='''' and CYID='''+Trim(FCYID)+''' and CRType='''+Trim(RKFlag)+'''');
    ExecSQL;
  end;}
  Close;
end;
procedure TfrmYSCRPB_ZHYH.TBDelClick(Sender: TObject);
var
  FBBMoney,CRID:string;
begin
  if CDS_HZ.IsEmpty then Exit;
  //if cxtabcontrol1.TabIndex<>0 then exit;
  

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;

  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('delete YF_Money_CR where YFID='''+Trim(CDS_HZ.fieldbyname('YFID').AsString)+'''');
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRPB_ZHYH.FormShow(Sender: TObject);
var fsj:string;
begin
  ReadCxGrid('应收款登记1232',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=SGetServerDate(ADOQueryTemp)-7;
  TZDSC.Visible:=false;
  if canshu2='杂费' then
  begin
    TZDSC.Visible:=true;
  end;
  fsj:='select distinct (A.BankName) name from YF_Money_CR A where A.CRType=''其他款项'' ';
  SInitComBoxBySql(ADOQueryCmd,BankName,False,fsj);
  //SetStatus();
  //InitGrid();
end;

procedure TfrmYSCRPB_ZHYH.TBRafreshClick(Sender: TObject);
begin
  Toolbar1.SetFocus;
  InitGrid();
end;

procedure TfrmYSCRPB_ZHYH.ToolButton2Click(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmYSCRPB_ZHYH.CRFlagChange(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmYSCRPB_ZHYH.Button2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if Trim(CDS_HZ.fieldbyname('SubID').AsString)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete YCL_SG_HZ where SubID='''+Trim(CDS_HZ.fieldbyname('SubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

function TfrmYSCRPB_ZHYH.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'YC','YF_Money_CR',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_CR where 1=2');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='其他款项';
      FieldByName('QtyFlag').Value:=0;
      //FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
      FieldByName('YFName').Value:=Trim(CDS_HZ.fieldbyname('YFName').AsString);
      FieldByName('CRTime').Value:=CDS_HZ.fieldbyname('CRTime').AsDateTime;
      FieldByName('status').Value:='2';
      fieldbyname('HuiLv').Value:='1';
      fieldbyname('SLV').Value:=1;
      fieldbyname('BZType').Value:=Trim(CDS_HZ.fieldbyname('BZType').AsString);
      fieldbyname('ComTaitou').Value:='绍兴飞美针纺有限公司';
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('YFId').Value:=Trim(maxId);
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('增行失败!','提示',0);
  end;
end;

procedure TfrmYSCRPB_ZHYH.cxGridDBColumn8PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YCL_SG_HZ ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where SubId='''+Trim(CDS_HZ.fieldbyname('SubId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.cxGridDBColumn5PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FQty,FPrice,FMoney,FHuiLv,FBBMoney,FKCBB,FFieldName,FSLV:String;
begin
  {if Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'' then
  begin
    Application.MessageBox('自动生成数据不能更改!','提示',0);
    Exit;
  end; }
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:=NULL;
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(BBMoney,0) BBMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKCBB:=ADOQueryTemp.fieldbyname('BBMoney').AsString;

  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FPrice:=Trim(CDS_HZ.fieldbyname('Price').AsString);
  if Trim(FPrice)='' then FPrice:='0';
  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FMoney:=Trim(CDS_HZ.fieldbyname('Money').AsString);
  if Trim(FMoney)='' then FMoney:='0';

  FHuiLv:=Trim(CDS_HZ.fieldbyname('HuiLv').AsString);
  if Trim(FHuiLv)='' then FHuiLv:='1';

  FSLV:=Trim(CDS_HZ.fieldbyname('SLV').AsString);
  if Trim(FSLV)='' then FSLV:='0';

  {FBBMoney:=Trim(CDS_HZ.fieldbyname('BBMoney').AsString);
  if Trim(FBBMoney)='' then FBBMoney:='0'; }

  if Trim(FFieldName)<>'Money' then
  begin
    if Trim(FFieldName)<>'HuiLv' then
    begin
      FBBMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice)*StrToFloat(FHuiLv)*StrToFloat(FSLV));
      FMoney:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice));
    end else
    begin
      FBBMoney:=FloatToStr(StrToFloat(FMoney)*StrToFloat(FHuiLv)*StrToFloat(FSLV));
    end;

  end else
  begin
    FBBMoney:=FloatToStr(StrToFloat(FMoney)*StrToFloat(FHuiLv)*StrToFloat(FSLV));
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Money').Value:=StrToFloat(FMoney);
    FieldByName('BBMoney').Value:=StrToFloat(FBBMoney);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    if Trim(FFieldName)<>'Money' then
    begin
      sql.Add(',Money='+FMoney);
    end;

    sql.Add(',BBMoney='+FBBMoney);
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    
    SQL.Add('Update YF_Money_KC Set KCBBMoney=KCBBMoney-'+FKCBB+'+'+FBBMoney);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmYSCRPB_ZHYH.cxGridDBColumn1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  if Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'' then
  begin
    Application.MessageBox('自动生成数据不能更改!','提示',0);
    Exit;
  end; 
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.ToolButton3Click(Sender: TObject);
begin
  with Self.CDS_HZ do
  begin
    Append;
    //FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('ZdyCode').AsString);
    //FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
    FieldByName('CRTime').Value:=SGetServerDate(ADOQueryTemp);
    fieldbyname('filler').Value:=trim(DName);
    fieldbyname('CRType').Value:='其他款项';
    Fieldbyname('HuiLv').Value:=1;
    fieldbyname('SLV').Value:=1;
    //fieldbyname('BZType').Value:='￥';
    fieldbyname('ComTaitou').Value:='绍兴飞美针纺有限公司';
    Post;
  end;
  Self.SaveData();
end;

procedure TfrmYSCRPB_ZHYH.cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(CDS_HZ.fieldbyname('YFType').AsString)<>'' then
  begin
    Application.MessageBox('自动生成数据不能更改!','提示',0);
    Exit;
  end;
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFName';
      flagname:='费用名称';
      MainType:=trim(DName)+'银行';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('YFCode').Value:=Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set YFCode='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
          sql.Add(' ,YFName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set QtyUnit='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MP_CodeName';
      flagname:='品名';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('P_CodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set P_CodeName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应收款列表');
end;

procedure TfrmYSCRPB_ZHYH.v2Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmProductOrderNewList:=TfrmProductOrderNewList.Create(Application);
    with frmProductOrderNewList do
    begin
      //frmProductOrderList.v1Column4.Visible:=True;
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('MainId').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('subID').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('subID').AsString);
          FieldByName('OrderNo').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('P_CodeName').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MPRTCodeName').AsString);
          FieldByName('P_Spec').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MPRTSpec').AsString);
          post;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate YF_Money_CR ');
            sql.Add(' Set MainId='''+Trim(SELF.CDS_HZ.fieldbyname('MainId').AsString)+'''');
            sql.Add(' ,SubId='''+Trim(SELF.CDS_HZ.fieldbyname('SubId').AsString)+'''');
            sql.Add(' ,p_CodeName='''+Trim(SELF.CDS_HZ.fieldbyname('P_CodeName').AsString)+'''');
            sql.Add(' ,P_Spec='''+Trim(SELF.CDS_HZ.fieldbyname('P_Spec').AsString)+'''');
            sql.Add(' ,OrderNo='''+Trim(SELF.CDS_HZ.fieldbyname('OrderNo').AsString)+'''');
            SQL.Add(',Editer='''+Trim(DName)+'''');
            SQL.Add(',Edittime=getdate() ');
            SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
            ExecSQL;
          end;
        end;
      end;
    end;
  finally
    frmProductOrderNewList.Free;
    self.Tv2.Controller.EditingController.ShowEdit();
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2PSPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    if FFieldName='CRFlag' then
    begin
      if mvalue='收' then
      sql.add(',QtyFlag=1');
      if mvalue='付' then
      sql.add(',QtyFlag=-1');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2KPMoneyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FBBMoney,FKCBB,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(KPMoney,0) KPMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKCBB:=ADOQueryTemp.fieldbyname('KPMoney').AsString;
  FBBMoney:=CDS_HZ.fieldbyname('KPMoney').AsString;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    SQL.Add('Update YF_Money_KC Set KCKPMoney=KCKPMoney-'+FKCBB+'+'+FBBMoney);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.Button1Click(Sender: TObject);
begin

  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  ADOQueryCmd.Connection.BeginTrans;
  try
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        If fieldbyname('ssel').AsBoolean then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('select * from YF_Money_CR ');
            sql.Add('where YFID='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            open;
            edit;
            Fieldbyname('Price').Value:=strtofloatdef(edit1.Text,0);
            Fieldbyname('Money').Value:=format('%.2f',[Fieldbyname('Qty').AsFloat * strtofloatdef(edit1.Text,0) ]);
            Fieldbyname('BBMoney').Value:=format('%.2f',[Fieldbyname('Qty').AsFloat * strtofloatdef(edit1.Text,0) ]);
            post;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    InitGrid();
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('数据保存失败！','提示信息',0);
  end;

end;

procedure TfrmYSCRPB_ZHYH.CheckBox1Click(Sender: TObject);
begin
  label13.Caption:='0';
  IF CDS_HZ.IsEmpty then exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value:=checkbox1.Checked;
      Label13.Caption:=floattostr(strtofloat(Label13.Caption)+fieldbyname('Money').AsCurrency);
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYSCRPB_ZHYH.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();

  InitGrid();
end;

procedure TfrmYSCRPB_ZHYH.FormCreate(Sender: TObject);
begin
  cxGrid2.Align:=alclient;
  canshu2:=trim(DParameters2);
  //canshu3:=trim(DParameters3);
end;

procedure TfrmYSCRPB_ZHYH.TchkClick(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET status=''1'' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;

    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRPB_ZHYH.TnochkClick(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;

  if CDS_HZ.Locate('ssel',true,[])=false then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with CDS_HZ do
    begin
      DisableControls;
      First;
      while not eof do
      begin
        IF Fieldbyname('ssel').AsBoolean=true then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add('update YF_Money_CR SET status=''0'' ');
            sql.Add('where YFID ='+quotedstr(trim(CDS_HZ.fieldbyname('YFID').AsString)));
            execsql;
          end;
        end;
        next;
      end;
      First;
      EnableControls;
    end;
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！','提示信息',0);
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2ComTaitouPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ComTaiTou';
      flagname:='公司抬头';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set ComTaiTou='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.TZDSCClick(Sender: TObject);
var i:integer;
begin
  frmFKCR:=TfrmFKCR.create(self) ;
  with frmFKCR do
  begin
    TSsel.visible:=true;
    TOOLButton3.Visible:=false;
    TBDel.Visible:=false;
    tchk.Visible:=false;
    TNochk.Visible:=false;
    for i:=0 to tv2.ColumnCount-1 do
    begin
      IF uppercase(tv2.Columns[i].DataBinding.FieldName)<>'SSEL' then
      tv2.Columns[i].Options.Focusing:=false;
    end;
    if showmodal=1 then
    begin
      with CDS_HZ do
      begin
        first;
        while not eof do
        begin
          if fieldbyname('Ssel').AsBoolean=true then
          begin
            with self.CDS_HZ do
            begin
              append;
              fieldbyname('CRTime').Value:=Now;
              fieldbyname('FactoryName').Value:=trim(frmFKCR.CDS_HZ.fieldbyname('FactoryName').AsString);
              fieldbyname('YFName').Value:=trim(frmFKCR.CDS_HZ.fieldbyname('YFName').AsString);
              fieldbyname('BZType').Value:='￥';
              fieldbyname('Money').Value:=frmFKCR.CDS_HZ.fieldbyname('Money').AsFloat;
              fieldbyname('filler').Value:=trim(DName);
              fieldbyname('HuiLv').Value:=1;
              fieldbyname('SLV').Value:=1;
              fieldbyname('FeeType').Value:='虚拟费用';
              post;
            end;
            self.SaveData();
          end;
          next;
        end;
      end;
    end;
    free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.VBZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BZType';
      flagname:='币种';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('BZType').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set BZType='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2Column4PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='MP_Spec';
      flagname:='规格';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('P_Spec').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set P_Spec='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2Column5PropertiesChange(Sender: TObject);
begin
  HJ(CDS_HZ,Label13,CDS_HZ.fieldbyname('Money').AsCurrency);
end;

procedure TfrmYSCRPB_ZHYH.v2ConNoHZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmJYorderConCX:=TfrmJYorderConCX.create(self);
  with frmJYorderConCX do
  begin
    formid:='1';
    if showmodal=1 then
    begin
      Self.CDS_HZ.Edit;
      Self.CDS_HZ.FieldByName('ConNo').Value:=Trim(Order_Main.fieldbyname('ConNo').AsString);
      Self.CDS_HZ.FieldByName('Conid').Value:=Trim(Order_Main.fieldbyname('subid').AsString);
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate YF_Money_CR ');
        sql.Add(' Set Conid='''+Trim(Order_Main.fieldbyname('subid').AsString)+'''');
        sql.add(',ConNO='''+trim(Order_Main.fieldbyname('ConNO').AsString)+'''');
        SQL.Add(',Editer='''+Trim(DName)+'''');
        SQL.Add(',Edittime=getdate() ');
        SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
        ExecSQL;
      end;
    end;
    free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2GYSNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          edit;
          FieldByName('GYSname').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set GYSName='''+trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(' where YFId='''+Trim(SELF.CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2Column6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if CDS_HZ.FieldByName('CRFlag').AsString='' then
  begin
    application.MessageBox('请先选择方向','提示');
    exit;
  end;
  if CDS_HZ.FieldByName('CRFlag').AsString='付' then
  begin
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          edit;
          FieldByName('FactoryName').Value:=Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set FactoryName='''+Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(' where YFId='''+Trim(SELF.CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
      Free;
    end;
  end
  else
  begin
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          edit;
          FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
          //Post;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set FactoryName='''+Trim(CDS_HZ.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(' where YFId='''+Trim(self.CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
      free;
    end;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2BankNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BankName2';
      flagname:='银行名称';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('BankName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set BankName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.TSselClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  if CDS_HZ.Locate('Ssel',true,[])=false then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  with CDS_HZ do
  begin
    first;
    while not eof do
    begin
      if fieldbyname('Ssel').AsBoolean=true then
      begin
        if CDS_HZ.FieldByName('IFSC').AsString='是' then
        begin
          if application.MessageBox('已生成过费用是否继续','提示',1)=2 then exit;
        end;
      end;
      next;
    end;
  end;
  if canshu3='' then exit;
  ModalResult:=1
end;

procedure TfrmYSCRPB_ZHYH.VSRMoneyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  if CDS_HZ.FieldByName('CRFlag').AsString='' then
  begin
    application.MessageBox('请先选择方向','提示');
    exit;
  end;
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('SRMoney').Value:=Trim(mvalue);
    post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set Money='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set Money=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2ZCMoneyPropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  if CDS_HZ.FieldByName('CRFlag').AsString='' then
  begin
    application.MessageBox('请先选择方向','提示');
    exit;
  end;
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('ZCMoney').Value:=Trim(mvalue);
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set Money='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set Money=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2FKTaiTouPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='FKTaitou';
      flagname:='付款抬头';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('FKTaitou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set FKTaitou='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSCRPB_ZHYH.v2BZTypePropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('BZType').Value:=Trim(mvalue);
    post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set BZType='''+Trim(mvalue)+'''');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

end.
