unit U_MDMX;

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, cxPC, cxButtonEdit,
  RM_E_llPDF, cxDropDownEdit, cxTextEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxBarBuiltInMenu;

type
  TfrmMDMX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    Label8: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    MPRTCodeName: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    ADOQuerySub: TADOQuery;
    v1Column3: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    //RMllPDFExport1: TRMllPDFExport;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt: Integer;
    FCKOrdNo: string;
    { Public declarations }
  end;

var
  frmMDMX: TfrmMDMX;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmMDMX.FormDestroy(Sender: TObject);
begin
  frmMDMX := nil;
end;

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

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

procedure TfrmMDMX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid(Self.Caption, Tv1, '发货管理');
end;

procedure TfrmMDMX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      Sql.Add(' select A.KCCarNo,B.Filler,B.FillTime,B.MJID,B.MJXH,A.KGQty,B.MJMaoZ ');
      sql.Add(' from CK_PBCP_CR A left join WFB_MJJY_PB B on A.MJID=B.MJID');
      sql.Add(' where A.CKOrdNo='''+Trim(FCKOrdNo)+''' order by B.FillTime');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMDMX.InitForm();
begin

  ReadCxGrid(Self.Caption, Tv1, '发货管理');
  InitGrid();

end;

procedure TfrmMDMX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '码单明细');
end;

procedure TfrmMDMX.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

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

procedure TfrmMDMX.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMDMX.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

end.

