unit U_ConInPut_CBYG;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxGridCustomPopupMenu,
  cxGridPopupMenu, cxCurrencyEdit, cxGridBandedTableView,
  cxGridDBBandedTableView, cxDropDownEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmConInPut_CBYG = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    Label9: TLabel;
    DEFStr7: TEdit;
    Label10: TLabel;
    YGNo: TEdit;
    Label14: TLabel;
    CustomerNoName: TBtnEditC;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOCmd: TADOQuery;
    ScrollBox1: TScrollBox;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Panel5: TPanel;
    Panel3: TPanel;
    ToolBar4: TToolBar;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBBandedTableView;
    TV3PrtCodeName: TcxGridDBBandedColumn;
    TV3Qty: TcxGridDBBandedColumn;
    TV3PRTPrice: TcxGridDBBandedColumn;
    TV3Money: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    Panel2: TPanel;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    cxGrid2: TcxGrid;
    TV4: TcxGridDBBandedTableView;
    TV4PrtCodeName: TcxGridDBBandedColumn;
    TV4XLQty: TcxGridDBBandedColumn;
    TV4PRTPrice: TcxGridDBBandedColumn;
    TV4Money: TcxGridDBBandedColumn;
    cxGridLevel1: TcxGridLevel;
    Panel7: TPanel;
    Panel4: TPanel;
    ToolBar5: TToolBar;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    cxGrid4: TcxGrid;
    TV2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn20: TcxGridDBBandedColumn;
    TV2Qty: TcxGridDBBandedColumn;
    TV2SunHao: TcxGridDBBandedColumn;
    TV2XLQty: TcxGridDBBandedColumn;
    TV2PRTPrice: TcxGridDBBandedColumn;
    TV2Money: TcxGridDBBandedColumn;
    cxGridLevel3: TcxGridLevel;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    V1PrtCode: TcxGridDBBandedColumn;
    V1PrtCodeName: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1PRTOrderQty: TcxGridDBBandedColumn;
    V1PRTPrice: TcxGridDBBandedColumn;
    V1ConMXMoney: TcxGridDBBandedColumn;
    V1Huilv: TcxGridDBBandedColumn;
    V1RMBMoney: TcxGridDBBandedColumn;
    cxGrid1Level1: TcxGridLevel;
    DataSource2: TDataSource;
    Order_ZL: TClientDataSet;
    DataSource3: TDataSource;
    Order_MLJG: TClientDataSet;
    DataSource4: TDataSource;
    Order_FL: TClientDataSet;
    DataSource5: TDataSource;
    Order_CBJG: TClientDataSet;
    cxStyle2: TcxStyle;
    V2JHDate: TcxGridDBBandedColumn;
    V3JHDate: TcxGridDBBandedColumn;
    V4JHDate: TcxGridDBBandedColumn;
    Panel6: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label11: TLabel;
    Label15: TLabel;
    Label1: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Panel8: TPanel;
    ToolBar6: TToolBar;
    ToolButton9: TToolButton;
    ToolButton10: TToolButton;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBBandedTableView;
    TV5PrtCodeName: TcxGridDBBandedColumn;
    tv5Money: TcxGridDBBandedColumn;
    V5JHDate: TcxGridDBBandedColumn;
    cxGridLevel4: TcxGridLevel;
    YLYGMoney: TcxCurrencyEdit;
    MLJGMoney: TcxCurrencyEdit;
    FLMoney: TcxCurrencyEdit;
    JGMoney: TcxCurrencyEdit;
    YGLiRun: TcxCurrencyEdit;
    BGYSFee: TcxCurrencyEdit;
    OtherMoney: TcxCurrencyEdit;
    ZJYGMoney: TcxCurrencyEdit;
    KPYGMoney: TcxCurrencyEdit;
    GLMoney: TcxCurrencyEdit;
    SOrdQty8: TcxCurrencyEdit;
    Label18: TLabel;
    KPFeeLV: TcxCurrencyEdit;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Label19: TLabel;
    SKType: TBtnEditA;
    Label20: TLabel;
    JQDate: TDateTimePicker;
    V1PriceUnit: TcxGridDBBandedColumn;
    V1OrderUnit: TcxGridDBBandedColumn;
    TBDYZH: TToolButton;
    V1Column1: TcxGridDBBandedColumn;
    V1Column2: TcxGridDBBandedColumn;
    V2Column1: TcxGridDBBandedColumn;
    Label2: TLabel;
    orderNo: TBtnEditA;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PRTPricePropertiesEditValueChanged(Sender: TObject);
    procedure V1HuilvPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure TV2QtyPropertiesEditValueChanged(Sender: TObject);
    procedure TV3QtyPropertiesEditValueChanged(Sender: TObject);
    procedure TV4XLQtyPropertiesEditValueChanged(Sender: TObject);
    procedure TV5QtyPropertiesEditValueChanged(Sender: TObject);
    procedure BGYSFeePropertiesEditValueChanged(Sender: TObject);
    procedure OtherMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure KPYGMoneyPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure SOrdQty8PropertiesEditValueChanged(Sender: TObject);
    procedure KPFeeLVPropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure SKTypeBtnClick(Sender: TObject);
    procedure V1PRTOrderQtyPropertiesEditValueChanged(Sender: TObject);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure TBDYZHClick(Sender: TObject);
    procedure tv5MoneyPropertiesEditValueChanged(Sender: TObject);
    procedure V2Column1PropertiesEditValueChanged(Sender: TObject);
    procedure orderNoBtnClick(Sender: TObject);
  private
    procedure InitData();
    function  SaveData():Boolean;
    procedure HJ();
    { Private declarations }
  public
    PState,CopyInt:Integer;
    canshu1:string;
    FMainId,FSubid,FFMainId,FYGNO,FST,FZT:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmConInPut_CBYG: TfrmConInPut_CBYG;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel,U_ZdyAttachment,U_CPManageSel,U_ProductOrderListSel;

{$R *.dfm}
procedure TfrmConInPut_CBYG.HJ();
begin
  if BGYSFee.Text='' then BGYSFee.Text:='0';
  if OtherMoney.Text='' then OtherMoney.Text:='0';
  if KPYGMoney.Text='' then KPYGMoney.Text:='0';
  if SOrdQty8.Text='' then SOrdQty8.Text:='0';
  if KPFeeLV.Text='' then KPFeeLV.Text:='0';
  if TV2.DataController.Summary.FooterSummaryValues[2]<>NULL then
    YLYGMoney.Text:=FloatToStr(TV2.DataController.Summary.FooterSummaryValues[2])
  else
    YLYGMoney.Text:='0';
  if TV3.DataController.Summary.FooterSummaryValues[1]<>NULL then
    MLJGMoney.Text:=FloatToStr(TV3.DataController.Summary.FooterSummaryValues[1])
  else
    MLJGMoney.Text:='0';
  if TV4.DataController.Summary.FooterSummaryValues[1]<>NULL then
    FLMoney.Text:=FloatToStr(TV4.DataController.Summary.FooterSummaryValues[1])
  else
  FLMoney.Text:='0';
  if TV5.DataController.Summary.FooterSummaryValues[1]<>NULL then
    JGMoney.Text:=FloatToStr(TV5.DataController.Summary.FooterSummaryValues[1])
  else
    JGMoney.Text:='0';
  if TV1.DataController.Summary.FooterSummaryValues[2]<>NULL then
  begin
    GLMoney.Text:=FloatToStr(TV1.DataController.Summary.FooterSummaryValues[2]*strtofloat(SOrdQty8.Text));
    KPYGMoney.Text:=FloatToStr(TV1.DataController.Summary.FooterSummaryValues[2]*strtofloat(KPFeeLV.Text));
  end
  else
  begin
    GLMoney.Text:='0';
    KPYGMoney.Text:='0';
  end;
  ZJYGMoney.Text:=floattostr(strtofloat(YLYGMoney.Text)+strtofloat(MLJGMoney.Text)+strtofloat(FLMoney.Text)+strtofloat(JGMoney.Text));
  if TV1.DataController.Summary.FooterSummaryValues[2]<>NULL then
  begin
    YGLiRun.Text:=floattostr(TV1.DataController.Summary.FooterSummaryValues[2]-strtofloat(ZJYGMoney.Text)-strtofloat(BGYSFee.Text)
                -strtofloat(OtherMoney.Text)-strtofloat(KPYGMoney.Text)-strtofloat(GLMoney.Text));
  end
  else
  begin
    YGLiRun.Text:=floattostr(0-strtofloat(ZJYGMoney.Text)-strtofloat(BGYSFee.Text)
                -strtofloat(OtherMoney.Text)-strtofloat(KPYGMoney.Text)-strtofloat(GLMoney.Text));
  end;
end;

procedure TfrmConInPut_CBYG.TBCloseClick(Sender: TObject);
begin
//  WriteCxBandedGrid('预估成本11',Tv1,'预估成本管理');
//  WriteCxBandedGrid('预估成本21',Tv2,'预估成本管理');
//  WriteCxBandedGrid('预估成本31',Tv3,'预估成本管理');
//  WriteCxBandedGrid('预估成本41',Tv4,'预估成本管理');
//  WriteCxBandedGrid('预估成本51',Tv5,'预估成本管理');
  Close;
end;

procedure TfrmConInPut_CBYG.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from JYOrderCon_YGCB A ');
    sql.Add('where A.MainId='''+Trim(FMainId)+'''');
    sql.add(' and A.CBType=''采购''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_ZL);
  SInitCDSData20(ADOQuery1,Order_ZL);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from JYOrderCon_YGCB A ');
    sql.Add('where A.MainId='''+Trim(FMainId)+'''');
    sql.add(' and A.CBType=''加工''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_MLJG);
  SInitCDSData20(ADOQuery1,Order_MLJG);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from JYOrderCon_YGCB A ');
    sql.Add('where A.MainId='''+Trim(FMainId)+'''');
    sql.add(' and A.CBType=''辅料''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_FL);
  SInitCDSData20(ADOQuery1,Order_FL);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.* ');
    sql.Add('from JYOrderCon_YGCB A ');
    sql.Add('where A.MainId='''+Trim(FMainId)+'''');
    sql.add(' and A.CBType=''费用''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_CBJG);
  SInitCDSData20(ADOQuery1,Order_CBJG);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select *,RMBMoney=ConMXMoney*Huilv from JYOrderCon_Sub_JG ');    
    sql.Add('where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.add(' from JYOrderCon_Main_JG A where A.MainId='''+Trim(FMainId)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  CustomerNoName.TxtCode:=Trim(ADOQuery1.fieldbyname('CustomerNo').AsString);
  if ADOQuery1.IsEmpty then
  begin
    YLYGMoney.Text:='0';
    FLMoney.Text:='0';
    MLJGMoney.Text:='0';
    BGYSFee.Text:='0';
    JGMoney.Text:='0';
    OtherMoney.Text:='0';
    ZJYGMoney.Text:='0';
    KPYGMoney.Text:='0';
    GLMoney.Text:='0';
    YGLiRun.Text:='0';
    SOrdQty8.Text:='0';
    KPFeeLV.Text:='0';
//    YGNo.Text:='自动生成';
  end
  else
  begin
    SCSHDataNew(ADOQuery1,panel6,2);
    YGNo.Text:=Trim(ADOQuery1.fieldbyname('YGNo').AsString);
  end;
end;

procedure TfrmConInPut_CBYG.FormShow(Sender: TObject);
begin
//  ReadCxBandedGrid('预估成本11',Tv1,'预估成本管理');
//  ReadCxBandedGrid('预估成本21',Tv2,'预估成本管理');
//  ReadCxBandedGrid('预估成本31',Tv3,'预估成本管理');
//  ReadCxBandedGrid('预估成本41',Tv4,'预估成本管理');
//  ReadCxBandedGrid('预估成本51',Tv5,'预估成本管理');
  InitData();
end;

function TfrmConInPut_CBYG.SaveData():Boolean;
var
  maxno,Smaxno,Zmaxno,Fmaxno,Jmaxno,Xmaxno:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOTemp,maxno,'GM','JYOrderCon_Main_JG',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end
    else
    begin
      maxno:=Trim(FMainId);
    end;
    if ( Trim(YGNo.Text)='' ) then
      FYGNo:=Trim(maxno)
    else
      FYGNo:=Trim(YGNo.Text);
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrderCon_Main_JG where MainId='''+Trim(FMainId)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId)='' then
      begin
        Append;
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('Status').Value:='0';
        FieldByName('MainId').Value:=Trim(maxno);
        FieldByName('YGNo').Value:=Trim(FYGNo);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      SSetsaveSqlNew(ADOCmd,'JYOrderCon_Main_JG',ScrollBox1,2);
      FieldByName('CustomerNo').Value:=Trim(CustomerNoName.TxtCode);
      fieldbyname('YLYGMoney').Value:=StrToFloat(YLYGMoney.Text);
      fieldbyname('FLMoney').Value:=StrToFloat(FLMoney.Text);
      fieldbyname('MLJGMoney').Value:=StrToFloat(MLJGMoney.Text);
      fieldbyname('BGYSFee').Value:=StrToFloat(BGYSFee.Text);
      fieldbyname('JGMoney').Value:=StrToFloat(JGMoney.Text);
      fieldbyname('OtherMoney').Value:=StrToFloat(OtherMoney.Text);
      fieldbyname('ZJYGMoney').Value:=StrToFloat(ZJYGMoney.Text);
      fieldbyname('KPYGMoney').Value:=StrToFloat(KPYGMoney.Text);
      fieldbyname('GLMoney').Value:=StrToFloat(GLMoney.Text);
      fieldbyname('YGLiRun').Value:=StrToFloat(YGLiRun.Text);
      FieldByName('SOrdQty8').Value:=StrToFloat(SOrdQty8.Text);
      FieldByName('KPFeeLV').Value:=StrToFloat(KPFeeLV.Text);
      Post;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderCon_Main_JG where YGNo='''+Trim(YGNo.Text)+'''');
      Open;
    end;
    if ADOCmd.RecordCount>1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('预估单号重复!','提示',0);
      Exit;
    end;

    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOTemp,Smaxno,'GS','JYOrderCon_Sub_JG',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          Smaxno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add(' select * from JYOrderCon_Sub_JG where MainId='''+Trim(maxno)+''' ');
          sql.Add(' and SubId='''+Trim(Smaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
          begin
            Append;
            FieldByName('MainId').Value:=Trim(maxno);
            FieldByName('SubId').Value:=Trim(Smaxno);
          end
          else
          begin
            Edit;
            FieldByName('editer').Value:=Trim(DName);
            FieldByName('editDate').Value:=SGetServerDate(ADOQuery1);
          end;
          FieldByName('PRTCodeNameEng').Value:=Trim(Order_Sub.Fieldbyname('PRTCodeNameEng').AsString);
          FieldByName('PRTspec').Value:=Trim(Order_Sub.fieldbyname('PRTspec').AsString);
          FieldByName('PRTMF').Value:=Trim(Order_Sub.fieldbyname('PRTMF').AsString);
          FieldByName('PRTKZ').Value:=Trim(Order_Sub.fieldbyname('PRTKZ').AsString);
          RTSetSaveDataCDSBand(ADOCmd,Tv1,Order_Sub,'JYOrderCon_Sub_JG',0);
          Post;
        end;
        Next;
      end;
    end;
    with Order_ZL do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_ZL.fieldbyname('YGID').AsString)='' then
        begin
          if GetLSNo(ADOTemp,Zmaxno,'CG','JYOrderCon_YGCB',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          Zmaxno:=Trim(Order_ZL.fieldbyname('YGID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_YGCB where YGID='''+Trim(Zmaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if isempty then
          begin
            Append;
            FieldByName('MainId').Value:=Trim(maxno);
            fieldbyname('YGID').Value:=Trim(Zmaxno);
            FieldByName('CBType').Value:='采购';
          end
          else
            Edit;
          SSetSaveDataCDSBandNew(ADOCmd,Tv2,Order_ZL,'JYOrderCon_YGCB',0);
          fieldbyname('OrderQty').Value:=Order_ZL.Fieldbyname('OrderQty').AsFloat;
          fieldbyname('Qty').Value:=Order_ZL.Fieldbyname('Qty').AsFloat;
          fieldbyname('SunHao').Value:=Order_ZL.Fieldbyname('SunHao').AsFloat;
          fieldbyname('XLQty').Value:=Order_ZL.Fieldbyname('XLQty').AsFloat;
          fieldbyname('PRTPrice').Value:=Order_ZL.Fieldbyname('PRTPrice').AsFloat;
          fieldbyname('Money').Value:=Order_ZL.Fieldbyname('Money').AsFloat;
          Post;
        end;
        Next;
      end;
    end;
    with Order_MLJG do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_MLJG.fieldbyname('YGID').AsString)='' then
        begin
          if GetLSNo(ADOTemp,Jmaxno,'JG','JYOrderCon_YGCB',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          Jmaxno:=Trim(Order_MLJG.fieldbyname('YGID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_YGCB where YGID='''+Trim(Jmaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if isempty then
          begin
            Append;
            FieldByName('MainId').Value:=Trim(maxno);
            fieldbyname('YGID').Value:=Trim(Jmaxno);
            FieldByName('CBType').Value:='加工';
          end
          else
            Edit;
          SSetSaveDataCDSBandNew(ADOCmd,Tv3,Order_MLJG,'JYOrderCon_YGCB',0);
          fieldbyname('Qty').Value:=Order_MLJG.Fieldbyname('Qty').AsFloat;
          fieldbyname('PRTPrice').Value:=Order_MLJG.Fieldbyname('PRTPrice').AsFloat;
          fieldbyname('Money').Value:=Order_MLJG.Fieldbyname('Money').AsFloat;
          Post;
        end;
        Next;
      end;
    end;
    with Order_FL do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_FL.fieldbyname('YGID').AsString)='' then
        begin
          if GetLSNo(ADOTemp,Fmaxno,'FL','JYOrderCon_YGCB',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          Fmaxno:=Trim(Order_FL.fieldbyname('YGID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_YGCB where YGID='''+Trim(Fmaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if isempty then
          begin
            Append;
            FieldByName('MainId').Value:=Trim(maxno);
            fieldbyname('YGID').Value:=Trim(Fmaxno);
            FieldByName('CBType').Value:='辅料';
          end
          else
            Edit;
          SSetSaveDataCDSBandNew(ADOCmd,Tv4,Order_FL,'JYOrderCon_YGCB',0);
          fieldbyname('XLQty').Value:=Order_FL.Fieldbyname('XLQty').AsFloat;
          fieldbyname('PRTPrice').Value:=Order_FL.Fieldbyname('PRTPrice').AsFloat;
          fieldbyname('Money').Value:=Order_FL.Fieldbyname('Money').AsFloat;
          Post;
        end;
        Next;
      end;
    end;
    with Order_CBJG do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_CBJG.fieldbyname('YGID').AsString)='' then
        begin
          if GetLSNo(ADOTemp,Xmaxno,'FY','JYOrderCon_YGCB',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          Xmaxno:=Trim(Order_CBJG.fieldbyname('YGID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderCon_YGCB where YGID='''+Trim(Xmaxno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if isempty then
          begin
            Append;
            FieldByName('MainId').Value:=Trim(maxno);
            fieldbyname('YGID').Value:=Trim(Xmaxno);
            FieldByName('CBType').Value:='费用';
          end
          else
            Edit;
          SSetSaveDataCDSBandNew(ADOCmd,Tv5,Order_CBJG,'JYOrderCon_YGCB',0);
          fieldbyname('Qty').Value:=Order_CBJG.Fieldbyname('Qty').AsFloat;
          fieldbyname('PRTPrice').Value:=Order_CBJG.Fieldbyname('PRTPrice').AsFloat;
          fieldbyname('Money').Value:=Order_CBJG.Fieldbyname('Money').AsFloat;
          Post;
        end;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
    Result:=False;
  end;
end;

procedure TfrmConInPut_CBYG.TBSaveClick(Sender: TObject);
begin
  Toolbar1.SetFocus;

  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmConInPut_CBYG.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      fnote:=True;
      MainType:=Trim(DName);
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        Self.Order_Sub.FieldByName('SOrdDefStr4').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmConInPut_CBYG.v1PriceUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PriceUnit';
      flagname:='价格单位';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmConInPut_CBYG.v1PRTPricePropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then
  mavlue:='0';
  with Order_Sub do
  begin
    edit;
    FieldByName('PRTPrice').Value:=mavlue;
    post;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('ConMXMoney').Value:=FieldByName('PRTOrderQty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('RMBMoney').Value:=FieldByName('Huilv').AsFloat*FieldByName('ConMXMoney').AsFloat;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.V1HuilvPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then
  mavlue:='0';
  with Order_Sub do
  begin
    edit;
    FieldByName('Huilv').Value:=mavlue;
    post;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('RMBMoney').Value:=FieldByName('Huilv').AsFloat*FieldByName('ConMXMoney').AsFloat;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.ToolButton7Click(Sender: TObject);
begin
  with Order_ZL do
  begin
    Append;
    post;
  end;
end;

procedure TfrmConInPut_CBYG.ToolButton5Click(Sender: TObject);
begin
  with Order_MLJG do
  begin
    Append;
    post;
  end;
end;

procedure TfrmConInPut_CBYG.ToolButton3Click(Sender: TObject);

begin
  with Order_FL do
  begin
    Append;
    post;
  end;
end;

procedure TfrmConInPut_CBYG.ToolButton9Click(Sender: TObject);
begin
  with Order_CBJG do
  begin
    Append;
    post;
  end;
end;

procedure TfrmConInPut_CBYG.TV2QtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_ZL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with Order_ZL do
  begin
    edit;
    FieldByName('XLQty').Value:=FieldByName('Qty').AsFloat*FieldByName('SunHao').AsFloat;
    FieldByName('Money').Value:=FieldByName('Qty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  tv2.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.TV3QtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_MLJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with Order_MLJG do
  begin
    edit;
    FieldByName('Money').Value:=FieldByName('Qty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  tv3.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.TV4XLQtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_FL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with Order_FL do
  begin
    edit;
    FieldByName('Money').Value:=FieldByName('XLQty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  tv4.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.TV5QtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv5.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_CBJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with Order_CBJG do
  begin
    edit;
    FieldByName('Money').Value:=FieldByName('Qty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  tv5.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.BGYSFeePropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxCurrencyEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  BGYSFee.Text:=mavlue;
  HJ();
end;

procedure TfrmConInPut_CBYG.OtherMoneyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxCurrencyEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  OtherMoney.Text:=mavlue;
  HJ();
end;

procedure TfrmConInPut_CBYG.KPYGMoneyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxCurrencyEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  KPYGMoney.Text:=mavlue;
  HJ();
end;

procedure TfrmConInPut_CBYG.ToolButton6Click(Sender: TObject);
begin
  if Order_MLJG.IsEmpty then Exit;
  if Trim(Order_MLJG.fieldbyname('YGID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_YGCB where YGID='''+Trim(Order_MLJG.fieldbyname('YGID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_MLJG.Delete;
end;

procedure TfrmConInPut_CBYG.ToolButton4Click(Sender: TObject);
begin
  if Order_FL.IsEmpty then Exit;
  if Trim(Order_FL.fieldbyname('YGID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_YGCB where YGID='''+Trim(Order_FL.fieldbyname('YGID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_FL.Delete;
end;

procedure TfrmConInPut_CBYG.ToolButton8Click(Sender: TObject);
begin
  if Order_ZL.IsEmpty then Exit;
  if Trim(Order_ZL.fieldbyname('YGID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_YGCB where YGID='''+Trim(Order_ZL.fieldbyname('YGID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_ZL.Delete;
end;

procedure TfrmConInPut_CBYG.ToolButton10Click(Sender: TObject);
begin
  if Order_CBJG.IsEmpty then Exit;
  if Trim(Order_CBJG.fieldbyname('YGID').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_YGCB where YGID='''+Trim(Order_CBJG.fieldbyname('YGID').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_CBJG.Delete;
end;

procedure TfrmConInPut_CBYG.SOrdQty8PropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxCurrencyEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  SOrdQty8.Text:=mavlue;
  HJ();
end;

procedure TfrmConInPut_CBYG.KPFeeLVPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxCurrencyEdit(Sender).EditingText;
  if mavlue='' then mavlue:='0';
  KPFeeLV.Text:=mavlue;
  HJ();
end;

procedure TfrmConInPut_CBYG.ToolButton1Click(Sender: TObject);
begin
  frmCPManageSel:=TfrmCPManageSel.create(self);
  with frmCPManageSel do
  begin
    if showmodal=1 then
    begin
      CDS_Main.DisableControls;
      with CDS_Main do
      begin
        first;
        while not Eof do
        begin
          if FieldByName('Ssel').AsBoolean=true then
          begin
            with Self.Order_Sub do
            begin
              append;
              FieldByName('PrtCode').Value:=Trim(CDS_Main.fieldbyname('CYNo').AsString);
              FieldByName('PrtCodeName').Value:=Trim(CDS_Main.fieldbyname('CYName').AsString);
              FieldByName('PRTCodeNameEng').Value:=Trim(CDS_Main.fieldbyname('CYEName').AsString);
              FieldByName('PRTspec').Value:=Trim(CDS_Main.fieldbyname('CYSpec').AsString);
              FieldByName('PRTMF').Value:=Trim(CDS_Main.fieldbyname('CYMF').AsString);
              FieldByName('PRTKZ').Value:=Trim(CDS_Main.fieldbyname('CYKZ').AsString);
              FieldByName('PriceUnit').Value:='RMB';
              FieldByName('OrderUnit').Value:='M';
              FieldByName('Huilv').Value:='1.0';
              post;
            end;
          end;
          Next;
        end;
      end;
      CDS_Main.DisableControls;
    end;
    free;
  end;
end;

procedure TfrmConInPut_CBYG.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if ( Trim(Order_Sub.fieldbyname('Subid').AsString)<>'' ) then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderCon_Sub_JG where Subid='''+Trim(Order_Sub.fieldbyname('Subid').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmConInPut_CBYG.SKTypeBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='SKType';
    flagname:='收款方式';
    if ShowModal=1 then
    begin
      SKType.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmConInPut_CBYG.V1PRTOrderQtyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  if mavlue='' then
  mavlue:='0';
  with Order_Sub do
  begin
    edit;
    FieldByName('PRTOrderQty').Value:=mavlue;
    post;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('ConMXMoney').Value:=FieldByName('PRTOrderQty').AsFloat*FieldByName('PRTPrice').AsFloat;
    post;
  end;
  with Order_Sub do
  begin
    edit;
    FieldByName('RMBMoney').Value:=FieldByName('Huilv').AsFloat*FieldByName('ConMXMoney').AsFloat;
    post;
  end;
  tv1.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      canshu1:=self.canshu1;
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(CDS_HZ.fieldbyname('ZdyName').AsString);
        CustomerNoName.TxtCode:=Trim(CDS_HZ.fieldbyname('ZdyCode').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmConInPut_CBYG.TBDYZHClick(Sender: TObject);
begin
  try
    frmProductOrderListSel:=TfrmProductOrderListSel.create(self);
    with frmProductOrderListSel do
    begin
      if showmodal=1 then
      begin
        Order_Main.DisableControls;
        with Order_Main do
        begin
          first;
          while not Eof do
          begin
            if ( FieldByName('SSel').AsBoolean=true ) then
            begin
              with Self.Order_Sub do
              begin
                Append;
                FieldByName('PrtCode').Value:=Trim(Order_Main.fieldbyname('MPRTCode').AsString);
                FieldByName('PrtCodeName').Value:=Trim(Order_Main.fieldbyname('MPRTCodeName').AsString);
                FieldByName('PRTCodeNameEng').Value:=Trim(Order_Main.fieldbyname('PRTEName').AsString);
                FieldByName('PRTspec').Value:=Trim(Order_Main.fieldbyname('MPRTSpec').AsString);
                FieldByName('PRTMF').Value:=Trim(Order_Main.fieldbyname('MPRTMF').AsString);
                FieldByName('PRTKZ').Value:=Trim(Order_Main.fieldbyname('MPRTKZ').AsString);
                FieldByName('PRTColor').Value:=Trim(Order_Main.fieldbyname('PRTColor').AsString);
                FieldByName('PRTHX').Value:=Trim(Order_Main.fieldbyname('PRTHX').AsString);
                FieldByName('PRTOrderQty').Value:=Order_Main.fieldbyname('PRTOrderQty').AsFloat;
                FieldByName('OrderUnit').Value:=Trim(Order_Main.fieldbyname('OrderUnit').AsString);
                FieldByName('PriceUnit').Value:=Trim(Order_Main.fieldbyname('PriceUnit1').AsString);
                FieldByName('PRTPrice').Value:=Order_Main.fieldbyname('PRTPrice').AsFloat;
                FieldByName('ConMXMoney').Value:=RoundFloat((Order_Main.fieldbyname('PRTOrderQty').AsFloat * Order_Main.fieldbyname('PRTPrice').AsFloat),2);
                FieldByName('RMBMoney').Value:=RoundFloat((Order_Main.fieldbyname('PRTOrderQty').AsFloat * Order_Main.fieldbyname('PRTPrice').AsFloat),2);
                FieldByName('Huilv').Value:='1.0';
                post;
              end;
            end;
            Next;
          end;
        end;
        Order_Main.DisableControls;
        Self.HJ();
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
end;

procedure TfrmConInPut_CBYG.tv5MoneyPropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv5.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  with Order_CBJG do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  tv5.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.V2Column1PropertiesEditValueChanged(
  Sender: TObject);
var mavlue,FFieldName:string;
begin
  mavlue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName;
  if mavlue='' then
  mavlue:='0';
  if ( (FFieldName='SunHao') and (StrToFloatDef(mavlue,0)>=1) ) then
  begin
    mavlue:='0';
    Application.MessageBox('损耗不能大于等于1！','提示',0);
  end;
  with Order_ZL do
  begin
    edit;
    FieldByName(FFieldName).Value:=mavlue;
    post;
  end;
  with Order_ZL do
  begin
    edit;
    FieldByName('Qty').Value:=RoundFloat((FieldByName('OrderQty').AsFloat/(1-FieldByName('SunHao').AsFloat)),2);
    FieldByName('XLQty').Value:=RoundFloat((FieldByName('Qty').AsFloat - FieldByName('OrderQty').AsFloat),2);
    FieldByName('Money').Value:=RoundFloat((FieldByName('Qty').AsFloat*FieldByName('PRTPrice').AsFloat),2);
    post;
  end;
  tv2.Controller.EditingController.ShowEdit();
  HJ();
end;

procedure TfrmConInPut_CBYG.orderNoBtnClick(Sender: TObject);
begin
  try
    frmProductOrderListSel:=TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      FFInt:=1;
      if ShowModal=1 then
      begin
        self.orderNO.Text:=frmProductOrderListSel.Order_Main.fieldbyname('orderNO').AsString;
        self.CustomerNoName.Text:=frmProductOrderListSel.Order_Main.fieldbyname('CustomerNoName').AsString;
        self.JQDate.DateTime:=frmProductOrderListSel.Order_Main.fieldbyname('dlydate').AsDateTime;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;

  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select *,sumQty=(select sum(PrtOrderQty) from JYOrder_sub X where X.mainID=A.mainID) from JYOrder_sub A inner join JYorder_Main B on B.MainID=A.mainID');
    sql.Add('where B.OrderNo='''+trim(OrderNo.Text)+''' ');
    open;
  end;
  Order_Sub.EmptyDataSet;
  with ADOTemp do
  begin
    while not eof do
    begin
      Order_Sub.Append;
      Order_Sub.fieldbyName('PrtCode').Value:=fieldbyName('MPrtCode').AsString;
      Order_Sub.fieldbyName('PrtCodeName').Value:=fieldbyName('MPrtCodeName').AsString;
      Order_Sub.fieldbyName('PRTspec').Value:=fieldbyName('MPRTspec').AsString;
      Order_Sub.fieldbyName('PRTColor').Value:=fieldbyName('PRTColor').AsString;
      Order_Sub.fieldbyName('PRTHX').Value:=fieldbyName('PRTHX').AsString;
      Order_Sub.fieldbyName('PRTOrderQty').Value:=fieldbyName('PRTOrderQty').AsFloat;
      Order_Sub.fieldbyName('OrderUnit').Value:=fieldbyName('OrderUnit').AsString;
      Order_Sub.fieldbyName('PriceUnit').Value:=fieldbyName('PriceUnit').AsString;
      Order_Sub.fieldbyName('PRTPrice').Value:=fieldbyName('PRTPrice').AsFloat;
      Order_Sub.fieldbyName('ConMXMoney').Value:=format('%.2f',[fieldbyName('PRTOrderQty').AsFloat*fieldbyName('PRTPrice').AsFloat]);
      Order_Sub.fieldbyName('Huilv').Value:=fieldbyName('Huilv').AsFloat;
      Order_Sub.fieldbyName('RMBMoney').Value:=format('%.2f',[fieldbyName('PRTOrderQty').AsFloat*fieldbyName('PRTPrice').AsFloat*fieldbyName('Huilv').AsFloat]);
      Order_Sub.Post;
      next;
    end;
  end;
  Order_ZL.Append;
  Order_ZL.FieldByName('PRTCodeName').Value:=ADOTemp.fieldbyName('MPrtCodeName').AsString;
  Order_ZL.FieldByName('OrderQty').Value:=ADOTemp.fieldbyName('sumQty').AsFloat;
  Order_ZL.Post;

  Order_MLJG.Append;
  Order_MLJG.FieldByName('PRTCodeName').Value:=ADOTemp.fieldbyName('MPrtCodeName').AsString;
  Order_MLJG.FieldByName('Qty').Value:=ADOTemp.fieldbyName('sumQty').AsFloat;
  Order_MLJG.Post;

  Order_FL.Append;
  Order_FL.FieldByName('PRTCodeName').Value:=ADOTemp.fieldbyName('MPrtCodeName').AsString;
//  Order_FL.FieldByName('OrderQty').Value:=ADOTemp.fieldbyName('sumQty').AsFloat;
  Order_FL.Post;

end;

end.
