unit U_ShaRKInPutWSQ;

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, StdCtrls, ExtCtrls;

type
  TfrmShaRKInPutWSQ = class(TForm)
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v2SPName: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    ToolBar1: TToolBar;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBSave: TToolButton;
    TBClose: TToolButton;
    v1CRType: TcxGridDBColumn;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column12: TcxGridDBColumn;
    v1FactoryName: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1SPCF: TcxGridDBColumn;
    v1SPSpec: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1BatchNo: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1SPNameGYS: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column14PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column5PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column11PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure v1Column10PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column8PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column15PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column7PropertiesEditValueChanged(Sender: TObject);
  private
    { Private declarations }
    FSPType,FDelStr:String;
    function SaveCKData():Boolean;
  public
    { Public declarations }
    FBCId,canshu3,FCRType,FHZCRType,ZHFlag:String;

  end;

var
  frmShaRKInPutWSQ: TfrmShaRKInPutWSQ;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp,
  U_ZdyAttachCP,U_ZdyAttachGYS;

{$R *.dfm}

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

procedure TfrmShaRKInPutWSQ.TBAddClick(Sender: TObject);
begin
   with CDS_Sub do
  begin
    Append;
    FieldByName('CRTime').Value:=Trim(FormatDateTime('yyyy-MM-dd',Now));
    FieldByName('QtyUnit').Value:='Kg';
    FieldByName('CRType').Value:=FCRType;
    Post;
  end;
end;
function TfrmShaRKInPutWSQ.SaveCKData():Boolean;
var
  FCRID,Maxno,FFSPID,FQMID,maxMXId:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
          open;
        end;
        FFSPID:=Trim(ADOQueryTemp.fieldbyname('SPID').AsString);
        if Trim(FFSPID)='' then
        begin
          if GetLSNo(ADOQueryCmd,Maxno,'SR','CK_SXPB_CR',3,1)=False then
          begin
            Result:=False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取纱线入库编号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          Maxno:=Trim(FFSPID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(Maxno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FFSPID)='' then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('SPID').Value:=Trim(Maxno);
          FieldByName('FZSPID').Value:=Trim(Maxno);
          FieldByName('CKName').Value:='纱线';
          FieldByName('FactoryNo').Value:=Trim(CDS_Sub.fieldbyname('FactoryNo').AsString);
          FieldByName('FromFactoryNo').Value:=Trim(CDS_Sub.fieldbyname('FromFactoryNo').AsString);
          FieldByName('ToFactoryNo').Value:=Trim(CDS_Sub.fieldbyname('ToFactoryNo').AsString);
          FieldByName('CPID').Value:=Trim(CDS_Sub.fieldbyname('CPID').AsString);
          FieldByName('SQID').Value:=CDS_Sub.fieldbyname('SQID').Value;
          FieldByName('Price').Value:=CDS_Sub.fieldbyname('Price').Value;
          FieldByName('FromSPID').Value:=CDS_Sub.fieldbyname('FromSPID').Value;//回仓有值
          FieldByName('QtySXStr').Value:=CDS_Sub.fieldbyname('QtySXStr').Value;//回仓有值
          FieldByName('CRFlag').Value:='入库';
          FieldByName('HZCRType').Value:=Trim(FHZCRType);
          FieldByName('CRQtyFlag').Value:=1;
          //FieldByName('CRID').Value:=FCRID;
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,CDS_Sub,'CK_SXPB_CR',2);
          if Trim(FFSPID)='' then
            FieldByName('Filler').Value:=Trim(DName)
          else
          begin
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDate(ADOQueryTemp);
          end;
          Post;
        end;
        if Trim(FHZCRType)='加工未做回仓' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update CK_SXPB_CR Set HCPS=(select Sum(PiQty) from CK_SXPB_CR A where A.FromSPID=CK_SXPB_CR.SPID and A.ZFFlag=0)');
            sql.Add(', HCQty=(select Sum(Qty) from CK_SXPB_CR A where A.FromSPID=CK_SXPB_CR.SPID and A.ZFFlag=0)');
            sql.Add(' where SPID='''+Trim(CDS_Sub.fieldbyname('FromSPID').AsString)+'''');
            ExecSQL;
          end;
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add(' select A.* ');
            SQL.Add(' from CK_SXPB_CR A  ');
            sql.Add(' where isnull(Qty,0)<isnull(HCQty,0)');
            sql.Add(' and SPID='''+Trim(CDS_Sub.fieldbyname('FromSPID').AsString)+'''');
            Open;
          end;
          if ADOQueryTemp.IsEmpty=False then
          begin
            CDS_Sub.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox(PChar('纱线：'+Trim(CDS_Sub.fieldbyname('SPName').AsString)+' 回仓数量大于出库数量不能保存！'),'提示',0);
            exit;
          end;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update CK_SXPB_CR Set MXKCQty=(select sum(isnull(Qty,0)*CRQtyFlag) from CK_SXPB_CR A where A.FZSPID=CK_SXPB_CR.SPID and A.ZFFlag=0)');
          sql.Add(',MXKCPiQty=(select sum(isnull(PiQty,0)*CRQtyFlag) from CK_SXPB_CR A where A.FZSPID=CK_SXPB_CR.SPID  and A.ZFFlag=0)');
          sql.Add(' where SPID='''+Trim(Maxno)+'''');
          ExecSQL;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID='''+Trim(Maxno)+'''');
          Open;
        end;
        if ADOQueryTemp.FieldByName('MXKCQty').Value<0 then
        begin
          CDS_Sub.DisableControls;
          ADOQueryCmd.Connection.RollbackTrans;
          Application.MessageBox('入库数小于出库数不能保存!','提示',0);
          Exit;
        end;
        Edit;
        FieldByName('SPID').Value:=Trim(Maxno);
        //FieldByName('CRID').Value:=Trim(FCRID);
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
  
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;

end;
procedure TfrmShaRKInPutWSQ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption),Tv1,'纱线仓库');
  Close;
end;

procedure TfrmShaRKInPutWSQ.FormShow(Sender: TObject);
var
  fsj:String;
begin
  ReadCxGrid(trim(Self.Caption),Tv1,'纱线仓库');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from CK_SXPB_CR A');
    sql.Add(' where SPID='''+Trim(FBCId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Sub);
  SInitCDSData20(ADOQueryTemp,CDS_Sub);

end;

procedure TfrmShaRKInPutWSQ.TBDelClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if Trim(CDS_Sub.fieldbyname('SPID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where FZSPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
      sql.Add(' and CRQtyFlag=-1');
      Open;
    end;
    if ADOQueryTemp.IsEmpty=False then
    begin
      Application.MessageBox('已有出库记录，不能删除!','提示',0);
      Exit;
    end;
    try
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete CK_SXPB_CR where SPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
        ExecSQL;
      end;
 
     
      ADOQueryCmd.Connection.CommitTrans;
      CDS_Sub.Delete;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!','提示',0);
    end;

  end else
  begin
    CDS_Sub.Delete;
  end;

end;

procedure TfrmShaRKInPutWSQ.TBSaveClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  //if CDS_MX.IsEmpty then Exit;
  if CDS_Sub.Locate('CRTime',null,[])=True then
  begin
    Application.MessageBox('发货时间不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('CRType',null,[])=True then
  begin
    Application.MessageBox('发货类型不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('SPName',null,[])=True then
  begin
    Application.MessageBox('品名不能为空!','提示',0);
    Exit;
  end;
 
  if CDS_Sub.Locate('FactoryName',null,[])=True then
  begin
    Application.MessageBox('纱线供应商不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('PiQty',null,[])=True then
  begin
    Application.MessageBox('箱/件数不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('Qty',null,[])=True then
  begin
    Application.MessageBox('数量不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('QtyUnit',null,[])=True then
  begin
    Application.MessageBox('数量单位不能为空!','提示',0);
    Exit;
  end;
  if SaveCKData() then
  begin
    if Trim(FDelStr)<>'有提示' then
    Application.MessageBox('保存成功!','提示',0);
    //ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SXKuWei';
      flagname:='库位';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('KuWei').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column14PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin                                                   
          Edit;
          FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('CoName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;

end;

procedure TfrmShaRKInPutWSQ.v2Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if Trim(canshu3)='' then
  begin
    try
      frmZDYHelp:=TfrmZDYHelp.Create(Application);
      with frmZDYHelp do
      begin
        flag:='SXYCLName';
        flagname:='纱线名称';
//        ViewFlag:=True;
        if ShowModal=1 then
        begin
          with Self.CDS_Sub do
          begin
            Edit;
            FieldByName('SPName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
            FieldByName('SPNameGYS').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          end;
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
  end else
  begin
    try
      frmZdyAttachCP:=TfrmZdyAttachCP.Create(Application);
      with frmZdyAttachCP do
      begin
        if ShowModal=1 then
        begin
          with Self.CDS_Sub do
          begin
            Edit;
            FieldByName('SPName').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ZdyName').AsString);
            FieldByName('SPSpec').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr1').AsString);
            FieldByName('SPCF').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr2').AsString);
            FieldByName('SPMF').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr7').AsString);
            FieldByName('SPKZ').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr8').AsString);
            FieldByName('SPKZ').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('DEFstr8').AsString);
            FieldByName('SPCode').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ZdyCode').AsString);
            FieldByName('CPID').Value:=Trim(frmZdyAttachCP.CDS_HZ.fieldbyname('ATID').AsString);
          end;
        end;
      end;
    finally
      frmZdyAttachCP.Free;
    end;
  end;

end;

procedure TfrmShaRKInPutWSQ.v1Column5PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SXKuWei';
      flagname:='库位';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('KuWei').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column11PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do            
        begin
          Edit;
          FieldByName('ToFactoryNo').Value:=Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          FieldByName('ToFactoryName').Value:=Trim(CDS_HZ.fieldbyname('CoName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;

end;

procedure TfrmShaRKInPutWSQ.v1Column16PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS:=TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;                                                        
          FieldByName('FromFactoryNo').Value:=Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          FieldByName('FromFactoryName').Value:=Trim(CDS_HZ.fieldbyname('CoName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
  
  {try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFFactory';
      flagname:='加工厂';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('FromFactoryNo').Value:=Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('FromFactoryName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end; }
end;

procedure TfrmShaRKInPutWSQ.Tv1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if CDS_Sub.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_SXPB_CR where FZSPID='''+Trim(CDS_Sub.fieldbyname('SPID').AsString)+'''');
    sql.Add(' and CRQtyFlag=-1 and ZFFlag=0 ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty=False then
  begin
   
    v1FactoryName.Options.Editing:=False;
     
    v2SPName.Options.Editing:=False;
    v1SPNameGYS.Options.Editing:=False;
    v1SPSpec.Options.Editing:=False;
    v1SPCF.Options.Editing:=False;
    v1BatchNo.Options.Editing:=False;
     
  end;
 
end;

procedure TfrmShaRKInPutWSQ.v1Column10PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTT';
      flagname:='公司抬头';
      frmZDYHelp.TBAdd.Visible:=False;
      frmZDYHelp.TBDel.Visible:=False;
      frmZDYHelp.TBEdit.Visible:=False;
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column8PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SXSPSpec';
      flagname:='纱线规格';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPSpec').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SXSPCF';
      flagname:='纱线成分';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPCF').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column15PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SXPinPai';
      flagname:='纱线品牌';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SXPinPai').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmShaRKInPutWSQ.v1Column7PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
  FQty,FPrice,FCostPrice,FMoney,FBBMoney:double;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
   with CDS_Sub do
  begin
    Edit;
    FieldByName(FFieldName).Value:=mvalue;
    Post;
  end;
  FQty:= CDS_Sub.fieldbyname('Qty').AsFloat;
  FPrice:= CDS_Sub.fieldbyname('Price').AsFloat;
  FCostPrice:= CDS_Sub.fieldbyname('CostPrice').AsFloat;
  FMoney:=CDS_Sub.fieldbyname('Money').AsFloat;
  if  FQty>0 then
    FPrice:=RoundFloat(FMoney/FQty,2)
  else
    FPrice:=0;

  with CDS_Sub do
  begin
    Edit;
    FieldByName('Price').Value:=FPrice;
    Post;
  end;

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

end.
