unit U_YFCRSEL;

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, Menus, MovePanel, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue;

type
  TfrmYFCRSEL = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    cxTabControl1: TcxTabControl;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    CDS_YFS: TClientDataSet;
    DS_YFS: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label5: TLabel;
    CPName: TEdit;
    FactoryName: TComboBox;
    Label1: TLabel;
    MXORDERNO: TEdit;
    ToolButton1: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2ssel: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column20: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    VBB: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Tv2Column2: 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 FactoryNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure YFGSTypeChange(Sender: TObject);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column19PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column21PropertiesEditValueChanged(Sender: TObject);
    procedure kkreasonKeyPress(Sender: TObject; var Key: Char);
    procedure begdateChange(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
  public

    { Public declarations }
    FCYID: string;
    fmanage: string;
  end;

var
  frmYFCRSEL: TfrmYFCRSEL;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmYFCRSEL.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select a.*,b.*,MXMONEYX=(ISNULL(B.QTY,0)*ISNULL(B.PRICE,0))  ');
      SQL.Add(',MXMONEYZ=(ISNULL(B.QTY,0)*ISNULL(B.PRICE,0)+isnull(B.xiaogangfei,0)+isnull(B.shangjifei,0))');
      SQL.ADD(' ,sktt=(SELECT SELLNAME FROM SalesContract_Main');

      SQL.Add(' WHERE ConNo=(SELECT ConNo FROM JYOrder_Main WHERE OrderNo=B.MXOrderNo)   ) ');
      //SQL.Add(',CKDATE=(SELECT CRTIME FROM CK_SXPB_CR E WHERE E.SPID=B.YFPZNO )');
      sql.Add('from YF_Money_CR A inner join YF_Money_CR_sub B ON A.YFID=B.YFID');
//      sql.Add('left join CK_SXPB_CR E on E.SPID=B.YFPZNO');
      sql.Add(' where b.DZDATE>=''' + FormatDateTime('yyyy-MM-dd', begdate.DateTime) + ''' ');
      sql.Add(' and b.DZDATE<''' + FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1) + ''' ');
      sql.Add(' and A.CRType=''应付款登记''  ');
      sql.Add(' and b.DZFLAG=1  ');
      sql.Add(' and a.STATUS=1  ');
      if cxTabControl1.TabIndex = 0 then
        SQL.Add(' and not exists(select YFID from YF_Money_CR_sub X where X.yfid=B.FKID ) ')
      else
        SQL.Add(' and  exists(select YFID from YF_Money_CR_Sub X where X.yfid=B.FKID )');
//      if cxTabControl1.TabIndex < 2 then
//        sql.Add(' and A.status=''' + inttostr(cxTabControl1.TabIndex) + ''' ');

      SQL.Add('ORDER BY a.CRTIME');
//      ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmYFCRSEL.FormDestroy(Sender: TObject);
begin
  frmYfCRSEL := nil;
end;

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

procedure TfrmYFCRSEL.TBCloseClick(Sender: TObject);
begin
//  WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, '财务管理');
  WriteCxGrid(trim(self.Caption) + 'Tv2', Tv2, '财务管理666');
  Close;
end;

procedure TfrmYFCRSEL.TBDelClick(Sender: TObject);
var
  FBBMoney, CRID: string;
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
          if Fieldbyname('kxtype').AsString = '扣款' then
          begin
            with ADOQueryCmd do
            begin
              close;
              sql.Clear;
//              sql.Add('delete YF_Money_CR where YFID=' + Quotedstr(Trim(CDS_HZ.fieldbyname('YFID').AsString)));
              sql.Add('delete YF_Money_CR_Sub where YFSID=''' + Trim(CDS_HZ.fieldbyname('YFSID').AsString) + '''');
              sql.Add('UPDATE YF_MONEY_CR SET Money=(SELECT SUM(MXMONEY) FROM YF_Money_CR_sub a where a.yfid=YF_MONEY_CR.yfid)');
              sql.Add(',bbmoney=(SELECT SUM(MXMONEY) FROM YF_Money_CR_sub a where a.yfid=YF_MONEY_CR.yfid)');
              SQL.Add('where yfid=''' + Trim(CDS_HZ.fieldbyname('YFID').AsString) + '''');
              execsql;
            end;
          end
          else
          begin
            with ADOQueryCmd do
            begin
              close;
              sql.Clear;
              sql.Add('delete YF_Money_CR where YFID=''' + Trim(CDS_HZ.fieldbyname('YFID').AsString) + '''');
              sql.Add('delete YF_Money_CR_Sub where YFID=''' + Trim(CDS_HZ.fieldbyname('YFID').AsString) + '''');

              sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
              sql.Add(' ' + quotedstr(trim(DName)));
              sql.Add(',getdate() ');
              sql.Add(',' + quotedstr(trim(self.Caption)));
              sql.Add(',' + quotedstr(trim('删除应收款')));
              sql.Add(',' + quotedstr(trim('单号:' + trim(CDS_HZ.FieldByName('YFPZNO').AsString))));
              sql.Add(',' + quotedstr(trim('成功')));
              sql.Add(')');
              execsql;
            end;
          end;

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

procedure TfrmYFCRSEL.FormShow(Sender: TObject);
var
  fsj: string;
begin

//  ReadCxGrid(trim(self.Caption) + 'Tv1', Tv1, '财务管理');
  ReadCxGrid(trim(self.Caption) + 'Tv2', Tv2, '财务管理666');
  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := Enddate.DateTime;
//  fsj := 'select distinct(YFGSType) name from YF_Money_CR where CRType=''应收款登记'' ';
//  SInitComBoxBySql(ADOQueryCmd, YFGSType, False, fsj);
  fsj := 'select distinct(FactoryName) Name from YF_Money_CR where CRType=''应付款登记''  order by FactoryName ';
  SInitComBoxBySql(ADOQueryCmd, FactoryName, False, fsj);

  InitGrid();
end;

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

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

procedure TfrmYFCRSEL.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFCRSEL.ToolButton1Click(Sender: TObject);
begin

  ModalResult := 1;
end;

procedure TfrmYFCRSEL.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmYFCRSEL.FormCreate(Sender: TObject);
begin
  cxGrid2.Align := alclient;
end;

procedure TfrmYFCRSEL.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 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 TfrmYFCRSEL.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 then
        begin
          if Fieldbyname('HZFPHX').AsFloat > 0 then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            EnableControls;
            application.MessageBox('不能撤销已核销数据！', '提示信息', 0);
            exit;
          end;
          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 TfrmYFCRSEL.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := TRUE;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYFCRSEL.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := FALSE;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYFCRSEL.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from YF_Money_CR_SUB A');
    sql.Add('where YFID=' + Quotedstr(Trim(CDS_HZ.fieldbyname('YFID').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_YFS);
  SInitCDSData20(ADOQueryTemp, CDS_YFS);
end;

procedure TfrmYFCRSEL.YFGSTypeChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYFCRSEL.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalues, FFieldName: string;
begin
  mvalues := TCXTextEdit(Sender).Text;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if mvalues = '' then
  begin
    mvalues := '';
  end;
  with CDS_HZ do
  begin
    edit;
    fieldbyname(FFieldName).Value := mvalues;
    post;
  end;
//  tv2.Controller.EditingController.ShowEdit();
//  if trim(mvalues) <> '' then
//  begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;

    sql.Add('Update YF_Money_CR_Sub set KKREASON=' + QuotedStr((mvalues)) + ' ');
    sql.Add(' where YFSID=''' + Trim((CDS_HZ.fieldbyname('yfsid').AsString)) + '''');
    ExecSQL;
  end;

  with CDS_HZ do
  begin
    Edit;
    CDS_HZ.fieldbyname('KKREASON').AsString := Trim(mvalues);
  end;

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

procedure TfrmYFCRSEL.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  mvalues, FFieldName: string;
begin
  mvalues := TCXTextEdit(Sender).Text;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if mvalues = '' then
  begin
    mvalues := '0';
  end;
  with CDS_HZ do
  begin
    edit;
    fieldbyname(FFieldName).Value := mvalues;
    post;
  end;
  tv2.Controller.EditingController.ShowEdit();
//  if trim(mvalues) <> '' then
//  begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_CR_Sub set ');
    sql.Add('KKMONEY=' + Trim(mvalues));
    sql.Add(' where YFSID=''' + Trim(CDS_HZ.fieldbyname('yfsid').AsString) + '''');

    sql.Add('Update YF_Money_CR_Sub set MXMONEY=(ISNULL(QTY,0)*ISNULL(PRICE,0)+isnull(xiaogangfei,0)+isnull(shangjifei,0))-KKMONEY');
    sql.Add(' where YFSID=''' + Trim(CDS_HZ.fieldbyname('yfsid').AsString) + '''');

    sql.Add('Update YF_Money_CR set MONEY=(SELECT SUM(MXMONEY) FROM YF_Money_CR_Sub A WHERE A.YFID=YF_Money_CR.YFID group by yfid)');
    sql.Add(' ,BBMONEY=(SELECT SUM(MXMONEY) FROM YF_Money_CR_Sub A WHERE A.YFID=YF_Money_CR.YFID group by yfid)');
    sql.Add(' where YFID=''' + Trim(CDS_HZ.fieldbyname('yfid').AsString) + '''');

    ExecSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    CDS_HZ.fieldbyname('KKMONEY').value := Trim(mvalues);
    CDS_HZ.fieldbyname('MXMONEY').value := StrToFloatDef(CDS_HZ.fieldbyname('MXMONEYZ').value, 0) - StrToFloatDef(mvalues, 0);
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmYFCRSEL.v2Column19PropertiesEditValueChanged(Sender: TObject);
var
  mvalues, FFieldName: string;
begin
  mvalues := TCXTextEdit(Sender).Text;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if mvalues = '' then
  begin
    mvalues := '0';
  end;
  with CDS_HZ do
  begin
    edit;
    fieldbyname(FFieldName).Value := mvalues;
    post;
  end;
  tv2.Controller.EditingController.ShowEdit();
//  if trim(mvalues) <> '' then
//  begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_CR_Sub  ');
    SQL.Add(' Set ' + FFieldName + '=' + Trim(mvalues));
    sql.Add(' where YFSID=''' + Trim(CDS_HZ.fieldbyname('yfsid').AsString) + '''');

    sql.Add('Update YF_Money_CR_Sub set MXMONEY=(ISNULL(QTY,0)*ISNULL(PRICE,0)+isnull(xiaogangfei,0)+isnull(shangjifei,0))-KKMONEY');
    sql.Add(' where YFSID=''' + Trim(CDS_HZ.fieldbyname('yfsid').AsString) + '''');

    sql.Add('Update YF_Money_CR set MONEY=(SELECT SUM(MXMONEY) FROM YF_Money_CR_Sub A WHERE A.YFID=YF_Money_CR.YFID group by yfid)');
    sql.Add(' ,BBMONEY=(SELECT SUM(MXMONEY) FROM YF_Money_CR_Sub A WHERE A.YFID=YF_Money_CR.YFID group by yfid)');
    sql.Add(' where YFID=''' + Trim(CDS_HZ.fieldbyname('yfid').AsString) + '''');

    ExecSQL;
  end;
  tv2.Controller.EditingController.ShowEdit();
  with CDS_HZ do
  begin
    Edit;
//    CDS_HZ.fieldbyname('KKMONEY').value := Trim(mvalues);
    CDS_HZ.fieldbyname('MXMONEYX').value := StrToFloatDef(CDS_HZ.fieldbyname('qty').asstring, 0) * StrToFloatDef(CDS_HZ.fieldbyname('price').asstring, 0);
    CDS_HZ.fieldbyname('MXMONEYZ').value := StrToFloatDef(CDS_HZ.fieldbyname('qty').asstring, 0) * StrToFloatDef(CDS_HZ.fieldbyname('price').asstring, 0) + StrToFloatDef(CDS_HZ.fieldbyname('xiaogangfei').asstring, 0) + StrToFloatDef(CDS_HZ.fieldbyname('shangjifei').asstring, 0);
    CDS_HZ.fieldbyname('MXMONEY').value := StrToFloatDef(CDS_HZ.fieldbyname('qty').asstring, 0) * StrToFloatDef(CDS_HZ.fieldbyname('price').asstring, 0) + StrToFloatDef(CDS_HZ.fieldbyname('xiaogangfei').asstring, 0) + StrToFloatDef(CDS_HZ.fieldbyname('shangjifei').asstring, 0) - StrToFloatDef(CDS_HZ.fieldbyname('kkmoney').asstring, 0);
  end;

end;

procedure TfrmYFCRSEL.v2Column21PropertiesEditValueChanged(Sender: TObject);
var
  mvalues, FFieldName: string;
begin
  mvalues := TCXTextEdit(Sender).Text;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  if mvalues = '' then
  begin
    mvalues := '0';
  end;
  with CDS_HZ do
  begin
    edit;
    fieldbyname(FFieldName).Value := mvalues;
    post;
  end;
  tv2.Controller.EditingController.ShowEdit();
//  if trim(mvalues) <> '' then
//  begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YF_Money_CR_Sub  ');
    SQL.Add(' Set ' + FFieldName + '=' + QuotedStr((mvalues)));
    sql.Add(' where YFSID=''' + Trim(CDS_HZ.fieldbyname('yfsid').AsString) + '''');

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

end;

procedure TfrmYFCRSEL.kkreasonKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    SelectNext(ActiveControl as TWinControl, True, True);
  end;
end;

procedure TfrmYFCRSEL.begdateChange(Sender: TObject);
begin
  Enddate.DateTime := begdate.DateTime;
end;

end.

