unit U_SysLogHelp;

interface

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

type
  TfrmSysLogHelp = class(TForm)
    ToolBar1: TToolBar;
    TQry: TToolButton;
    Tclose: TToolButton;
    ADOQueryLog: TADOQuery;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    cxGrid1: TcxGrid;
    tv1: TcxGridDBTableView;
    tv1OperMan: TcxGridDBColumn;
    tv1jopertime: TcxGridDBColumn;
    tv1Model: TcxGridDBColumn;
    tv1acction: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    tv1Opevent: TcxGridDBColumn;
    tv1Result: TcxGridDBColumn;
    Panel1: TPanel;
    Label2: TLabel;
    begDate: TDateTimePicker;
    endDate: TDateTimePicker;
    Label3: TLabel;
    edt_model: TEdit;
    CheckBox1: TCheckBox;
    Label4: TLabel;
    Opevent: TEdit;
    ThreeImgList: TImageList;
    ImageList_new32: TImageList;
    ThreeColorBase: TcxStyleRepository;
    SHuangSe: TcxStyle;
    SkyBlue: TcxStyle;
    Default: TcxStyle;
    QHuangSe: TcxStyle;
    Red: TcxStyle;
    FontBlue: TcxStyle;
    TextSHuangSe: TcxStyle;
    FonePurple: TcxStyle;
    FoneClMaroon: TcxStyle;
    FoneRed: TcxStyle;
    RowColor: TcxStyle;
    handBlack: TcxStyle;
    cxBlue: TcxStyle;
    SHuangSeCu: TcxStyle;
    procedure TcloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TQryClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure OpeventKeyPress(Sender: TObject; var Key: Char);
  private
    procedure DoQuery();
    procedure DoFilter();
  public
    fModel, facction: string;
    fOtherWhere: string;
  end;

var
  frmSysLogHelp: TfrmSysLogHelp;

implementation

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

procedure TfrmSysLogHelp.TcloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmSysLogHelp.FormCreate(Sender: TObject);
begin
  cxGrid1.Align := alClient;
  begDate.DateTime := date - 31;
  endDate.DateTime := date;
  with ADOConnection1 do
  begin
    Connected := false;
    ConnectionString := DConString;
    Connected := true;
  end;
end;
/////////////////////////////////////////////////////////
  //
////////////////////////////////////////////////////////

procedure TfrmSysLogHelp.DoQuery();
var
  mbegdate, menddate: string;
begin
  mbegdate := formatDatetime('yyyy-MM-dd', begDate.Date);
  menddate := formatDatetime('yyyy-MM-dd', endDate.Date + 1);
  try
    with ADOQueryLog do
    begin
      close;
      sql.clear;
      filtered := false;
      sql.add('select A.* ');
      sql.add('from SY_sysLog A');
      if CheckBox1.Checked then
      begin
        sql.Add('where OperTime>=' + quotedStr(mbegdate));
        sql.Add('and OperTime<' + quotedStr(menddate));
      end
      else
      begin
        sql.Add('where 1=1');
      end;

      if trim(Opevent.Text) <> '' then
        sql.add('and Opevent LIKE ' + quotedStr('%' + Opevent.Text + '%'));

      if trim(fModel) <> '' then
        sql.add('and Model=' + quotedStr(fModel));
      if trim(facction) <> '' then
        sql.add('and acction=' + quotedStr(facction));
      if trim(fOtherWhere) <> '' then
      begin
        sql.add(fOtherWhere);
      end;
      sql.Add('order by operOr,Opertime');
      Open;
    end;
  finally
  end;
end;
///////////////////////////////////////////////////////////
  //
///////////////////////////////////////////////////////////

procedure TfrmSysLogHelp.DoFilter();
var
  filterStr: string;
begin
  filterStr := '';
  if trim(edt_model.text) <> '' then
  begin
    filterStr := ' and model =' + quotedStr(trim(edt_model.text));
  end;
  if trim(Opevent.text) <> '' then
  begin
    filterStr := ' and OpEvent like ' + quotedStr('%' + trim(Opevent.text) + '%');
  end;

  try
    ADOQueryLog.DisableControls;
    if trim(filterStr) = '' then
    begin
      ADOQueryLog.Filtered := false;
      exit;
    end;
    filterStr := trim(RightBStr(filterStr, length(filterStr) - 3));
    with ADOQueryLog do
    begin
      filtered := false;
      filter := filterStr;
      filtered := true;
    end;
  finally
    ADOQueryLog.EnableControls;
  end;

end;

procedure TfrmSysLogHelp.FormShow(Sender: TObject);
begin
  DoQuery();
end;

procedure TfrmSysLogHelp.OpeventKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    DoQuery();
  end;
end;

procedure TfrmSysLogHelp.TQryClick(Sender: TObject);
begin
  DoQuery();
end;

procedure TfrmSysLogHelp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := cafree;
end;

end.

