unit U_MachGlideHelp;

interface

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

type
  TfrmMachGlideHelp = class(TForm)
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ADOQuery1GlideNo: TStringField;
    ADOQuery1GlideName: TStringField;
    ADOQuery1GlidePara: TStringField;
    ADOQuery1GlideNote: TStringField;
    AD_sub: TADODataSet;
    Ds_sub: TDataSource;
    Splitter2: TSplitter;
    Panel1: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    ToolBar1: TToolBar;
    BtnFind: TToolButton;
    BtnOk: TToolButton;
    BtnClose: TToolButton;
    Panel2: TPanel;
    Panel5: TPanel;
    dbGrid1: TcxGrid;
    tv1: TcxGridDBTableView;
    dbGrid1Level1: TcxGridLevel;
    tv1glideNo: TcxGridDBColumn;
    tv1glideName: TcxGridDBColumn;
    tv1glidePara: TcxGridDBColumn;
    tv1glideNote: TcxGridDBColumn;
    ADOConnection1: TADOConnection;
    cxGrid1: TcxGrid;
    cxGridDBTableView1: TcxGridDBTableView;
    v1cnt: TcxGridDBColumn;
    v1deptName: TcxGridDBColumn;
    v1deviceNo: TcxGridDBColumn;
    v1deviceName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryMach: TADOQuery;
    DataSource2: TDataSource;
    pics: TImageList;
    ToolBar2: TToolBar;
    TOk: TToolButton;
    Tclose: TToolButton;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyleTree: TcxStyle;
    procedure FormCreate(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
    procedure TcloseClick(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure cxGridDBTableView1FocusedRecordChanged(
      Sender: TcxCustomGridTableView; APrevFocusedRecord,
      AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
  private
    { Private declarations }
    load_flag :Boolean;
    this_code :string;
    procedure DoQuery();
    procedure DoFilter(mDept:string);
  public
    { Public declarations }
  end;

var
  frmMachGlideHelp: TfrmMachGlideHelp;

implementation

{$R *.dfm}

uses
  U_global;


procedure TfrmMachGlideHelp.FormCreate(Sender: TObject);
begin
  Panel2.Align:=Alclient;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;
  try
    ADOQueryMach.DisableControls ;
    with ADOQueryMach do
    begin
      close;
      Open;
    end;
  finally
    ADOQueryMach.EnableControls;
  end;
  DoQuery();
end;

procedure TfrmMachGlideHelp.tv1DblClick(Sender: TObject);
begin
  TOk.Click;
end;
////////////////////////////////////////////////////////////
  //
////////////////////////////////////////////////////////////
procedure TfrmMachGlideHelp.DoQuery();
var
  strsql:string;
begin
  If ADOQueryMach.IsEmpty then
  strsql:=' select distinct *,isnull(A.glideDept,''ÆäËü'') as dept from V_MC_glide A order By a.glideNo '
  else
  strsql:=' select distinct A.*,isnull(A.glideDept,''ÆäËü'') as dept from V_MC_glide A,mc_glide_mach B '+
          ' where A.GlideNO=B.GlideNO and B.deviceNO='+quotedstr(Trim(ADOQueryMach.fieldbyname('deviceNO').AsString)) +
          ' order By A.glideNo ';
  try
    ADOQuery1.DisableControls ;
    with ADOQuery1 do
    begin
      close;
      sql.clear;
      filtered:=false;
      sql.add(strsql);
      Open;
    end;
  finally
    ADOQuery1.EnableControls ;
  end;
end;
/////////////////////////////////////////
procedure TfrmMachGlideHelp.DoFilter(mDept:string);
var
  filterStr:string;
begin
  if mDept<>'R' then
    filterStr:=' and Dept= '+quotedStr(trim(mDept));

  if trim(edit1.Text)<>'' then
    filterStr:=filterStr+' and glideName like '+quotedStr('%'+trim(edit1.Text)+'%');

  try
    ADOQuery1.DisableControls ;
    filterStr:=trim(RightBStr(filterStr,length(filterStr)-4));
    with ADOQuery1 do
    begin
      filtered:=false;
      if trim(filterStr)<>'' then
      begin
        filter:=filterStr;
        filtered:=true;
      end;
    end;
  finally
    ADOQuery1.EnableControls ;
  end;
end;

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

procedure TfrmMachGlideHelp.TOkClick(Sender: TObject);
begin
  iF adoquery1.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmMachGlideHelp.cxGridDBTableView1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  DoQuery();
end;

end.
