unit U_orderInPut_HYWT_Sub;

interface

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

type
  TFrmOrderInPut_HYWT_Sub = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    conNo: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    original: TEdit;
    Label11: TLabel;
    Attached: TEdit;
    Label12: TLabel;
    TDNum: TEdit;
    Payaddress: TBtnEditA;
    CustomerNoName: TBtnEditA;
    Export: TBtnEditA;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    POD: TBtnEditA;
    shiptime: TDateTimePicker;
    Label17: TLabel;
    voy: TBtnEditA;
    vessel: TBtnEditA;
    Label18: TLabel;
    BLNo: TEdit;
    Label19: TLabel;
    Validtime: TDateTimePicker;
    ifFP: TCheckBox;
    ifZY: TCheckBox;
    Label20: TLabel;
    goodsdate: TDateTimePicker;
    Label21: TLabel;
    DLYDate: TDateTimePicker;
    Label22: TLabel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1BJNO: TcxGridDBColumn;
    V1SordQty1: TcxGridDBColumn;
    V1BGType: TcxGridDBColumn;
    V1PRTspec: TcxGridDBColumn;
    V1GoodsNo: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ToolBar2: TToolBar;
    Tadd: TToolButton;
    TDEL: TToolButton;
    WTNo: TEdit;
    Label23: TLabel;
    conDefstr1: TBtnEditA;
    V1SordQty2: TcxGridDBColumn;
    V1SordQty4: TcxGridDBColumn;
    V1SOrdDefNote3: TcxGridDBColumn;
    V1SOrdDefNote1: TcxGridDBColumn;
    ADOQueryTmp: TADOQuery;
    order_Sub: TClientDataSet;
    DataSource1: TDataSource;
    ADOQueryCmd: TADOQuery;
    XYNO: TEdit;
    DLYaddress: TBtnEditA;
    Label24: TLabel;
    MPRTBZNote: TMemo;
    orddefstr1: TEdit;
    ConPerson2: TEdit;
    ConPerson1: TEdit;
    Label25: TLabel;
    orderNo: TBtnEditA;
    KHConNo: TEdit;
    V1PRTCode: TcxGridDBColumn;
    V1PRTCodeName: TcxGridDBColumn;
    V1PRTColor: TcxGridDBColumn;
    V1OrderUnit: TcxGridDBColumn;
    V1SordQty3: TcxGridDBColumn;
    V1XHNO: TcxGridDBColumn;
    V1PRTprice: TcxGridDBColumn;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label26: TLabel;
    CYNO: TBtnEditA;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TaddClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure CustomerNoNameBtnClick(Sender: TObject);
    procedure V1BGTypePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure V1SordQty1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure PayaddressBtnClick(Sender: TObject);
    procedure vesselBtnClick(Sender: TObject);
    procedure DLYaddressBtnClick(Sender: TObject);
    procedure conDefstr1BtnClick(Sender: TObject);
    procedure voyBtnClick(Sender: TObject);
    procedure ExportBtnClick(Sender: TObject);
    procedure PODBtnClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure TDELClick(Sender: TObject);
    procedure CYNOBtnClick(Sender: TObject);
    procedure orderNoBtnClick(Sender: TObject);
  private
    procedure initdata();
    procedure savedata();
    { Private declarations }
  public
    FMainId: string;
    { Public declarations }
  end;

var
  FrmOrderInPut_HYWT_Sub: TFrmOrderInPut_HYWT_Sub;

implementation
                   
Uses U_DataLink,U_Fun, U_ZDYHelp, U_ZDYHelpSel, U_ProductOrderListSel,
  U_ProductOrderNewList_CY_Sel;

{$R *.dfm}

procedure TFrmOrderInPut_HYWT_Sub.savedata();
var FSubid: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOQueryCmd,FMainid,'HY','JYOrderWT_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 JYOrderWT_Main where MainId='''+Trim(FMainId)+'''');
      Open;
      if IsEmpty then
      begin
        Append;
        FieldByName('filler').AsString:=Trim(DName);
        FieldByName('filltime').AsDateTime:=SGetServerDateTime(ADOQueryTmp);
      end
      else
      begin
        Edit;
      end;
      FieldByName('MainId').Value:=Trim(FMainid);
      SSetsaveSqlNew(ADOQueryCmd,'JYOrderWT_Main',Panel1,2);
      FieldByName('status').AsString:='';
      if ifFP.Checked=True then
      begin
        FieldByName('ifFp').AsString:='T';
      end
      else
      begin
        FieldByName('ifFp').AsString:='F';
      end;
      if ifzy.Checked=True then
      begin
        FieldByName('ifzy').AsString:='T';
      end
      else
      begin
        FieldByName('ifzy').AsString:='F';
      end;
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrderWT_Main where WTNO='''+Trim(WTNO.Text)+'''');
      Open;
    end;
    if ADOQueryCmd.RecordCount>1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('委托单号重复!','提示');
      Exit;
    end;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,FSubid,'HY','JYOrderWT_Sub',4,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          FSubid:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrderWT_Sub where MainId='''+Trim(FMainId)+'''');
          sql.Add(' and SubId='''+Trim(FSubid)+'''');
          Open;
          if IsEmpty then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(FMainId);
          FieldByName('SubId').Value:=Trim(FSubid);
          RTSetSaveDataCDS(ADOQueryCmd,Tv1,Order_Sub,'JYOrderWT_Sub',0);
          fieldbyname('SordQty1').Value:=Order_Sub.fieldbyname('SordQty1').AsFloat;
          fieldbyname('SordQty2').Value:=Order_Sub.fieldbyname('SordQty2').AsFloat;
          fieldbyname('SordQty3').Value:=Order_Sub.fieldbyname('SordQty3').AsFloat;
          fieldbyname('SordQty4').Value:=Order_Sub.fieldbyname('SordQty4').AsFloat;
          fieldbyname('PRTprice').Value:=Order_Sub.fieldbyname('PRTprice').AsFloat;
          fieldbyname('Money').Value:=Order_Sub.fieldbyname('Money').AsFloat;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(FSubid);
        Next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.initdata();
begin
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from JYOrderwt_Main');
    sql.Add('where Mainid='''+trim(FMainid)+'''');
    Open;
    if not IsEmpty then
    begin
      SCSHDataNew(ADOQueryTmp,Panel1,2);
      MPRTBZNote.Text:=Trim(fieldbyname('MPRTBZNote').AsString);
      if FieldByName('iffp').AsString='T' then
      iffp.Checked:=True
      else
      iffp.Checked:=False;
      if FieldByName('ifzy').AsString='T' then
      ifzy.Checked:=True
      else
      ifzy.Checked:=False;
    end
    else
    begin
      shiptime.DateTime:=SGetServerDateTime(ADOQueryCmd);
      DLYDate.DateTime:=SGetServerDateTime(ADOQueryCmd);
      goodsdate.DateTime:=SGetServerDateTime(ADOQueryCmd);
      Validtime.DateTime:=SGetServerDateTime(ADOQueryCmd);
    end;
  end;
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from JYOrderWT_Sub ');
    sql.Add('where Mainid='''+trim(FMainid)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTmp,Order_Sub);
  SInitCDSData20(ADOQueryTmp,Order_Sub);
end;
procedure TFrmOrderInPut_HYWT_Sub.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TFrmOrderInPut_HYWT_Sub.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alclient;
end;

procedure TFrmOrderInPut_HYWT_Sub.FormDestroy(Sender: TObject);
begin
  FrmOrderInPut_HYWT_Sub:=nil;
end;

procedure TFrmOrderInPut_HYWT_Sub.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name,Tv1);
  InitData();
end;

procedure TFrmOrderInPut_HYWT_Sub.TBCloseClick(Sender: TObject);
begin
  close;
  WriteCxGrid(Self.Caption+Tv1.Name,Tv1);
end;

procedure TFrmOrderInPut_HYWT_Sub.TaddClick(Sender: TObject);
begin
  with order_Sub do
  begin
    Append;
    
    Post;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.TBSaveClick(Sender: TObject);
begin
  if WTNo.Text='' then
  begin
    Application.MessageBox('委托单号不能为空','提示');
    exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  SaveData();
end;

procedure TFrmOrderInPut_HYWT_Sub.CustomerNoNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CustomerNoName';
      flagname:='经营单位';
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.V1BGTypePropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BGTYPE';
      flagname:='包装式样';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('BGTYPE').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.V1SordQty1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='SordQty1';
      flagname:='成交条件';
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('SordQty1').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.PayaddressBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Payaddress';
      flagname:='运费付至';
      if ShowModal=1 then
      begin
        Payaddress.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.vesselBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='vessel';
      flagname:='船名';
      if ShowModal=1 then
      begin
        vessel.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.DLYaddressBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Payaddress';
      flagname:='装箱地点';
      if ShowModal=1 then
      begin
        DLYaddress.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.conDefstr1BtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Payaddress';
      flagname:='发货地址';
      if ShowModal=1 then
      begin
        conDefstr1.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.voyBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='voy';
      flagname:='航次';
      if ShowModal=1 then
      begin
        voy.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.ExportBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Export';
      flagname:='出口口岸';
      if ShowModal=1 then
      begin
        Export.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.PODBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='Export';
      flagname:='目的港';
      if ShowModal=1 then
      begin
        POD.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.MPRTBZNoteDblClick(Sender: TObject);
var i: Integer;
begin
  i:=0;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='MPRTBZNote';
      flagname:='注意事项';
      if ShowModal=1 then
      begin
        MPRTBZNote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              i:=i+1;
              MPRTBZNote.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString)
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.TDELClick(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  if Trim(Order_Sub.fieldbyname('SubId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',1)=2 then Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrderWT_Sub where SubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TFrmOrderInPut_HYWT_Sub.CYNOBtnClick(Sender: TObject);
var
  ConMainId:string;
begin
  ConMainId:='';
  frmProductOrderNewList_CY_SEL:=TfrmProductOrderNewList_CY_SEL.create(self);
  with frmProductOrderNewList_CY_SEL do
  begin
    FFInt:=1;
    if showmodal=1 then
    begin
      ConMainId:=trim(Order_Main.fieldbyname('mainID').asstring);
    end;
    free;
  end;
  iF ConMainId='' then exit;
  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select B.*,A.*,c.KhconNo,C.ConPerson2,C.ConPerson3,C.conDefstr2,C.conDefstr6,C.condefstr10,C.priceNote,C.Payment,C.ShippMent, ');
    sql.Add('PriceUnit1=(select top 1 PriceUnit from JYordercon_sub X where X.mainID=C.mainid)');
    sql.Add('from JYOrderCY_sub A ');
    sql.Add('inner join  JYOrderCY_Main B on B.mainID=A.mainID ');
    sql.Add('left join JYOrderCon_Main C on C.conNO=B.conNO ');
    sql.Add('where  B.mainID like '''+'%'+Trim(ConMainId)+'%'+'''');
    Open;
  end;
  IF not ADOQueryTmp.IsEmpty then
  begin
    ConNo.Text:=Trim(ADOQueryTmp.fieldbyname('ConNo').AsString);
    WTNO.Text:='WT_'+Trim(ADOQueryTmp.fieldbyname('ConNo').AsString);
    orderNo.Text:=Trim(ADOQueryTmp.fieldbyname('orderNo').AsString);
    CYNO.Text:=Trim(ADOQueryTmp.fieldbyname('CYNO').AsString);
    DLYDate.DateTime:=ADOQueryTmp.fieldbyname('DLYDate').AsDateTime;
    CustomerNoName.Text:=Trim(ADOQueryTmp.fieldbyname('CustomerNoName').AsString);
    CustomerNoName.TxtCode:=Trim(ADOQueryTmp.fieldbyname('CustomerNo').AsString);
    KHCONNO.Text:=Trim(ADOQueryTmp.fieldbyname('KHCONNO').AsString);
    ConPerson1.Text:=Trim(ADOQueryTmp.fieldbyname('ConPerson2').AsString);
    conDefstr1.Text:=Trim(ADOQueryTmp.fieldbyname('conDefstr1').AsString);
    BLNo.Text:=Trim(ADOQueryTmp.fieldbyname('orddefstr3').AsString);
  end;
  Order_Sub.EmptyDataSet;
  with ADOQueryTmp do
  begin
    First;
    while not Eof do
    begin
      with Order_Sub do
      begin
        Append;
        FieldByName('XHNO').Value:=Trim(ADOQueryTmp.fieldbyname('XHNO').AsString);
        FieldByName('PRTCode').Value:=Trim(ADOQueryTmp.fieldbyname('PRTCode').AsString);
        FieldByName('PRTCodeName').Value:=Trim(ADOQueryTmp.fieldbyname('PRTCodeName').AsString);
        FieldByName('PRTspec').Value:=Trim(ADOQueryTmp.fieldbyname('PRTspec').AsString);
        FieldByName('SordQty3').Value:=Trim(ADOQueryTmp.fieldbyname('PRTOrderQty').AsString);
        FieldByName('PRTColor').Value:=Trim(ADOQueryTmp.fieldbyname('PRTColor').AsString);
        FieldByName('OrderUnit').Value:=Trim(ADOQueryTmp.fieldbyname('OrderUnit').AsString);
        FieldByName('PRTPrice').Value:=Trim(ADOQueryTmp.fieldbyname('PRTPrice').AsString);
        FieldByName('PriceUnit').Value:=Trim(ADOQueryTmp.fieldbyname('PriceUnit1').AsString);
        FieldByName('SOrdDefNote4').Value:=Trim(ADOQueryTmp.fieldbyname('subID').AsString);
        Post;
      end;
      Next;
    end;
  end;
end;

procedure TFrmOrderInPut_HYWT_Sub.orderNoBtnClick(Sender: TObject);
begin
  frmProductOrderListSel:=TfrmProductOrderListSel.create(self);
  with frmProductOrderListSel do
   begin
     if showmodal=1 then
     begin
       with ADOQueryCmd do
       begin
         Close;
         sql.Clear;
         sql.Add('select B.*,A.*,c.KhconNo,C.ConPerson2,C.ConPerson3,C.conDefstr2,C.conDefstr6 from JYOrder_sub A ');
         sql.Add('inner join  JYOrder_Main B on B.mainID=A.mainID ');
         sql.Add('left  join JYOrderCon_Main C on C.conNO=B.conNO ');
         sql.Add('where B.mainID like '''+'%'+Trim(Order_Main.fieldbyname('mainID').asstring)+'%'+'''');
         Open;
         IF not IsEmpty then
         begin
           ConNo.Text:=Trim(ADOQueryCmd.fieldbyname('ConNo').AsString);
           orderNo.Text:=Trim(ADOQueryCmd.fieldbyname('orderNo').AsString);
           WTNO.Text:='WT_'+Trim(ADOQueryCmd.fieldbyname('ConNo').AsString);
           CustomerNoName.Text:=Trim(ADOQueryCmd.fieldbyname('CustomerNoName').AsString);
           CustomerNoName.TxtCode:=Trim(ADOQueryCmd.fieldbyname('CustomerNo').AsString);
           DLYDate.DateTime:=ADOQueryCmd.fieldbyname('DLYDate').AsDateTime;
           ConPerson1.Text:=Trim(ADOQueryCmd.fieldbyname('ConPerson2').AsString);
           KHCONNO.Text:=Trim(ADOQueryCmd.fieldbyname('KHCONNO').AsString);
           ConPerson2.Text:=Trim(ADOQueryCmd.fieldbyname('ConPerson3').AsString);
           conDefstr1.Text:=Trim(ADOQueryCmd.fieldbyname('conDefstr2').AsString);
         end;
         Order_Sub.EmptyDataSet;
         with ADOQueryCmd do
         begin
           First;
           while not Eof do
           begin
             with Order_Sub do
             begin
               Append;
               FieldByName('XHNO').Value:=Trim(ADOQueryCmd.fieldbyname('XHNO').AsString);
               FieldByName('PRTCode').Value:=Trim(ADOQueryCmd.fieldbyname('MPRTCode').AsString);
               FieldByName('PRTCodeName').Value:=Trim(ADOQueryCmd.fieldbyname('MPRTCodeName').AsString);
               FieldByName('PRTspec').Value:=Trim(ADOQueryCmd.fieldbyname('MPRTspec').AsString);
               FieldByName('PRTColor').Value:=Trim(ADOQueryCmd.fieldbyname('PRTColor').AsString);
               FieldByName('OrderUnit').Value:=Trim(ADOQueryCmd.fieldbyname('OrderUnit').AsString);
               FieldByName('PRTPrice').Value:=ADOQueryCmd.fieldbyname('PRTPrice').AsFloat;
               FieldByName('PriceUnit').Value:=Trim(ADOQueryCmd.fieldbyname('PriceUnit').AsString);
               FieldByName('SordQty3').Value:=ADOQueryCmd.fieldbyname('PRTOrderQty').AsFloat;
               FieldByName('SOrdDefNote4').Value:=Trim(ADOQueryCmd.fieldbyname('subID').AsString);
               Post;
             end;
             Next;
           end;
         end;
       end;
     end;
     Free;
   end;
end;

end.
