unit U_CGMian;

interface

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

type
  TfrmCGMian = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    CRTime: TDateTimePicker;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1CodeName: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label6: TLabel;
    Label9: TLabel;
    v1MF: TcxGridDBColumn;
    v1KZ: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label2: TLabel;
    JHDate: TDateTimePicker;
    Label3: TLabel;
    Note: TMemo;
    Tv1Column1: TcxGridDBColumn;
    GYSName: TBtnEditA;
    ADOCmd: TADOQuery;
    ADOTemp: TADOQuery;
    ADOQuery1: TADOQuery;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure v1P_ColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
    procedure fromFactoryNameBtnClick(Sender: TObject);
    procedure kuweiBtnClick(Sender: TObject);
    procedure v1NotePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PRTSpecPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure FactoryNameBtnClick(Sender: TObject);
    procedure v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure v1CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure RangchangBtnClick(Sender: TObject);
    procedure GYSNameBtnClick(Sender: TObject);
    procedure Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
  private
    procedure InitGrid();
    procedure SetFrom();
    function savedate(): Boolean;
    function CheckData(): Boolean;
    { Private declarations }
  public
    fkeyNO: string;
    FType, PState: integer;
    fCRType, FZZType: string;
    FMainId, FFMainId: string;
    { Public declarations }
  end;

var
  frmCGMian: TfrmCGMian;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_GYSList, U_RTFun, U_BPZDY_LRM,
  U_ProductOrderNewList_New2, U_MCP;
{$R *.dfm}

function TfrmCGMian.CheckData(): Boolean;
begin
  try

    if Trim(GYSName.Text) = '' then
      raise Exception.Create('供应商不能为空！');
    if CDS_Main.IsEmpty then
      raise Exception.Create('明细不能为空！');

    if CDS_Main.Locate('CPName', null, []) then
      raise Exception.Create('品名不能为空！');
    if CDS_Main.Locate('CPName', '', []) then
      raise Exception.Create('品名不能为空！');

    if CDS_Main.Locate('PS', null, []) then
      raise Exception.Create('匹数不能为空！');
    if CDS_Main.Locate('PS', 0, []) then
      raise Exception.Create('匹数不能为0！');

    if CDS_Main.Locate('Qty', null, []) then
      raise Exception.Create('数量不能为空！');
    if CDS_Main.Locate('Qty', 0, []) then
      raise Exception.Create('数量不能为0！');

    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmCGMian.SetFrom();
begin

end;

function TfrmCGMian.savedate(): Boolean;
var
  maxno, maxmnno, FSSId: string;
  fconNO, fmxType: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNoHZ(ADOCmd, maxno, 'CG', 'CG_Main', 3, 1, 3) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from CG_Main where CGID=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
      end
      else
      begin
        Edit;
      end;
      FieldByName('CGID').Value := Trim(maxno);
      RTSetsavedata(ADOCmd, 'CG_Main', Panel1, 2);

      if Trim(FMainId) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;

    FMainId := Trim(maxno);
    ///保存子表
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_Main.fieldbyname('CGSID').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'CGS', 'CG_Sub', 4, 1) = False then
          begin
            CDS_Main.EnableControls;
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(CDS_Main.fieldbyname('CGSID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from CG_Sub ');
          sql.Add(' where CGSID=''' + Trim(maxno) + '''');
          Open;
        end;
        if ADOCmd.IsEmpty then
        begin
          FSSId := '';
        end
        else
        begin
          FSSId := Trim(maxno);
        end;
        with ADOCmd do
        begin
          if Trim(FSSId) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('CGID').Value := Trim(FMainId);
          FieldByName('CGSID').Value := Trim(maxno);
          FieldByName('MainID').Value := Trim(CDS_Main.FieldByName('MainID').AsString);
          FieldByName('SubID').Value := Trim(CDS_Main.FieldByName('SubID').AsString);
          FieldByName('ConNo').Value := Trim(CDS_Main.FieldByName('ConNo').AsString);
          RTSetSaveDataCDS(ADOCmd, Tv1, CDS_Main, 'CG_Sub', 0);
          Post;
        end;
        CDS_Main.Edit;
        CDS_Main.FieldByName('CGSID').Value := Trim(maxno);
        Next;
      end;
    end;
    CDS_Main.EnableControls;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
    Result := False;
  end;
end;

procedure TfrmCGMian.InitGrid();
begin

  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    if PState = 1 then
    begin
      sql.Add(' select A.*  ');
      sql.Add(' from CG_Sub A');
      sql.Add('where CGID=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' select A.*  ');
      sql.Add(' from CG_Sub A');
      sql.Add(' where 1<>1');

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

  if PState = 0 then
  begin
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select CPName=Value1,KZ=Value2,GYSCPName=Value3,MF=Value4,PS=PSHZ,Qty=QtyHZ ');
      sql.Add(' from TbForBatch where MainType=''棉采购'' and DName =''' + Trim(DName) + '''');
      Open;
    end;
    with ADOQuery1 do
    begin
      First;
      while not Eof do
      begin
        with CDS_Main do
        begin
          append;
          FieldbyName('CPName').Value := Trim(ADOQuery1.fieldbyname('CPName').AsString);
          FieldbyName('GYSCPName').Value := Trim(ADOQuery1.fieldbyname('GYSCPName').AsString);
          FieldbyName('KZ').Value := Trim(ADOQuery1.fieldbyname('KZ').AsString);
          FieldbyName('MF').Value := Trim(ADOQuery1.fieldbyname('MF').AsString);
          if ADOQuery1.fieldbyname('ps').AsInteger < 0 then
          begin
            FieldbyName('ps').Value := ADOQuery1.fieldbyname('ps').AsInteger * - 1;
          end
          else
          begin
            FieldbyName('ps').Value := ADOQuery1.fieldbyname('ps').AsInteger;
          end;
          if ADOQuery1.fieldbyname('Qty').AsFloat < 0 then
          begin
            FieldbyName('Qty').Value := ADOQuery1.fieldbyname('Qty').AsFloat * - 1;
          end
          else
          begin
            FieldbyName('Qty').Value := ADOQuery1.fieldbyname('Qty').AsFloat;
          end;
          post;
        end;
        Next;
      end;
    end;
  end;

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(' from CG_Main A');
    sql.Add(' where CGID=''' + Trim(FMainId) + ''' ');
    Open;
  end;
  SCSHDataNew(ADOQuery1, Panel1, 2);

end;

procedure TfrmCGMian.FormDestroy(Sender: TObject);
begin
  frmCGMian := nil;
end;

procedure TfrmCGMian.FormCreate(Sender: TObject);
begin
  CRTime.Date := SGetServerDate10(ADOQueryTmp);
  JHDate.Date := SGetServerDate10(ADOQueryTmp);
end;

procedure TfrmCGMian.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption + tv1.Name + '2', Tv1, '采购棉');
  Action := cahide;
end;

procedure TfrmCGMian.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption + tv1.Name + '2', Tv1, '采购棉');
  InitGrid();
end;

procedure TfrmCGMian.TBSaveClick(Sender: TObject);
begin

  CRTime.SetFocus;
  if CheckData() = false then
    exit;

  if savedate() then
  begin
    application.MessageBox('数据保存成功！', '提示信息');
    ModalResult := 1;
  end
  else
  begin
    application.MessageBox('数据保存失败！', '提示信息', MB_ICONERROR);
  end;
end;

procedure TfrmCGMian.ToolButton1Click(Sender: TObject);
begin
//  with CDS_Main do
//  begin
//    append;
//    FieldbyName('ps').Value := 0;
//    FieldbyName('Qty').Value := 0;
//    post;
//  end;

  frmMCP := TfrmMCP.create(self);
  with frmMCP do
  begin
    flag := 'MName';
    flagName := '棉';
    ViewFlag := true;
    Panel4.Align := alClient;
    ToolBar3.Visible := false;
    Button1.Visible := False;
    if ShowModal = 1 then
    begin
      Self.CDS_Main.append;
      Self.CDS_Main.FieldByName('CPName').Value := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      Self.CDS_Main.FieldByName('GYSCPName').Value := Trim(ClientDataSet1.fieldbyname('CPName').AsString);
      Self.CDS_Main.FieldByName('MF').Value := Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
      Self.CDS_Main.FieldByName('KZ').Value := Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
      Self.CDS_Main.FieldByName('FLNote').Value := Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
      Self.CDS_Main.FieldByName('PMHH').Value := Trim(ClientDataSet1.fieldbyname('PMHH').AsString);
      Self.CDS_Main.FieldbyName('ps').Value := 0;
      Self.CDS_Main.FieldbyName('Qty').Value := 0;
    end;
    free;
  end;

end;

procedure TfrmCGMian.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;
  if Trim(CDS_Main.FieldByName('CGSID').AsString) = '' then
  begin
    CDS_Main.Delete;
  end
  else
  begin
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('update CG_Sub set CGID=CGID+''删'' where CGSID=' + quotedstr(Trim(CDS_Main.FieldByName('CGSID').AsString)));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_Main.Delete;
  end;
end;

procedure TfrmCGMian.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmCGMian.v1P_ColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdColor';
      flagname := '颜色';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
      MainType := Trim(DName);
      fnote := True;
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('P_Color').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCGMian.v1QtyPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_Main do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    FieldbyName('PS').Value := format('%.0f', [FieldByName('Qty').AsFloat / FieldByName('PiChang').AsFloat]);
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCGMian.fromFactoryNameBtnClick(Sender: TObject);
begin
//  if Trim(CRType.Text) = '客供入库' then
//  begin
//    try
//      frmZdyAttachment := TfrmZdyAttachment.Create(Application);
//      with frmZdyAttachment do
//      begin
//        if ShowModal = 1 then
//        begin
//          fromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//        end;
//      end;
//    finally
//      frmZdyAttachment.Free;
//    end;
//  end
//  else
//  begin
//    try
//      frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
//      with frmZdyAttachGYS do
//      begin
//        if ShowModal = 1 then
//        begin
//          fromFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//        end;
//      end;
//    finally
//      frmZdyAttachGYS.Free;
//    end;
//  end;

  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'LaiZiDW';
      flagname := '来自单位';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmCGMian.kuweiBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'kuwei';
      flagname := '库位';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGMian.v1NotePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'WJGRKNote';
      flagname := '备注';

      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('Note').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.Post;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmCGMian.v1PRTSpecPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'flSPEC';
      flagname := '辅料规格';
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('SPEC').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmCGMian.FactoryNameBtnClick(Sender: TObject);
begin
//  try
//    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
//    with frmZdyAttachGYS do
//    begin
//      if ShowModal = 1 then
//      begin
//        FactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//      end;
//    end;
//  finally
//    frmZdyAttachGYS.Free;
//  end;
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'CunFangCangKu';
      flagname := '存放仓库';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGMian.v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'FLqtyUnit';
      flagname := '单位';
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('qtyUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

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

procedure TfrmCGMian.ToolButton3Click(Sender: TObject);
var
  MaxNo: string;
begin

  if CDS_Main.IsEmpty then
    exit;
  CopyAddRowCDS(CDS_Main);

  with CDS_Main do
  begin
    edit;
    FieldbyName('CRID').Value := '';
    post;
  end;

end;

procedure TfrmCGMian.v1CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmMCP := TfrmMCP.create(self);
  with frmMCP do
  begin
    flag := 'MName';
    flagName := '棉';
    ViewFlag := true;
    Panel4.Align := alClient;
    ToolBar3.Visible := false;
    Button1.Visible := False;
    if ShowModal = 1 then
    begin
      Self.CDS_Main.Edit;
      Self.CDS_Main.FieldByName('CPName').Value := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      Self.CDS_Main.FieldByName('GYSCPName').Value := Trim(ClientDataSet1.fieldbyname('CPName').AsString);
      Self.CDS_Main.FieldByName('MF').Value := Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
      Self.CDS_Main.FieldByName('KZ').Value := Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
      Self.CDS_Main.FieldByName('FLNote').Value := Trim(ClientDataSet1.fieldbyname('BPNote').AsString);
      Self.CDS_Main.FieldByName('PMHH').Value := Trim(ClientDataSet1.fieldbyname('PMHH').AsString);
    end;
    free;
  end;

end;

procedure TfrmCGMian.RangchangBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Rangchang';
      flagname := '染厂';
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmCGMian.GYSNameBtnClick(Sender: TObject);
begin
  try
    frmGYSList := TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      KHType.Text := '棉厂';
      KHType.TxtCode := '棉厂';
      if ShowModal = 1 then
      begin
        Self.GYSName.Text := Trim(frmGYSList.Order_Main.fieldbyname('KHName').AsString);
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

procedure TfrmCGMian.Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmProductOrderNewList_New2 := TfrmProductOrderNewList_New2.Create(Application);
    with frmProductOrderNewList_New2 do
    begin
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('OrderNo').Value := Trim(Order_Main.fieldbyname('MLOrderNo').AsString);
        Self.CDS_Main.FieldByName('ConNo').Value := Trim(Order_Main.fieldbyname('MLConNo').AsString);
        Self.CDS_Main.FieldByName('MainID').Value := Trim(Order_Main.fieldbyname('NewMLID').AsString);
        Self.CDS_Main.FieldByName('SubID').Value := Trim(Order_Main.fieldbyname('NewSubid').AsString);
        Self.CDS_Main.FieldByName('KHNO').Value := Trim(Order_Main.fieldbyname('KHNO').AsString);
      end;
    end;
  finally
    frmProductOrderNewList_New2.Free;
  end;
end;

end.

