⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findpublic.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
字号:
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, KsSkinButtons,
  KsSkinForms, KsSkinPanels, KsSkinLabels, se_controls;

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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -