unit U_WageEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxContainer,
  cxLabel, StdCtrls, cxCheckBox, ExtCtrls, Menus;

type
  TfrmWageEdit = class(TForm)
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    DataSource1: TDataSource;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label2: TLabel;
    CarType: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v2Column12: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    cxgrdDownQty: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxgrdWzPrice: TcxGridDBColumn;
    cxgrdCarBalance: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label3: TLabel;
    CarNo: TEdit;
    Label4: TLabel;
    ConNo: TEdit;
    Label5: TLabel;
    C_Code: TEdit;
    Label1: TLabel;
    C_CodeName: TEdit;
    Label6: TLabel;
    Apxh: TEdit;
    Label7: TLabel;
    APID: TEdit;
    ToolButton1: TToolButton;
    Label8: TLabel;
    PlanQty: TEdit;
    ToolButton2: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure v1Column10PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column6PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column13PropertiesEditValueChanged(Sender: TObject);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column21PropertiesEditValueChanged(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure cxgrdDownQtyPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure cxgrdCarBalancePropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
    FAPID: string;
  end;

var
  frmWageEdit: TfrmWageEdit;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_SysLogHelp;

{$R *.dfm}

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

procedure TfrmWageEdit.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid('绣花工日工资', Tv1, '工资管理');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.CONNO ,B.MainId,B.SubId,B.C_Code,B.C_CodeName ');
    sql.Add(',C.CarType,C.CarNo,C.Apxh,C.APID,C.PlanQty ');
    sql.Add(' from Worker_WorkDetail C left join Cloth_Main A  on  A.MainId=C.MainId');
    sql.Add('left join Cloth_sub B on C.SubId=B.SubId ');
    sql.Add('where C.APID=' + quotedstr(trim(FAPID)));
    sql.Add(' and not exists(select * from DCGMoney X where X.GZID=C.GZID) ');
    sql.Add(' group by A.CONNO ,B.MainId,B.SubId,B.C_Code,B.C_CodeName,C.CarType,C.CarNo,C.Apxh,C.APID,C.PlanQty');
    Open;
  end;
  SCSHDataNew(ADOQueryTemp, ScrollBox1, 2);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.CONNO ,B.MainId,B.SubId,B.C_Code,B.C_CodeName ');
    sql.Add(',MPMoney=(JGPrice+ISNULL(CarBalance,0))*Qty/10000');
    sql.Add(',C.* from Worker_WorkDetail C left join Cloth_Main A  on  A.MainId=C.MainId');
    sql.Add('left join Cloth_sub B on C.SubId=B.SubId ');
    sql.Add('where C.APID=' + quotedstr(trim(FAPID)));
    sql.Add(' and not exists(select * from DCGMoney X where X.GZID=C.GZID) ');

    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Main);
  SInitCDSData20(ADOQueryTemp, CDS_Main);

end;

procedure TfrmWageEdit.v1Column10PropertiesEditValueChanged(Sender: TObject);
begin
  with CDS_Sub do
  begin
    Edit;
    FieldByName('ElseWage').Value := StrToFloat(TcxTextEdit(Sender).EditingText);
    FieldByName('Money').Value := FieldByName('OutputWage').AsFloat + FieldByName('ElseWage').AsFloat - FieldByName('KKMoney').AsFloat;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.v1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  price1: Double;
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ElseWageName';
      flagname := '其他工资项目';
      fnote := True;
      V1Note.Caption := '单价';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ElseWageName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          if TryStrToFloat(Trim(frmZDYHelp.ClientDataSet1.fieldbyname('Note').AsString), price1) then
            FieldByName('Price1').Value := price1
          else
            FieldByName('Price1').Value := 0;

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

procedure TfrmWageEdit.v2Column6PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FPDTiaoXian, FISM, FHXName: string;
  FMiShu, AZhenShu, FZhenShu, FPrice, FMoney, FOutputWage, FElseWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FMiShu := fieldbyname('MiShu').AsFloat;
    FZhenShu := fieldbyname('ZhenShu').AsFloat;
    FElseWage := fieldbyname('ElseWage').AsFloat;
    FKKMoney := fieldbyname('KKMoney').AsFloat;
    FPDTiaoXian := Trim(fieldbyname('PDTiaoXian').AsString);
    FISM := trim(fieldbyname('ISM').AsString);
    FHXName := trim(fieldbyname('HXName').AsString);
  end;
  if FISM = '是' then
  begin
    FPrice := 0.5;
    FOutputWage := FMiShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end
  else
  begin
    if FPDTiaoXian = '是' then
    begin
      FPrice := 3.2;
    end
    else
    begin
      if Pos('横条', FHXName) > 0 then
      begin
        if FZhenShu < 33 then
          FPrice := 2.5
        else
          FPrice := 2.6;
      end
      else
      begin
        //if FMiShu<200 then
        begin
          with ADOQueryTemp do
          begin
            Close;
            SQL.Clear;
            SQL.Add('select * from KH_ZDY_TJList where ZdyName=''' + Trim(Self.CDS_Sub.fieldbyname('TouJu').AsString) + ''' ');
            Open;
          end;
          AZhenShu := ADOQueryTemp.fieldbyname('LJZhenShu').AsFloat;
          if FZhenShu < AZhenShu then
            FPrice := ADOQueryTemp.fieldbyname('Price1').AsFloat
          else
            FPrice := ADOQueryTemp.fieldbyname('Price2').AsFloat;
        end;
      end;
    end;
    FOutputWage := FZhenShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  if CDS_Sub.FieldByName('IFCLBZ').AsString = '是' then
  begin
    with CDS_Sub do
    begin
      edit;
      FieldByName('CLBZQty').Value := FZhenShu * 0.2;
      post;
    end;
    FOutputWage := FZhenShu * 1.2 * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('Price').Value := FPrice;
    FieldByName('OutputWage').Value := FOutputWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.v1Column13PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
  FQty1, FPrice1, FMoney, FElseWage, FOutputWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FQty1 := fieldbyname('Qty1').AsFloat;
    FPrice1 := fieldbyname('Price1').AsFloat;
    FOutputWage := fieldbyname('OutputWage').AsFloat;
    FKKMoney := fieldbyname('KKMOney').AsFloat;
  end;
  FElseWage := FQty1 * FPrice1;
  FMoney := FElseWage + FOutputWage;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('ElseWage').Value := FElseWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'XHNote';
      flagname := '备注信息';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('Note').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmWageEdit.v1Column21PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FPDTiaoXian, FISM, FHXName: string;
  FMiShu, AZhenShu, FZhenShu, FPrice, FMoney, FOutputWage, FElseWage, FKKMoney: Double;
begin
  mvalue := Trim(TcxTextEdit(Sender).EditingText);
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Sub do
  begin
    edit;
    fieldbyname(FFieldName).value := mvalue;
    Post;
    FPrice := fieldbyname('Price').AsFloat;
    FMiShu := fieldbyname('MiShu').AsFloat;
    FZhenShu := fieldbyname('ZhenShu').AsFloat;
    FElseWage := fieldbyname('ElseWage').AsFloat;
    FKKMoney := fieldbyname('KKMoney').AsFloat;
    FPDTiaoXian := Trim(fieldbyname('PDTiaoXian').AsString);
    FISM := trim(fieldbyname('ISM').AsString);
    FHXName := trim(fieldbyname('HXName').AsString);
  end;
  if FISM = '是' then
  begin
    FOutputWage := FMiShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end
  else
  begin
    FOutputWage := FZhenShu * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  if CDS_Sub.FieldByName('IFCLBZ').AsString = '是' then
  begin
    with CDS_Sub do
    begin
      edit;
      FieldByName('CLBZQty').Value := FZhenShu * 0.2;
      post;
    end;
    FOutputWage := FZhenShu * 1.2 * FPrice;
    FMoney := FOutputWage + FElseWage;
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('Price').Value := FPrice;
    FieldByName('OutputWage').Value := FOutputWage;
    FieldByName('Money').Value := FMoney - FKKMoney;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.N1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''半天'',QJQty=0.5 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '半天';
      fieldbyname('QJQty').Value := 0.5;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;

end;

procedure TfrmWageEdit.N2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''一天'',QJQty=1 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '一天';
      fieldbyname('QJQty').Value := 1;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmWageEdit.N3Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=null,QJQty=0 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '';
      fieldbyname('QJQty').Value := 0;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmWageEdit.N4Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  GZListMain SET QJNote=''休假'',QJQty=0 ');
      sql.Add('where GZMainID=' + quotedstr(trim(CDS_Main.fieldbyname('GZMainID').AsString)));
      execsql;
    end;
    with CDS_Main do
    begin
      edit;
      fieldbyname('QJNote').Value := '休假';
      fieldbyname('QJQty').Value := 0;
      Post;
    end;
  except
    application.MessageBox('请假失败！', '提示信息', 0);
  end;
end;

procedure TfrmWageEdit.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('绣花工日工资', Tv1, '工资管理');
  Close;
end;

procedure TfrmWageEdit.cxgrdDownQtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FApid, FDetailId, Fopevent: string;
  FDownQty, FQty, FCarBalance, FCarPrice, FMPMoney: Double;
  YFDownQty, YFCarBalance: Double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_Main do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
    FDownQty := FieldByName('DownQty').AsFloat;
    FCarBalance := FieldByName('CarBalance').AsFloat;
    FCarPrice := FieldByName('CarPrice').AsFloat;
    FApid := FieldByName('Apid').AsString;
    FDetailId := FieldByName('DetailId').AsString;
  end;
  FQty := FDownQty;
  FMPMoney := FQty * (FCarPrice + FCarBalance) / 10000;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Worker_WorkDetail where DetailId=' + quotedstr(FDetailId));
    Open;
  end;
  YFDownQty := ADOQueryTemp.FieldByName('DownQty').AsFloat;
  YFCarBalance := ADOQueryTemp.FieldByName('CarBalance').AsFloat;

  Fopevent := 'ID:' + Trim(FDetailId);
  Fopevent := Fopevent + ';下机转速：' + Trim(FloatToStr(YFDownQty)) + '>>>' + Trim(FloatToStr(FDownQty));

  with CDS_Main do
  begin
    Edit;
    FieldByName('DownQty').Value := FDownQty;
    FieldByName('Qty').Value := FQty;
    FieldByName('CarBalance').Value := FCarBalance;
    FieldByName('MPMoney').Value := FMPMoney;
    Post;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    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('修改' + FFieldName)));
    sql.Add(',' + quotedstr(Fopevent));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    ExecSQL;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.ToolButton1Click(Sender: TObject);
var
  MQty: Double;
begin

  ConNo.SetFocus;
  if TV1.DataController.Summary.FooterSummaryValues[3] <> NULL then
    MQty := TV1.DataController.Summary.FooterSummaryValues[3];
  if MQty <> StrToFloat(PlanQty.Text) then
  begin
    application.MessageBox('产量转速合计与预计不符！', '提示信息', 0);
    Exit;
  end;

  try
    CDS_Main.DisableControls;
    ADOQueryCmd.Connection.BeginTrans;

    with CDS_Main do
    begin
      First;
      while not Eof do
      begin

        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate Worker_WorkDetail ');
            sql.Add(' Set DownQty=' + Trim(CDS_Main.FieldByName('DownQty').AsString));
            sql.Add(' , Qty=' + Trim(CDS_Main.FieldByName('Qty').AsString));
            sql.Add(' , CarBalance=' + Trim(CDS_Main.FieldByName('CarBalance').AsString));
            sql.Add(' where DetailId=' + quotedstr(Trim(CDS_Main.FieldByName('DetailId').AsString)));
            ExecSQL;
          end;
          ExecSQL;
        end;

        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.EnableControls;
    application.MessageBox('保存成功！', '提示信息', 0);
  except
    ADOQueryCmd.Connection.RollbackTrans;
    CDS_Main.EnableControls;
    application.MessageBox('保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmWageEdit.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FApid, FDetailId, Fopevent: string;
  FQty, FCarBalance, FCarPrice, FMPMoney: Double;
  YFQty, YFCarBalance: Double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_Main do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
    FQty := FieldByName('Qty').AsFloat;
    FCarBalance := FieldByName('CarBalance').AsFloat;
    FCarPrice := FieldByName('CarPrice').AsFloat;
    FApid := FieldByName('Apid').AsString;
    FDetailId := FieldByName('DetailId').AsString;
  end;

  FMPMoney := FQty * (FCarPrice + FCarBalance) / 10000;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Worker_WorkDetail where DetailId=' + quotedstr(FDetailId));
    Open;
  end;
  YFQty := ADOQueryTemp.FieldByName('DownQty').AsFloat;
  YFCarBalance := ADOQueryTemp.FieldByName('CarBalance').AsFloat;

  Fopevent := 'ID:' + Trim(FDetailId);
  Fopevent := Fopevent + ';产量转速：' + Trim(FloatToStr(YFQty)) + '>>>' + Trim(FloatToStr(FQty));

  with CDS_Main do
  begin
    Edit;
    FieldByName('Qty').Value := FQty;
    FieldByName('MPMoney').Value := FMPMoney;
    Post;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    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('修改' + FFieldName)));
    sql.Add(',' + quotedstr(Fopevent));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    ExecSQL;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.cxgrdCarBalancePropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName, FApid, FDetailId, Fopevent: string;
  FQty, FCarBalance, FCarPrice, FMPMoney: Double;
  YFDownQty, YFCarBalance: Double;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_Main do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
    FQty := FieldByName('Qty').AsFloat;
    FCarBalance := FieldByName('CarBalance').AsFloat;
    FCarPrice := FieldByName('CarPrice').AsFloat;
    FApid := FieldByName('Apid').AsString;
    FDetailId := FieldByName('DetailId').AsString;
  end;

  FMPMoney := FQty * (FCarPrice + FCarBalance) / 10000;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Worker_WorkDetail where DetailId=' + quotedstr(FDetailId));
    Open;
  end;
  YFCarBalance := ADOQueryTemp.FieldByName('CarBalance').AsFloat;

  Fopevent := 'ID:' + Trim(FDetailId);
  Fopevent := Fopevent + ';补助单价：' + Trim(FloatToStr(YFCarBalance)) + '>>>' + Trim(FloatToStr(FCarBalance));

  with CDS_Main do
  begin
    Edit;
    FieldByName('CarBalance').Value := FCarBalance;
    FieldByName('MPMoney').Value := FMPMoney;
    Post;
  end;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    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('修改' + FFieldName)));
    sql.Add(',' + quotedstr(Fopevent));
    sql.Add(',' + quotedstr(trim('成功')));
    sql.Add(')');
    ExecSQL;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageEdit.ToolButton2Click(Sender: TObject);
begin
  frmSysLogHelp := TfrmSysLogHelp.create(self);
  with frmSysLogHelp do
  begin
    fModel := self.caption;
  //  facction:='生产指示单删除';
    showmodal;
    free;
  end;
end;

end.

