unit U_XcCustCodeHelp_dx;

interface

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

type
  TfrmXcCustCodeHelp_dx = class(TForm)
    ADOQueryHelp: TADOQuery;
    btOk: TBitBtn;
    btNo: TBitBtn;
    dbGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    Tv1code: TcxGridDBColumn;
    Tv1Name: TcxGridDBColumn;
    dbGrid1Level1: TcxGridLevel;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    NameOrCode: TEdit;
    Label1: TLabel;
    procedure btNoClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btOkClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Tv1DblClick(Sender: TObject);
    procedure NameOrCodeChange(Sender: TObject);
  private
    procedure InitData();
  public
    Fflag:string;  //类型标志
    fDivChar:string;
    pColumns:integer;
    fSelResult:string;
  end;

var
  frmXcCustCodeHelp_dx: TfrmXcCustCodeHelp_dx;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmXcCustCodeHelp_dx.btNoClick(Sender: TObject);
begin
  ModalResult:=-1;
end;

procedure TfrmXcCustCodeHelp_dx.FormCreate(Sender: TObject);
begin
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;
end;
////////////////////////////////////////////////
  //函数：
////////////////////////////////////////////////
procedure TfrmXcCustCodeHelp_dx.InitData();
begin
  with ADOQueryHelp do
  begin
    close;
    sql.clear;
    sql.Add('select * from XC_Custcode');
    sql.Add('where flag='''+Fflag+'''');
    sql.Add('and Valid=''Y''');
    sql.Add('order by orderno');
    Open;
  end;

end;
procedure TfrmXcCustCodeHelp_dx.FormShow(Sender: TObject);
begin
  self.Caption :='输入帮助(类别：'+FFlag+')';
  InitData();
end;

procedure TfrmXcCustCodeHelp_dx.btOkClick(Sender: TObject);
var
  fsj:string;
begin
  if ADOQueryHelp.IsEmpty then exit;
  fSelResult:=trim(ADOQueryHelp.fieldByName('Name').AsString);
  ModalResult:=1;
end;

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

procedure TfrmXcCustCodeHelp_dx.Tv1DblClick(Sender: TObject);
begin
  btOk.Click ;
end;

procedure TfrmXcCustCodeHelp_dx.NameOrCodeChange(Sender: TObject);
var
  fsj:string;
begin
  if Trim(NameOrCode.Text)<>'' then
  begin
    fsj:=' name like '+QuotedStr('%'+Trim(NameOrCode.Text)+'%');
    fsj:=fsj+' or code like '+QuotedStr('%'+Trim(NameOrCode.Text)+'%');
  end;
  with ADOQueryHelp do
  begin
    Filtered:=False;
    Filter:=fsj;
    Filtered:=True;
  end;
end;

end.
