findpublic.pas

来自「胜天财务进销存2003源代码,SQLSERVER版,目前最完整的财务进销存系统.」· PAS 代码 · 共 167 行

PAS
167
字号
unit FindPublic;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  BaseForm, dxExEdtr, dxEdLib, dxEditor, ExtCtrls, StdCtrls, Buttons,
  dxCntner, dxDBGrid, dbData, dxTL, dxDBCtrl, dxDBTL, KsControls,
  KsButtons, KsSkinButtons, KsHooks, KsForms, KsSkinForms, KsPanels,
  KsSkinPanels, KsLabels, KsSkinLabels;

type
  TfrmFindPublic = class(TfrmBaseForm)
    Label1: TSeSkinLabel;
    edtName: TdxEdit;
    bbFind: TSeSkinButton;
    bbNo: TSeSkinButton;
    Panel1: TSeSkinPanel;
    Label2: TSeSkinLabel;
    Label3: TSeSkinLabel;
    checkAll: TdxCheckEdit;
    edtDirection: TdxPickEdit;
    edtCaption: TdxPickEdit;
    edtField: TdxPickEdit;
    bbFindDown: TSeSkinButton;
    procedure bbNoClick(Sender: TObject);
    procedure bbFindClick(Sender: TObject);
    procedure bbFindDownClick(Sender: TObject);
  private
    { Private declarations }
    bReturn: Boolean;
    sPubText: string;
    lPubFiled: Integer;
    gridGrid1: TCustomdxDBTreeListControl;
    procedure MainShow;
    procedure LoadData;
    function GridFind(lDirect: Integer): Boolean;
  public
    { Public declarations }
  end;

function FindPublicShow(Grid1: TCustomdxDBTreeListControl; var sText: string; var
  lFiled: Integer): Boolean;

implementation

uses SysPublic;

{$R *.DFM}

function FindPublicShow(Grid1: TCustomdxDBTreeListControl; var sText: string; var
  lFiled: Integer): Boolean;
var
  frmFindPublic: TfrmFindPublic;
begin
  frmFindPublic := TfrmFindPublic.Create(Application);
  with frmFindPublic do
  begin
    gridGrid1 := Grid1;
    sPubText := sText;
    lPubFiled := lFiled;
    MainShow;
    sText := sPubText;
    lFiled := lPubFiled;
    Result := bReturn;
    Free;
  end;
end;

procedure TfrmFindPublic.MainShow;
begin
  bOperateLog:=False;
  LoadData;
  ShowModal;
end;

procedure TfrmFindPublic.LoadData;
var
  lCol: Integer;
  sCaption, sField: string;
begin
  sCaption := '';
  edtDirection.ItemIndex := 0;
  edtName.Text := sPubText;
  //得到GRID的列名称
  for lCol := 0 to gridGrid1.ColumnCount - 1 do
    if gridGrid1.Columns[lCol].Visible = true then
    begin
      sCaption := sCaption + gridGrid1.Columns[lCol].Caption + #13;
      sField := sField + gridGrid1.Columns[lCol].FieldName + #13;
    end;
  edtField.Items.Text := sField;
  edtCaption.Items.Text := sCaption;
  if edtCaption.items.Count > 0 then
    edtCaption.ItemIndex := 0;
  if lPubFiled >= 0 then
    edtCaption.ItemIndex := lPubFiled;
end;

procedure TfrmFindPublic.bbNoClick(Sender: TObject);
begin
  inherited;
  Close;
end;

function TfrmFindPublic.GridFind(lDirect: Integer): Boolean;
var
  bFind: Boolean;
  lRow: Integer;
begin
  bFind := false;
  lPubFiled := edtCaption.ItemIndex;
  sPubText := edtName.Text;
  lRow := gridGrid1.DataSource.DataSet.RecNo;
  if lDirect = 0 then
    gridGrid1.DataSource.DataSet.First
  else
    gridGrid1.DataSource.DataSet.RecNo := lRow + 1;
  while not gridGrid1.DataSource.DataSet.Eof do
  begin
    if checkAll.Checked then
    begin
      if edtName.Text <>
        gridGrid1.ColumnByFieldName(edtField.Items.Strings[edtCaption.ItemIndex]).Field.AsString then
        gridGrid1.DataSource.DataSet.Next
      else
      begin
        bFind := true;
        break;
      end;
    end
    else
    begin
      if Pos(edtName.Text,
        gridGrid1.ColumnByFieldName(edtField.Items.Strings[edtCaption.ItemIndex]).Field.AsString) = 0 then
        gridGrid1.DataSource.DataSet.Next
      else
      begin
        bFind := true;
        break;
      end;
    end;
  end;

  if not bFind then
  begin
    gridGrid1.DataSource.DataSet.RecNo := lRow;
    MsgBox('数据没找到,请重新输入条件!', '提示', MB_OK);
  end;
  Result := bFind;
end;

procedure TfrmFindPublic.bbFindClick(Sender: TObject);
begin
  inherited;
  if GridFind(edtDirection.ItemIndex) then
    Close;
end;

procedure TfrmFindPublic.bbFindDownClick(Sender: TObject);
begin
  inherited;
  GridFind(1);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?