unit U_OrderLRList;

interface

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

type
  TfrmOrderLRList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    MovePanel2: TMovePanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1DeliveryDate: TcxGridDBColumn;
    v1MPRTCodeName: TcxGridDBColumn;
    v1MPRTSpec: TcxGridDBColumn;
    v1MPRTMF: TcxGridDBColumn;
    v1MPRTKZ: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column4: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column5: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label5: TLabel;
    Label3: TLabel;
    Label13: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    CPType: TComboBox;
    YWY: TEdit;
    OrdPerson1: TEdit;
    orderNo: TEdit;
    MPRTCodeName: TEdit;
    CustomerNoName: TEdit;
    conNo: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure PRTColorChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmOrderLRList: TfrmOrderLRList;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_OrderJD;

{$R *.dfm}

procedure TfrmOrderLRList.FormDestroy(Sender: TObject);
begin
  frmOrderLRList:=nil;
end;

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

procedure TfrmOrderLRList.FormCreate(Sender: TObject);
begin
  cxGrid1.Align:=alClient;
  EndDate.DateTime:=SGetServerDateTime(ADOQueryTemp);
  BegDate.DateTime:=EndDate.DateTime-7;
end;

procedure TfrmOrderLRList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      Filtered:=False;
      sql.Add(' exec P_View_OrderProfit');
      sql.Add(' @begdate='''+formatdateTime('yyyy-MM-dd',begdate.DateTime)+'''');
      sql.Add(',@enddate='''+formatdateTime('yyyy-MM-dd',enddate.DateTime+1)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmOrderLRList.TBRafreshClick(Sender: TObject);
begin
  //BegDate.SetFocus;
  MovePanel2.Visible:=True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible:=False;
end;

procedure TfrmOrderLRList.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  end;
end;

procedure TfrmOrderLRList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption+tv1.Name+'1',Tv1);
  Close;
end;

procedure TfrmOrderLRList.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption+tv1.Name+'1',Tv1);
end;

procedure TfrmOrderLRList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then exit;
  TcxGridToExcel(self.Caption,cxGrid1);
end;

procedure TfrmOrderLRList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmOrderLRList.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmOrderLRList.PRTColorChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmOrderLRList.cxTabControl1Change(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmOrderLRList.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmOrderJD:=TfrmOrderJD.Create(Application);
    with frmOrderJD do
    begin
      OrderNo.Text:=Trim(Self.CDS_Main.fieldbyname('OrderNo').AsString);
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmOrderJD.Free;
  end;
end;

end.
