unit U_MFZDZSDXZ1;

interface

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

type
  TfrmMFZDZSD1 = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    ToolButton3: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label2: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OrderNo: TEdit;
    KHorderNo: TEdit;
    PBFactory: TEdit;
    ConNo: TEdit;
    RanFactory: TEdit;
    Orddefstr5: TEdit;
    PRTCodeName: TEdit;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    ADOQueryTemp: TADOQuery;
    Label7: TLabel;
    PRTkuanNo: TEdit;
    Label11: TLabel;
    SOrddefstr1: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure OrderNoChange(Sender: TObject);
    procedure KHorderNoChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMFZDZSD1: TfrmMFZDZSD1;

implementation

uses
  U_DataLink, U_Fun;
{$R *.dfm}

procedure TfrmMFZDZSD1.InitGrid();
var
  strwhere: string;
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin

      Close;
      Filtered := False;
      sql.Clear;
      sql.add('select A.*,B.* from JYOrder_Main A  ');
      sql.add('inner join JYOrder_Sub B on A.mainid=B.mainid');
//      sql.add('where 1=1 ');
//      if trim(orderno.text) <> '' then
//      begin
//        sql.add('and orderno like '%''+ trim(orderno.text) +''%' ');
//      end;
//      if trim(KHorderNo.text) <> '' then
//      begin
//        sql.add('and KHorderNo like '%''+ trim(KHorderNo.text) +''%' ');
//      end;
//      if trim(PRTkuanNo.text) <> '' then
//      begin
//        sql.add('and PRTkuanNo like '%''+ trim(PRTkuanNo.text) +''%' ');
//      end;
//      if trim(SOrddefstr1.text) <> '' then
//      begin
//        sql.add('and SOrddefstr1 like '%''+ trim(SOrddefstr1.text) +''%' ');
//      end;
      sql.Add('where A.FillTime>=''' + FormatDateTime('yyyy-MM-dd', BegDate.DateTime) + ''' ');
      sql.Add('and  A.FillTime<''' + FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1) + ''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmMFZDZSD1.FormDestroy(Sender: TObject);
begin
  frmMFZDZSD1 := nil;           
end;

procedure TfrmMFZDZSD1.FormShow(Sender: TObject);
begin
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 7;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

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

procedure TfrmMFZDZSD1.OrderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmMFZDZSD1.KHorderNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmMFZDZSD1.TBCloseClick(Sender: TObject);
begin
  Close;
end;

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

end.

