unit U_CP_YDang_MTBJ_Sub;

interface

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

type
  TfrmCP_YDang_MTBJ_Sub = class(TForm)
    ToolBar1: TToolBar;
    Tsave: TToolButton;
    TClose: TToolButton;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    TAdd: TToolButton;
    TDel: TToolButton;
    ADOQueryTmp: TADOQuery;
    ADOQueryCMD: TADOQuery;
    DataSource1: TDataSource;
    contract_Sub: TClientDataSet;
    Label4: TLabel;
    SQdate: TDateTimePicker;
    Label6: TLabel;
    SQ: TBtnEditA;
    Label8: TLabel;
    ConPerson1: TBtnEditA;
    JGprice: TEdit;
    afterprice: TEdit;
    JGafter: TEdit;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label15: TLabel;
    CustomerNoName: TBtnEditA;
    Label1: TLabel;
    BJNote: TMemo;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1PRTCodeName: TcxGridDBColumn;
    V1PRTSpec: TcxGridDBColumn;
    V1PriceUnit: TcxGridDBColumn;
    V1PRTCF: TcxGridDBColumn;
    V1PRTOrderQty: TcxGridDBColumn;
    V1OrderUnit: TcxGridDBColumn;
    V1MFQty: TcxGridDBColumn;
    V1KZQty: TcxGridDBColumn;
    V1SOrdQty5: TcxGridDBColumn;
    V1SOrdQty6: TcxGridDBColumn;
    V1SOrdQty7: TcxGridDBColumn;
    V1SOrdQty8: TcxGridDBColumn;
    V1SOrdQty9: TcxGridDBColumn;
    V1SOrdQty10: TcxGridDBColumn;
    V1SOrdQty11: TcxGridDBColumn;
    V1SOrdQty12: TcxGridDBColumn;
    V1SOrdQty13: TcxGridDBColumn;
    V1Note: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    V1SOrdQty2: TcxGridDBColumn;
    Label2: TLabel;
    BJtime: TDateTimePicker;
    V1BJXS: TcxGridDBColumn;
    V1PBMF: TcxGridDBColumn;
    V1PBKZ: TcxGridDBColumn;
    V1PBSPEC: TcxGridDBColumn;
    V1PRTCode: TcxGridDBColumn;
    V1BJPrice: TcxGridDBColumn;
    CustomerNo: TEdit;
    V1SOrddefstr1: TcxGridDBColumn;
    V1CBPrice: TcxGridDBColumn;
    V1HuiLv: TcxGridDBColumn;
    V1BJEPrice: TcxGridDBColumn;
    V1QDLQty: TcxGridDBColumn;
    V1PBFK: TcxGridDBColumn;
    Label3: TLabel;
    YWTel: TBtnEditA;
    V1JQDate: TcxGridDBColumn;
    V1Column1: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure TCloseClick(Sender: TObject);
    procedure TAddClick(Sender: TObject);
    procedure TDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TsaveClick(Sender: TObject);
    procedure TVOrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure ConPerson1BtnClick(Sender: TObject);
    procedure CustomerNoNameBtnClick(Sender: TObject);
    procedure V1PRTCodePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1YPNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1PRTSpecPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1PRTCodeNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1BJXSPropertiesEditValueChanged(Sender: TObject);
    procedure V1SOrddefstr1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1SOrdQty1PropertiesEditValueChanged(Sender: TObject);
    procedure V1SOrdQty2PropertiesEditValueChanged(Sender: TObject);
    procedure V1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1PriceUnitPropertiesEditValueChanged(Sender: TObject);
    procedure V1PBKZPropertiesEditValueChanged(Sender: TObject);
    procedure YWTelBtnClick(Sender: TObject);
  private
    procedure InitData();
    function  SaveData():Boolean;
    { Private declarations }
  public
    formid: integer;
    Fint: integer;
    FMainid: string;
    fTYPE: string;
    { Public declarations }
  end;

var
  frmCP_YDang_MTBJ_Sub: TfrmCP_YDang_MTBJ_Sub;

implementation

uses U_fun, U_ZDYHelp,U_DataLink,U_ZDYHelpSel,U_CPManage_BJ, U_FileUp_SQ,U_ZdyAttachment_CX;

{$R *.dfm}

procedure TfrmCP_YDang_MTBJ_Sub.Initdata();
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('select * from CP_YDang_MTBJ_Main where Mainid='''+trim(FMainid)+'''');
    open;
    if not isempty then
    begin
      BJTIME.DateTime:=fieldbyname('BJTIME').AsDateTime;
      BJNOTE.Text:=trim(fieldbyname('BJnote').AsString);
      CustomerNoName.Text:=trim(fieldbyname('CustomerNoName').asstring);
      ConPerson1.Text:=trim(fieldbyname('ConPerson1').asstring);
    end;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.clear;
    sql.Add('select * from CP_YDang_MTBJ_Sub ');
    //sql.add('left join TP_File TP on TP.WBID=A.SOrddefstr1 ');
    sql.Add(' where Mainid='''+trim(FMainid)+'''');
    open;
  end;
  SCreateCDS20(ADOQuerycmd,contract_Sub);
  SInitCDSData20(ADOQuerycmd,contract_Sub);
end;

function TfrmCP_YDang_MTBJ_Sub.SaveData(): boolean;
var FSubid: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOQueryCmd,FMainId,'MTBJ','CP_YDang_MTBJ_Main',3,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end;
    with ADOQuerycmd do
    begin
      close;
      sql.Clear;
      sql.add('select * from CP_YDang_MTBJ_Main where Mainid='''+trim(Fmainid)+'''');
      open;
      if isempty then
      begin
        append;
        fieldbyname('filltime').AsDateTime:=SGetServerDateTime(ADOQueryTmp);
        fieldbyname('filler').asstring:=trim(DName);
      end
      else
      begin
        edit;
      end;
      SSetsaveSqlNew(ADOQuerycmd,'CP_YDang_MTBJ_Main',Panel1,2);
      fieldbyname('Mainid').AsString:=trim(Fmainid);
      if formid<>99 then
      fieldbyname('status').AsString:='0'
      else
      fieldbyname('status').AsString:='1';
      post;
    end;
    with contract_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(contract_sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,FSubid,'B','CP_YDang_MTBJ_Sub',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取流水号失败!','提示',0);
            Exit;
          end;
        end
        else
        begin
          Fsubid:=trim(contract_sub.fieldbyname('subID').asstring);
        end;
        with ADOQuerycmd do
        begin
          close;
          sql.Clear;
          sql.Add('select * from CP_YDang_MTBJ_Sub where Mainid='''+trim(Fmainid)+''' ');
          sql.Add('and Subid='''+trim(FSubid)+'''');
          open;
          if isempty then
          begin
            append;
          end
          else
          begin
            edit;
          end;
          fieldbyname('Mainid').AsString:=trim(Fmainid);
          fieldbyname('Subid').asstring:=trim(Fsubid);
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,contract_Sub,'CP_YDang_MTBJ_Sub',0);
          fieldbyname('PRTOrderQty').Value:=contract_sub.fieldbyname('PRTOrderQty').AsFloat;
          fieldbyname('SOrdQty1').Value:=contract_sub.fieldbyname('SOrdQty1').AsFloat;
          fieldbyname('BJEPrice').Value:=contract_sub.fieldbyname('BJEPrice').AsFloat;
          fieldbyname('SOrdQty2').Value:=contract_sub.fieldbyname('SOrdQty2').AsFloat;
          fieldbyname('SOrdQty3').Value:=contract_sub.fieldbyname('SOrdQty3').AsFloat;
          fieldbyname('SOrdQty4').Value:=contract_sub.fieldbyname('SOrdQty4').AsFloat;
          fieldbyname('SOrdQty5').Value:=contract_sub.fieldbyname('SOrdQty5').AsFloat;
          fieldbyname('SOrdQty6').Value:=contract_sub.fieldbyname('SOrdQty6').AsFloat;
          fieldbyname('SOrdQty7').Value:=contract_sub.fieldbyname('SOrdQty7').AsFloat;
          fieldbyname('SOrdQty8').Value:=contract_sub.fieldbyname('SOrdQty8').AsFloat;
          fieldbyname('SOrdQty9').Value:=contract_sub.fieldbyname('SOrdQty9').AsFloat;
          fieldbyname('SOrdQty10').Value:=contract_sub.fieldbyname('SOrdQty10').AsFloat;
          fieldbyname('SOrdQty11').Value:=contract_sub.fieldbyname('SOrdQty11').AsFloat;
          fieldbyname('SOrdQty12').Value:=contract_sub.fieldbyname('SOrdQty12').AsFloat;
          fieldbyname('SOrdQty13').Value:=contract_sub.fieldbyname('SOrdQty13').AsFloat;
          fieldbyname('SOrdQty14').Value:=contract_sub.fieldbyname('SOrdQty14').AsFloat;
          fieldbyname('SOrdQty15').Value:=contract_sub.fieldbyname('SOrdQty15').AsFloat;
          fieldbyname('QDLQty').Value:=contract_sub.fieldbyname('QDLQty').AsFloat;
          fieldbyname('PBMF').Value:=contract_sub.fieldbyname('PBMF').AsFloat;
          fieldbyname('PBKZ').Value:=contract_sub.fieldbyname('PBKZ').AsFloat;
          fieldbyname('BJXS').Value:=contract_sub.fieldbyname('BJXS').AsFloat;
          fieldbyname('Huilv').Value:=contract_sub.fieldbyname('Huilv').AsFloat;
          fieldbyname('CBPrice').Value:= contract_sub.fieldbyname('CBPrice').AsFloat;
//          contract_sub.fieldbyname('SOrdQty2').AsFloat/(1-contract_sub.fieldbyname('SOrdQty1').AsFloat/100)
//                                        +contract_sub.fieldbyname('SOrdQty5').AsFloat+contract_sub.fieldbyname('SOrdQty6').AsFloat
//                                        +contract_sub.fieldbyname('SOrdQty7').AsFloat+contract_sub.fieldbyname('SOrdQty8').AsFloat
//                                        +contract_sub.fieldbyname('SOrdQty9').AsFloat+contract_sub.fieldbyname('SOrdQty10').AsFloat
//                                        +contract_sub.fieldbyname('SOrdQty11').AsFloat+contract_sub.fieldbyname('SOrdQty12').AsFloat
//                                        +contract_sub.fieldbyname('SOrdQty13').AsFloat;
          if contract_sub.fieldbyname('Huilv').AsFloat<>0 then
          fieldbyname('BJPrice').Value:=fieldbyname('CBPrice').AsFloat*contract_sub.fieldbyname('BJXS').AsFloat/contract_sub.FieldByName('Huilv').AsFloat
          else
          fieldbyname('BJPrice').Value:=contract_sub.fieldbyname('BJPrice').AsFloat;
          post;
        end;
        contract_sub.Edit;
        contract_sub.FieldByName('SubId').Value:=Trim(FSubid);
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！','提示');
    ModalResult:=1;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示');
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alclient;
end;

procedure TfrmCP_YDang_MTBJ_Sub.TCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmCP_YDang_MTBJ_Sub.TAddClick(Sender: TObject);
begin
  with contract_Sub do
  begin
    append;
    FieldByName('HuiLv').AsFloat:=1;
    FieldByName('PRTSpec').AsFloat:=1;
    FieldByName('PRTKZ').AsFloat:=1;
    FieldByName('HCPrice').AsFloat:=0;
    FieldByName('SOrdQty2').AsFloat:=1;
    FieldByName('BJXS').AsFloat:=1;
    post;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.TDelClick(Sender: TObject);
begin
  IF Contract_Sub.IsEmpty then exit;
  with ADOQueryTmp do
  begin
    close;
    sql.Clear;
    sql.add('delete from CP_YDang_MTBJ_Sub where Subid='+quotedstr(trim(contract_Sub.fieldbyname('Subid').AsString)));
    execsql;
  end;
  contract_Sub.delete;
end;

procedure TfrmCP_YDang_MTBJ_Sub.FormShow(Sender: TObject);
begin
  ReadCxGrid('MTINPUT',Tv1,'面料报价管理');
  SQdate.DateTime:=SGetServerDateTime(ADOQueryTmp);
  BJtime.DateTime:=SGetServerDateTime(ADOQueryTmp);
  ConPerson1.Text:=trim(DName);
  {if Formid<>99 then
  begin
    V1PriceUnit.Visible:=False;
    V1BJPrice.Options.Editing:=False;
    V1CBPrice.Visible:=False;
    V1HuiLv.Visible:=False;
    V1BJXS.Visible:=False;
    V1PBMF.Visible:=False;
    V1PBKZ.Visible:=False;
    V1BJPrice.visible:=False;
    V1PBSPEC.Visible:=False;
    V1SOrdQty1.Visible:=False;
    V1SOrdQty2.Visible:=False;
    V1SOrdQty5.Visible:=False;
    V1SOrdQty6.Visible:=False;
    V1SOrdQty7.Visible:=False;
    V1SOrdQty8.Visible:=False;
    V1SOrdQty9.Visible:=False;
    V1SOrdQty10.Visible:=False;
    V1SOrdQty11.Visible:=False;
    V1SOrdQty12.Visible:=False;
    V1SOrdQty13.Visible:=False;
  end;}
  Initdata();
  if Formid=99 then
  begin
    BJtime.DateTime:=SGetServerDateTime(ADOQueryTmp);
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.TsaveClick(Sender: TObject);
begin
  writeCxGrid('MTINPUT',Tv1,'面料报价管理');
  if CustomerNoName.Text='' then
  begin
    application.MessageBox('客户不能为空','');
    exit;
  end;
  if contract_sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  SaveData();
end;

procedure TfrmCP_YDang_MTBJ_Sub.TVOrderUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  writeCxGrid(self.Caption+tv1.Name+'1',Tv1);
  Action:=cafree;
end;

procedure TfrmCP_YDang_MTBJ_Sub.FormDestroy(Sender: TObject);
begin
  frmCP_YDang_MTBJ_Sub:=nil;
end;

procedure TfrmCP_YDang_MTBJ_Sub.ConPerson1BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flagname:='业务员';
      flag:='ConPerson1';
      if ShowModal=1 then
      begin
        ConPerson1.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.CustomerNoNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachment_CX:=TfrmZdyAttachment_CX.Create(Application);
    with frmZdyAttachment_CX do
    begin
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(CDS_HZ.fieldbyname('ZDYName').AsString);
        CustomerNo.Text:=Trim(CDS_HZ.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZdyAttachment_CX.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PRTCodePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flagname:='产品编号';
      flag:='PRTCode';
      fnote:=true;
      V1Note.Caption:='中文名称';
      V1Name.Caption:='编号';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.contract_Sub.FieldByName('PRTCodeName').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1YPNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flagname:='样品名称';
      flag:='YPName';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('YPName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PRTSpecPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTSpec';
      flagname:='规格型号';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('PRTSpec').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PRTCodeNamePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  FrmCPManage_BJ:=TFrmCPManage_BJ.create(Self);
  with FrmCPManage_BJ do
  begin
    if showmodal=1 then
    begin
        with contract_Sub do
        begin
          Edit;
          Fieldbyname('SOrddefstr1').Value:=CDS_Main.fieldbyname('WBID').asstring;
          Fieldbyname('PRTCode').Value:=CDS_Main.fieldbyname('CYNo').asstring;
          Fieldbyname('PRTCF').Value:=CDS_Main.fieldbyname('CYCF').asstring;
          Fieldbyname('PRTMF').Value:=CDS_Main.fieldbyname('CYMF').asstring;
          Fieldbyname('SOrdQty1').Value:=CDS_Main.fieldbyname('price1').AsFloat;
          Fieldbyname('SOrdQty2').Value:=CDS_Main.fieldbyname('Price2').AsFloat;
        end;
//      with ADOQueryTmp do
//      begin
//        close;
//        sql.Clear;
//        sql.Add('select Top 1 A.* from CP_YDang_MTBJ_Sub A ');
//        Sql.add('inner join CP_YDang_BJ_Main B on B.Mainid=A.Mainid ');
//        sql.add('where A.PRTCode='''+trim(FrmCPManage_BJ.CDS_Main.fieldbyname('CYNo').AsString)+'''');
//        sql.add(' and B.status<>0');
//        sql.add(' order by B.Filltime desc');
//        open;
//      end;
//      if ADOqueryTmp.IsEmpty=false then
//      begin
//        with contract_Sub do
//        begin
//          Edit;
//          Fieldbyname('PRTCodeName').Value:=ADOQueryTmp.fieldbyname('PRTCodeName').asstring;
//          Fieldbyname('SOrddefstr1').Value:=ADOQueryTmp.fieldbyname('SOrddefstr1').asstring;
//          Fieldbyname('PRTCode').Value:=ADOQueryTmp.fieldbyname('PRTCode').asstring;
//          Fieldbyname('PRTSpec').Value:=ADOQueryTmp.fieldbyname('PRTSpec').AsFloat;
//          Fieldbyname('PRTCF').Value:=ADOQueryTmp.fieldbyname('PRTCF').asstring;
//          Fieldbyname('PRTMF').Value:=ADOQueryTmp.fieldbyname('PRTMF').asstring;
//          Fieldbyname('PRTKZ').Value:=ADOQueryTmp.fieldbyname('PRTKZ').AsFloat;
//          Fieldbyname('SOrdQty1').Value:=ADOQueryTmp.fieldbyname('SOrdQty1').AsFloat;
//          Fieldbyname('SOrdQty2').Value:=ADOQueryTmp.fieldbyname('SOrdQty2').AsFloat;
//          Fieldbyname('OrderUnit').Value:=ADOQueryTmp.fieldbyname('OrderUnit').asstring;
//          Fieldbyname('PBSPEC').Value:=ADOQueryTmp.fieldbyname('PBSPEC').asstring;
//          Fieldbyname('PBMF').Value:=ADOQueryTmp.fieldbyname('PBMF').asstring;
//          Fieldbyname('PBKZ').Value:=ADOQueryTmp.fieldbyname('PBKZ').asstring;
//          Fieldbyname('BJXS').Value:=ADOQueryTmp.fieldbyname('BJXS').AsFloat;
//          Fieldbyname('BJPrice').Value:=ADOQueryTmp.fieldbyname('BJPrice').AsFloat;
//          Fieldbyname('PriceUnit').Value:=ADOQueryTmp.fieldbyname('PriceUnit').asstring;
//          Fieldbyname('HuiLv').Value:=ADOQueryTmp.fieldbyname('HuiLv').AsFloat;
//          Fieldbyname('CBPrice').Value:=ADOQueryTmp.fieldbyname('CBPrice').AsFloat;
//          Fieldbyname('SOrdQty5').Value:=ADOQueryTmp.fieldbyname('SOrdQty5').AsFloat;
//          Fieldbyname('SOrdQty6').Value:=ADOQueryTmp.fieldbyname('SOrdQty6').AsFloat;
//          Fieldbyname('SOrdQty7').Value:=ADOQueryTmp.fieldbyname('SOrdQty7').AsFloat;
//          Fieldbyname('SOrdQty8').Value:=ADOQueryTmp.fieldbyname('SOrdQty8').AsFloat;
//          Fieldbyname('SOrdQty9').Value:=ADOQueryTmp.fieldbyname('SOrdQty9').AsFloat;
//          Fieldbyname('SOrdQty10').Value:=ADOQueryTmp.fieldbyname('SOrdQty10').AsFloat;
//          Fieldbyname('SOrdQty11').Value:=ADOQueryTmp.fieldbyname('SOrdQty11').AsFloat;
//          Fieldbyname('SOrdQty12').Value:=ADOQueryTmp.fieldbyname('SOrdQty12').AsFloat;
//          Fieldbyname('SOrddefstr1').Value:=ADOQueryTmp.fieldbyname('SOrddefstr1').asstring;
//          Fieldbyname('SOrdQty13').Value:=ADOQueryTmp.fieldbyname('SOrdQty13').AsFloat;
//        end;
//      end
//      else
//      begin
//        with contract_Sub do
//        begin
//          Edit;
//          Fieldbyname('PRTCodeName').Value:=CDS_Main.fieldbyname('CYName').asstring;
//          Fieldbyname('SOrddefstr1').Value:=CDS_Main.fieldbyname('WBID').asstring;
//          Fieldbyname('PRTCode').Value:=CDS_Main.fieldbyname('CYNo').asstring;
//          Fieldbyname('PRTSpec').Value:=CDS_Main.fieldbyname('CYSpec').asstring;
//          Fieldbyname('PRTCF').Value:=CDS_Main.fieldbyname('CYCF').asstring;
//          Fieldbyname('PRTMF').Value:=CDS_Main.fieldbyname('CYMF').asstring;
//          Fieldbyname('PRTKZ').Value:=CDS_Main.fieldbyname('CYKZ').asstring;
//          Fieldbyname('SOrdQty1').Value:=CDS_Main.fieldbyname('price1').AsFloat;
//          Fieldbyname('SOrdQty2').Value:=CDS_Main.fieldbyname('Price2').AsFloat;
//        end;
 //     end;
    end;
    Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1OrderUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1BJXSPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  FXS:String;
begin
  FXS:=floattostr(contract_sub.fieldbyname('SOrdQty2').AsFloat/(1-contract_sub.fieldbyname('SOrdQty1').AsFloat/100)
                                        +contract_sub.fieldbyname('SOrdQty5').AsFloat+contract_sub.fieldbyname('SOrdQty6').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty7').AsFloat+contract_sub.fieldbyname('SOrdQty8').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty9').AsFloat+contract_sub.fieldbyname('SOrdQty10').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty11').AsFloat+contract_sub.fieldbyname('SOrdQty12').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty13').AsFloat);
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;

  with contract_Sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FieldByName('CBPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)]));
    FieldByName('BJPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)*Fieldbyname('BJXS').AsFloat]));
  end;
  //Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1SOrddefstr1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmFileUp_SQ:=TfrmFileUp_SQ.Create(Application);
    with frmFileUp_SQ do
    begin
      Code.Text:=Trim(Self.contract_Sub.fieldbyname('PRTCode').AsString);
      CYID:=Trim(Self.contract_Sub.fieldbyname('SOrddefstr1').AsString);
      if ShowModal=1 then
      begin
        with contract_Sub do
        begin
          edit;
          fieldbyname('SOrddefstr1').AsString:=Trim(ADOQueryFile.fieldbyname('CYID').asstring);
        end;
      end;
    end;
  finally
    frmFileUp_SQ.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1SOrdQty1PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  FXS:String;
begin
  if trim(TcxTextEdit(Sender).EditingText)='' then
  TcxTextEdit(Sender).EditingText:='0';
  FXS:=floattostr(contract_sub.fieldbyname('SOrdQty2').AsFloat/(1-contract_sub.fieldbyname('SOrdQty1').AsFloat/100)
                                        +contract_sub.fieldbyname('SOrdQty5').AsFloat+contract_sub.fieldbyname('SOrdQty6').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty7').AsFloat+contract_sub.fieldbyname('SOrdQty8').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty9').AsFloat+contract_sub.fieldbyname('SOrdQty10').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty11').AsFloat+contract_sub.fieldbyname('SOrdQty12').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty13').AsFloat);
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;

  with contract_Sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FieldByName('CBPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)]));
    FieldByName('BJPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)*Fieldbyname('BJXS').AsFloat]));
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1SOrdQty2PropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  FXS:String;
begin
  if TcxTextEdit(Sender).EditingText='' then
  TcxTextEdit(Sender).EditingText:='0';
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with contract_Sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;

    FXS:=floattostr(contract_sub.fieldbyname('SOrdQty2').AsFloat*contract_sub.fieldbyname('PRTSpec').AsFloat*contract_sub.fieldbyname('PRTKZ').AsFloat
                                        +contract_sub.fieldbyname('HCPrice').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty5').AsFloat+contract_sub.fieldbyname('SOrdQty6').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty7').AsFloat+contract_sub.fieldbyname('SOrdQty8').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty9').AsFloat+contract_sub.fieldbyname('SOrdQty10').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty11').AsFloat+contract_sub.fieldbyname('SOrdQty12').AsFloat
                                        +contract_sub.fieldbyname('SOrdQty13').AsFloat);
    FieldByName('CBPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)]));
    if fieldbyname('Huilv').AsFloat<>0 then
    FieldByName('BJPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)*Fieldbyname('BJXS').AsFloat/FieldByName('Huilv').AsFloat]))
    else
    begin
      FieldByName('BJPrice').Value:=0;
      application.MessageBox('汇率不能为0','提示',0);
      exit;
    end;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PriceUnitPropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='币种';
      if ShowModal=1 then
      begin
        Self.contract_Sub.Edit;
        Self.contract_Sub.FieldByName('PriceUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PriceUnitPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
begin
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with contract_Sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    if TcxTextEdit(Sender).EditingText='￥' then
    begin
      fieldbyname('Huilv').AsFloat:=1;
    end;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCP_YDang_MTBJ_Sub.V1PBKZPropertiesEditValueChanged(
  Sender: TObject);
var
  Fieldname:string;
  FXS:String;
begin
  if TcxTextEdit(Sender).EditingText='' then
  TcxTextEdit(Sender).EditingText:='0';
  Fieldname:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with contract_Sub do
  begin
    edit;
    fieldbyname(Fieldname).Value:=TcxTextEdit(Sender).EditingText;
    FXS:=floattostr(contract_sub.fieldbyname('PBMF').AsFloat*contract_sub.fieldbyname('PBFK').AsFloat*contract_sub.fieldbyname('PBKZ').AsFloat
                    *contract_sub.fieldbyname('SOrdQty2').AsFloat/(1-contract_sub.fieldbyname('SOrdQty1').AsFloat/100)
                    +contract_sub.fieldbyname('SOrdQty5').AsFloat+contract_sub.fieldbyname('SOrdQty6').AsFloat
                    +contract_sub.fieldbyname('SOrdQty7').AsFloat+contract_sub.fieldbyname('SOrdQty8').AsFloat
                    +contract_sub.fieldbyname('SOrdQty9').AsFloat+contract_sub.fieldbyname('SOrdQty10').AsFloat
                    +contract_sub.fieldbyname('SOrdQty11').AsFloat+contract_sub.fieldbyname('SOrdQty12').AsFloat
                    +contract_sub.fieldbyname('SOrdQty13').AsFloat);
    FieldByName('CBPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)]));
    if fieldbyname('Huilv').AsFloat<>0 then
    FieldByName('BJPrice').Value:=strtofloat(format('%.2f',[strtofloat(FXS)*Fieldbyname('BJXS').AsFloat/FieldByName('Huilv').AsFloat]))
    else
    begin
      FieldByName('BJPrice').Value:=0;
      application.MessageBox('汇率不能为0','提示',0);
      exit;
    end;
  end;
  Tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCP_YDang_MTBJ_Sub.YWTelBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flagname:='手机';
      flag:='YWTel';
      if ShowModal=1 then
      begin
        YWTel.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
