unit U_SampleHelp_YH;

interface

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

type
  TfrmSampleHelp_YH = class(TForm)
    ToolBar2: TToolBar;
    TOK: TToolButton;
    Tclose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    begDate: TDateTimePicker;
    Label4: TLabel;
    endDate: TDateTimePicker;
    Label5: TLabel;
    Edit2: TEdit;
    ADOQueryHelp: TADOQuery;
    DataSource1: TDataSource;
    dbGrid1: TcxGrid;
    tv1: TcxGridDBTableView;
    tv1swid: TcxGridDBColumn;
    tv1P_colStd: TcxGridDBColumn;
    tv1P_colorName: TcxGridDBColumn;
    tv1P_code: TcxGridDBColumn;
    tv1P_chnName: TcxGridDBColumn;
    tv1P_Breadth: TcxGridDBColumn;
    tv1plates: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Trefresh: TToolButton;
    ADOQueryTmp: TADOQuery;
    tv1P_yhNo: TcxGridDBColumn;
    tv1p_request: TcxGridDBColumn;
    tv1customName: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure TcloseClick(Sender: TObject);
    procedure TOKClick(Sender: TObject);
    procedure TrefreshClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    procedure DoQuery();
    procedure DoFilter();
  public
    fCraftStr:string;
  end;

var
  frmSampleHelp_YH: TfrmSampleHelp_YH;

implementation
uses
  U_adodbmd_p;
{$R *.dfm}

procedure TfrmSampleHelp_YH.FormCreate(Sender: TObject);
begin
  dbGrid1.Align :=alClient;
  begDate.Date :=date()-30;
  endDate.Date:=date();
  DoQuery();
end;
////////////////////////////////////////////////////
  //
////////////////////////////////////////////////////
procedure TfrmSampleHelp_YH.DoQuery();
var
  mbegdate,menddate:string;
begin
  mbegdate:=formatDatetime('yyyy-MM-dd',begDate.DateTime);
  menddate:=formatDatetime('yyyy-MM-dd',endDate.DateTime+1);
  with ADOQueryHelp do
  begin
    close;
    filtered:=false;
    sql.clear;
    sql.Add('exec P_Get_SampleList');
    sql.Add('YH');
    sql.Add(',1');
    sql.Add(','+quotedStr(mbegdate));
    sql.Add(','+quotedStr(menddate));
    Open;
  end;
end;
procedure TfrmSampleHelp_YH.TcloseClick(Sender: TObject);
begin
  ModalResult:=-1;
end;

procedure TfrmSampleHelp_YH.TOKClick(Sender: TObject);
var
  mp_yhNo:string;
begin
  if ADOQueryHelp.IsEmpty then
  begin
    application.MessageBox('未有记录!','提示信息',0);
    exit;
  end
  else
  begin
    mp_yhNo:=trim(ADOQueryHelp.fieldByName('P_YhNo').AsString);
    with ADOQueryHelp do
    begin
      filtered:=false;
      filter:='P_YhNo='+quotedStr(mp_yhNo);
      filtered:=true;
    end;
   {
    with ADOQueryTmp do
    begin
      close;
      Parameters.ParamByName('craftIdx').Value :=trim(ADOQueryHelp.fieldByName('craftIdx').AsString);
      Open;
      fCraftStr:='';
      while not Eof do
      begin
        if fCraftStr='' then
          fCraftStr:=trim(fieldByName('glideNo').AsString)
        else
          fCraftStr:=fCraftStr+'->'+trim(fieldByName('glideNo').AsString);
        Next;
      end;
      close;
    end;
    }
    ModalResult:=1;
  end;
end;

procedure TfrmSampleHelp_YH.TrefreshClick(Sender: TObject);
begin
  DoQuery();
  DoFilter();
end;
////////////////////////////////////////////////////
  //函数：过滤数据
////////////////////////////////////////////////////
procedure TfrmSampleHelp_YH.DoFilter();
var
  filterStr:string;
begin
  filterStr:='';
  //花型
  if trim(Edit1.Text) <>'' then
  begin
    filterStr:=' and P_YhNo like '+quotedStr('%'+trim(Edit1.Text)+'%');
  end;
  //客户
  if trim(Edit2.Text)<>'' then
  begin
    filterStr:=filterStr+' and customName like '+quotedStr('%'+trim(Edit2.Text)+'%');
  end;

  try
    ADOQueryHelp.DisableControls ;
    if trim(filterStr)='' then
    begin
      ADOQueryHelp.Filtered:=false;
      ADOQueryHelp.EnableControls;
      exit;
    end;
    filterStr:=trim(RightBStr(filterStr,length(filterStr)-4));
    with ADOQueryHelp do
    begin
      filtered:=false;
      filter:=filterStr;
      filtered:=true;
    end;
  finally
    ADOQueryHelp.EnableControls;
    
  end;
end;
procedure TfrmSampleHelp_YH.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;

end.
