unit U_OrderJD;

interface

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

type
  TfrmOrderJD = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    orderNo: TEdit;
    GroupBox1: TGroupBox;
    Panel2: TPanel;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPrtSpec: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1SordQtY1: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1ordderNote1: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column2: TcxGridDBColumn;
    CDS_Order: TClientDataSet;
    DS_Order: TDataSource;
    ADOQueryMain: TADOQuery;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    V2Column1: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    V2Column3: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    V2Column5: TcxGridDBColumn;
    V2Column6: TcxGridDBColumn;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    TV4Column1: TcxGridDBColumn;
    TV4Column2: TcxGridDBColumn;
    CDS_CG: TClientDataSet;
    DS_CG: TDataSource;
    DS_DH: TDataSource;
    CDS_DH: TClientDataSet;
    CDS_TP: TClientDataSet;
    DS_TP: TDataSource;
    V4Column1: TcxGridDBColumn;
    V4Column2: TcxGridDBColumn;
    V3Column1: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure orderNoKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
  private
    Procedure InitOrder();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmOrderJD: TfrmOrderJD;

implementation
uses
  U_DataLink,U_OrderInPut,U_Fun;
{$R *.dfm}
Procedure TfrmOrderJD.InitOrder();
begin
  with adoqueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('EXEC P_View_Order_JD10');
    sql.Add('@keyNo='+quotedstr(trim(orderNo.Text)));
    sql.Add(',@flag='+quotedstr(trim('0')));
    open;
  end;

  SCreateCDS20(adoqueryMain,CDS_Order);
  SInitCDSData20(adoqueryMain,CDS_Order);

  with adoqueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('EXEC P_View_Order_JD10');
    sql.Add('@keyNo='+quotedstr(trim(orderNo.Text)));
    sql.Add(',@flag='+quotedstr(trim('1')));
    open;
  end;

  SCreateCDS20(adoqueryMain,CDS_CG);
  SInitCDSData20(adoqueryMain,CDS_CG);


  with adoqueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('EXEC P_View_Order_JD10');
    sql.Add('@keyNo='+quotedstr(trim(orderNo.Text)));
    sql.Add(',@flag='+quotedstr(trim('2')));
    open;
  end;

  SCreateCDS20(adoqueryMain,CDS_DH);
  SInitCDSData20(adoqueryMain,CDS_DH);

  with adoqueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('EXEC P_View_Order_JD10');
    sql.Add('@keyNo='+quotedstr(trim(orderNo.Text)));
    sql.Add(',@flag='+quotedstr(trim('3')));
    open;
  end;

  SCreateCDS20(adoqueryMain,CDS_TP);
  SInitCDSData20(adoqueryMain,CDS_TP);

end;
procedure TfrmOrderJD.FormDestroy(Sender: TObject);
begin
 frmOrderJD:=nil;
end;

procedure TfrmOrderJD.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=cafree;
end;

procedure TfrmOrderJD.orderNoKeyPress(Sender: TObject; var Key: Char);
begin
  IF key=#13 then
  begin
    IF trim(orderNo.Text)='' then exit;
    InitOrder();
  end;
end;

procedure TfrmOrderJD.FormShow(Sender: TObject);
begin
  InitOrder();
end;

end.
