unit U_OtherFeeSave;

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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmOtherFeeSave = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    ADOQueryMain: TADOQuery;
    TBExport: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    yydd: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    TBAdd: TToolButton;
    VYB: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    Edit1: TEdit;
    Label7: TLabel;
    Button1: TButton;
    Label8: TLabel;
    ComTaiTou: TEdit;
    TBSave: TToolButton;
    CheckBox1: TCheckBox;
    v2Column2: TcxGridDBColumn;
    ToolButton1: TToolButton;
    FYNAME: TEdit;
    v2Column11: TcxGridDBColumn;
    Label11: TLabel;
    SFDW: TEdit;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    Label2: TLabel;
    JSR: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    ZHMC: TEdit;
    fyyt: TEdit;
    Label9: TLabel;
    Note: TEdit;
    Tv2Column1: 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 yyddChange(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TBExportClick(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2BatchNoPropertiesEditValueChanged(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TBSaveClick(Sender: TObject);
    procedure yyddKeyPress(Sender: TObject; var Key: Char);
    procedure v2Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function SaveData(): Boolean;
    procedure InitYFName();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
  end;

//var
  //frmOtherFeeSave: TfrmOtherFeeSave;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZdyAttachGYS, U_RTFun, U_ZdyAttachment,
  U_ProductOrderListSel;

{$R *.dfm}

procedure TfrmOtherFeeSave.InitGrid();
begin
  ToolBar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      Filtered := False;
      sql.Add(' select A.* ');
//      sql.Add(',FactoryName10=dbo.getPinYin(A.FactoryName)+RTrim(A.FactoryName)');
      sql.Add(' from CW_FY A WHERE 1=1');
      if CheckBox1.Checked then
      begin
        sql.Add('AND A.FYDATE>=''' + FormatDateTime('yyyy-MM-dd', begdate.DateTime) + ''' ');
        sql.Add(' and A.FYDATE<''' + FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1) + ''' ');
      end
      else
      begin
//        sql.Add('where A.CRTime>=''2000-01-01'' ');
//        sql.Add(' and CRTime<''2500-01-01'' ');
      end;
//      sql.Add(' and A.CRType=''费用登记''  ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmOtherFeeSave.InitGridHZ();
begin
end;

procedure TfrmOtherFeeSave.FormDestroy(Sender: TObject);
begin
 // frmYFCR:=nil;
 // frmOtherFeeSave:=nil;
end;

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

procedure TfrmOtherFeeSave.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('费用登记', Tv2, '财务管理');
  Close;
end;

procedure TfrmOtherFeeSave.TBDelClick(Sender: TObject);
begin

  if CDS_HZ.IsEmpty 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 then
        begin
          with ADOQueryCmd do
          begin
            close;
            sql.Clear;
            sql.Add(' delete CW_FY where FYID=''' + Trim(CDS_HZ.fieldbyname('FYID').AsString) + '''');
            execsql;
          end;

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

//  if CDS_HZ.IsEmpty then
//    Exit;
//
//  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
//    Exit;
//  try
//    ADOQueryCmd.Connection.BeginTrans;
//    with ADOQueryCmd do
//    begin
//      close;
//      sql.Clear;
//      sql.Add(' delete CW_FY where FYID=''' + Trim(CDS_HZ.fieldbyname('FYID').AsString) + '''');
//      execsql;
//    end;
//    ADOQueryCmd.Connection.CommitTrans;
//    CDS_HZ.Delete;
//  except
//    ADOQueryCmd.Connection.RollbackTrans;
//    Application.MessageBox('删除失败!', '提示', 0);
//  end;
end;

procedure TfrmOtherFeeSave.FormShow(Sender: TObject);
begin
  ReadCxGrid('费用登记', Tv2, '财务管理');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := SGetServerDateMBeg(ADOQueryTemp);
//  InitYFName();
  InitGrid();
//  if Self.Caption = '费用查询' then
//  begin
//    TBSave.Visible := False;
//    TBAdd.Visible := False;
//    TBDel.Visible := False;
//    Tv2.OptionsData.Editing := False;
//  end;
end;

procedure TfrmOtherFeeSave.InitYFName();
var
  fsj: string;
begin
//  fsj := ' select distinct(YFName) Name,Code=''''  from YF_Money_CR where CRType=''费用登记'' and isnull(YFName,'''')<>'''' ';
//  SInitComBoxBySql(ADOQueryTemp, YFName, False, fsj);
end;

procedure TfrmOtherFeeSave.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
  InitYFName();
end;

procedure TfrmOtherFeeSave.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, CDS_HZ);
  SInitCDSData20(ADOQueryMain, CDS_HZ);
end;

procedure TfrmOtherFeeSave.yyddChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

function TfrmOtherFeeSave.SaveData(): Boolean;
var
  maxId, CRID: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd, maxId, 'FY', 'CW_FY', 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 CW_FY where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('FYID').Value := Trim(maxId);
      //FieldByName('CRID').Value:=StrToInt(CRID);
      SSetSaveDataCDSNew(ADOQueryCmd, Tv2, CDS_HZ, 'CW_FY', 7);
      FieldByName('Filler').Value := Trim(DName);

      FieldByName('FROMMAINID').Value := Trim(CDS_HZ.fieldbyname('FROMMAINID').AsString);
      FieldByName('FROMSUBID').Value := Trim(CDS_HZ.fieldbyname('FROMSUBID').AsString);
//      FieldByName('ZDYNameTj').Value := Trim(CDS_HZ.fieldbyname('ZDYNameTj').AsString);
      FieldByName('FYDATE').Value := formatdateTIme('yyyy-MM-dd', CDS_HZ.fieldbyname('FYDATE').AsDateTime);
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('FYId').Value := Trim(maxId);
      //FieldByName('CRID').Value:=StrToInt(CRID);
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('增行失败!', '提示', 0);
  end;
end;

procedure TfrmOtherFeeSave.cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FQty, FPrice, FMoney, 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;

  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';

  if Trim(FFieldName) <> 'Money' then
  begin
    FMoney := FloatToStr(StrToFloat(FQty) * StrToFloat(FPrice));
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('Money').Value := StrToFloat(FMoney);
    Post;
  end;

  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmOtherFeeSave.cxGridDBColumn1PropertiesEditValueChanged(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;

  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmOtherFeeSave.TBAddClick(Sender: TObject);
begin
//  try
//    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
//    with frmProductOrderListSel do
//    begin
//      if ShowModal = 1 then
//      begin
//        with Self.CDS_HZ do
//        begin
//          Append;
//          FieldByName('SFDW').Value := Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
//          FieldByName('FROMMAINID').Value := Trim(Order_Main.fieldbyname('MAINID').AsString);
//          FieldByName('FROMSUBID').Value := Trim(Order_Main.fieldbyname('SUBID').AsString);
//          FieldByName('YYDD').Value := Trim(Order_Main.fieldbyname('ORDERNO').AsString);
//          FieldByName('FYDATE').Value := SGetServerDate(ADOQueryTemp);
//
//          Post;
//        end;
//        Self.SaveData();
//      end;
//    end;
//  finally
//    frmProductOrderListSel.Free;
//  end;
//  tv2.Controller.EditingController.ShowEdit();

  with Self.CDS_HZ do
  begin
    Append;

    FieldByName('FYDATE').Value := SGetServerDate(ADOQueryTemp);

    Post;
  end;
  Self.SaveData();
end;

procedure TfrmOtherFeeSave.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 := '费用';
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
//          FieldByName('YFCode').Value := Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('FYName').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOtherFeeSave.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);

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOtherFeeSave.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv2, ADOQueryMain, '费用列表');
end;

procedure TfrmOtherFeeSave.v2Column2PropertiesEditValueChanged(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;

end;

procedure TfrmOtherFeeSave.v2BatchNoPropertiesEditValueChanged(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;

end;

procedure TfrmOtherFeeSave.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 TfrmOtherFeeSave.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmOtherFeeSave.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue: Boolean;
begin
  mvalue := TcxCheckBox(Sender).EditingValue;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPFlag').Value := mvalue;
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('update YF_Money_CR Set ');
    if mvalue = true then
    begin
      sql.Add(' KPFlag=1 ');
    end
    else
    begin
      sql.Add(' KPFlag=0 ');
    end;
    sql.Add(' where YFID=''' + Trim(CDS_HZ.fieldbyname('YFID').AsString) + '''');
    ExecSQL;
  end;
end;

procedure TfrmOtherFeeSave.v2Column8PropertiesButtonClick(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 := 'GSTT';
      flagname := '公司抬头';
      V1Name.Caption := '中文名称';
      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 TfrmOtherFeeSave.TBSaveClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  begdate.SetFocus;
  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 then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from CW_FY where FYID=''' + Trim(CDS_HZ.fieldbyname('FYID').AsString) + '''');
            Open;
          end;
          with ADOQueryCmd do
          begin
            Edit;
            RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_HZ, 'CW_FY', 7);

            Post;
          end;

        end;
        next;
      end;
      First;
      EnableControls;
    end;

    Application.MessageBox('保存成功!', '提示', 0);
    InitGrid();
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
//  try
//    ADOQueryCmd.Connection.BeginTrans;
//    with ADOQueryCmd do
//    begin
//      Close;
//      sql.Clear;
//      sql.Add('select * from CW_FY where FYID=''' + Trim(CDS_HZ.fieldbyname('FYID').AsString) + '''');
//      Open;
//    end;
//    with ADOQueryCmd do
//    begin
//      Edit;
//      RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_HZ, 'CW_FY', 7);
//
//      Post;
//    end;
//    ADOQueryCmd.Connection.CommitTrans;
//    Application.MessageBox('保存成功!', '提示', 0);
//  except
//    ADOQueryCmd.Connection.RollbackTrans;
//    Application.MessageBox('保存失败!', '提示', 0);
//  end;
end;

procedure TfrmOtherFeeSave.yyddKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin

    ToolBar1.SetFocus;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        SQL.Clear;
        Filtered := False;
        sql.Add(' select A.* ');

        sql.Add('from  CW_FY A WHERE 1=1');
        if CheckBox1.Checked then
        begin
          sql.Add(' and A.CRTime>=''' + FormatDateTime('yyyy-MM-dd', begdate.DateTime) + ''' ');
          sql.Add(' and A.CRTime<''' + FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1) + ''' ');
        end;

        Open;
      end;
      SCreateCDS20(ADOQueryMain, CDS_HZ);
      SInitCDSData20(ADOQueryMain, CDS_HZ);
    finally
      ADOQueryMain.EnableControls;
      ToolButton2.Click;
    end;
  end;
end;

procedure TfrmOtherFeeSave.v2Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'FYYT';
      flagname := '费用用途';
//      MainType := '费用';
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
//          FieldByName('YFCode').Value := Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('fyyt').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOtherFeeSave.v2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          EDIT;
//          FieldByName('SFDW').Value := Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
          FieldByName('FROMMAINID').Value := Trim(Order_Main.fieldbyname('MAINID').AsString);
          FieldByName('FROMSUBID').Value := Trim(Order_Main.fieldbyname('SUBID').AsString);
          FieldByName('YYDD').Value := Trim(Order_Main.fieldbyname('ORDERNO').AsString);
//          FieldByName('FYDATE').Value := SGetServerDate(ADOQueryTemp);

          Post;
        end;
//        Self.SaveData();
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmOtherFeeSave.v2Column6PropertiesButtonClick(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
          Append;
          FieldByName('FactoryNo').Value := Trim(CDS_HZ.fieldbyname('ZdyCode').AsString);
          FieldByName('FactoryName').Value := Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
          FieldByName('CRTime').Value := SGetServerDate(ADOQueryTemp);
          Post;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set FactoryNo=''' + Trim(frmZdyAttachment.CDS_HZ.fieldbyname('ZdyCode').AsString) + '''');
          sql.Add(' ,FactoryName=''' + Trim(frmZdyAttachment.CDS_HZ.fieldbyname('ZdyName').AsString) + '''');
          SQL.Add(',Editer=''' + Trim(DName) + '''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId=''' + Trim(self.CDS_HZ.fieldbyname('YFId').AsString) + '''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOtherFeeSave.ToolButton1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  begdate.SetFocus;
  if Application.MessageBox('确定要批量保存当前页面的所有数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while not Eof do
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from YF_Money_CR where YFID=''' + Trim(CDS_HZ.fieldbyname('YFID').AsString) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Edit;
          RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_HZ, 'YF_Money_CR', 7);
          FieldByName('Editer').Value := Trim(DName);
          FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
          Post;
        end;
        Next;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功!', '提示', 0);
  except
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

procedure TfrmOtherFeeSave.v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ZHName';
      flagname := '账户名称';
//      MainType := '费用';
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
//          FieldByName('YFCode').Value := Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('ZHMC').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOtherFeeSave.v2Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'JSR';
      flagname := '经手人';
//      MainType := '费用';
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
//          FieldByName('YFCode').Value := Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('JSR').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOtherFeeSave.v2Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'SFDW';
      flagname := '收费单位/人';
//      MainType := '费用';
      if ShowModal = 1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
//          FieldByName('YFCode').Value := Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('SFDW').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.

