unit U_ProductOrderList_Sel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmProductOrderList_Sel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    v1OrderNo: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1OrdPerson1: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTOrderQty: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    v1MPRTKZ: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    ToolButton3: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1JGForctyName: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt, FCloth: Integer;

    { Public declarations }
  end;

var
  frmProductOrderList_Sel: TfrmProductOrderList_Sel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmProductOrderList_Sel.FormDestroy(Sender: TObject);
begin
  frmProductOrderList_Sel := nil;
end;

procedure TfrmProductOrderList_Sel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmProductOrderList_Sel.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
end;

procedure TfrmProductOrderList_Sel.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单列表选择', Tv1, '生产指示单管理');
end;

procedure TfrmProductOrderList_Sel.InitGrid();
begin
//  if Length(Trim(self.ConNO.Text)) < 3 then
//    Exit;


  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select PRTORDERQTY=(SELECT SUM(PRTORDERQTY) FROM JYOrder_SUB B where A.MAINID=B.MAINID GROUP BY B.MAINID ) ');
      SQL.Add(',YWNAME=(SELECT TOP 1 CYENAME FROM CP_YDANG C WHERE C.CYNO=A.MPRTCODE)');
      sql.Add(',orderunit=(SELECT TOP 1 orderunit FROM JYOrder_sub d WHERE d.mainid=A.mainid)');
      SQL.Add(',SCSKX=(SELECT TOP 1 SCSKX FROM SalesContract_Sub E INNER JOIN SalesContract_MAIN F ON E.MAINID=F.MAINID WHERE E.SCSCode=A.MPRTCODE AND F.CONNO=A.CONNO)');
      SQL.Add(',SCSHX=(SELECT TOP 1 SCSHX FROM SalesContract_Sub E INNER JOIN SalesContract_MAIN F ON E.MAINID=F.MAINID WHERE E.SCSCode=A.MPRTCODE AND F.CONNO=A.CONNO)');
      sql.add(',A.*,A.OrderNo OrderNoM ');
      sql.add(' from JYOrder_Main A  ');
      SQL.Add('where A.orderno like ''' + '%' + Trim(self.orderno.Text) + '%' + '''');
      sql.Add('and filltime>=''2022-01-01''');
//ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmProductOrderList_Sel.InitForm();
begin
  ReadCxGrid('指示单列表选择', Tv1, '生产指示单管理');
//  InitGrid();
end;

procedure TfrmProductOrderList_Sel.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmProductOrderList_Sel.ToolButton3Click(Sender: TObject);
begin
  ModalResult := 1;
end;

procedure TfrmProductOrderList_Sel.OrderNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

end.

