unit U_CHZDZSDXZ1;

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, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue,
  dxSkinscxPCPainter;

type
  TfrmCHZDZSD1 = 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
  frmCHZDZSD1: TfrmCHZDZSD1;

implementation

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

procedure TfrmCHZDZSD1.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 TfrmCHZDZSD1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

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

procedure TfrmCHZDZSD1.FormDestroy(Sender: TObject);
begin
  frmCHZDZSD1 := nil;     
end;

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

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

procedure TfrmCHZDZSD1.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 TfrmCHZDZSD1.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 TfrmCHZDZSD1.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmCHZDZSD1.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  ModalResult := 1;
end;

end.

