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

📄 search.pas

📁 大富翁离线浏览器源码
💻 PAS
字号:
unit Search;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TfrmSearch = class(TForm)
    btnOK: TButton;
    btnCancel: TButton;
    PageControl1: TPageControl;
    TSNormal: TTabSheet;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    edtSearchStr: TEdit;
    chkTitle: TCheckBox;
    chkName: TCheckBox;
    chkContent: TCheckBox;
    GroupBox1: TGroupBox;
    cbbRoom: TComboBox;
    TSCustom: TTabSheet;
    memSearch: TMemo;
    cbbLogic: TComboBox;
    Label2: TLabel;
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    function prockeyword(KeyType,KeyWord,Flag:string):string;
  public
    { Public declarations }
    SearchStr:string;
    Target:string;
    TitleOnly:boolean;    
    Return:boolean;
  end;

var
  frmSearch: TfrmSearch;

implementation

uses
    main, dm;

{$R *.DFM}

procedure TfrmSearch.btnOKClick(Sender: TObject);
var
        ssCondition,SFlag:string;
begin
     if PageControl1.ActivePageIndex = 1 then
     begin
           SearchStr := memSearch.Text;
           Target := '自定义查找';
           Return := true;
           Close;
           exit;
     end;

     if edtSearchStr.Text = '' then
     begin
          messagebox(Handle,'请输入要搜索的内容!' ,'提醒',mb_ok or MB_ICONWARNING);
          exit;
     end;

     if (not chkTitle.Checked) and (not chkName.Checked) and (not chkContent.Checked) then
     begin
          messagebox(Handle,'请至少选中一个选项!' ,'提醒',mb_ok or MB_ICONWARNING);
          exit;
     end;

     Return := true;
     TitleOnly := true;
     ssCondition := '';

     SFlag := cbbLogic.Items[cbbLogic.itemindex];

     if cbbRoom.ItemIndex <> 0 then
     begin
          ssCondition := ssCondition + ' (roomid =' + inttostr(DM1.GetRoomID(cbbRoom.Items[cbbRoom.ItemIndex])) + ' ) and ';
     end;

     if chkTitle.Checked then ssCondition := ssCondition + prockeyword('subject', edtSearchStr.Text, SFlag) + ' or';

     if chkName.Checked then
     begin
     ssCondition := ssCondition + prockeyword('userfrom', edtSearchStr.Text, SFlag) + ' or';
     TitleOnly := false;
     end;

     if chkContent.Checked then
     begin
     ssCondition := ssCondition + prockeyword('content', edtSearchStr.Text, SFlag) + ' or';
     TitleOnly := false;
     end;

     ssCondition := copy(ssCondition,1,length(ssCondition)-2);

     SearchStr := 'select id,subject,userfrom,points,regdatetime,replytimes,status from letters where (' + ssCondition + ') and (parent = 0) ' ;

     //用于找出所有某人发过的贴子,包括跟贴,速度极慢
     if TitleOnly = false then
     begin
        SearchStr := 'select id,subject,userfrom,points,regdatetime,replytimes,status from letters where (' + ssCondition + ') and (parent = 0) ' ;
        SearchStr := SearchStr + ' union select id,subject,userfrom,points,regdatetime,replytimes,status from letters where id in (select parent from letters where (parent <> 0) And (' + ssCondition + ')) ';
//        SearchStr := SearchStr + ' union select id as 序号,subject as 标题,userfrom as 提问者,points as 分数,regdatetime as 发表时间,replytimes as 回复次数 from letters where id in (select parent,userform,roomid from letters where (parent <> 0) And (' + ssCondition + '))  order by regdatetime DESC';
     end;

     Target := '查找'+'“' + edtSearchStr.Text + '”';
     close;
end;

procedure TfrmSearch.btnCancelClick(Sender: TObject);
begin
     Close;
end;

procedure TfrmSearch.FormCreate(Sender: TObject);
var
        i:integer;
begin
     Return := false;

     cbbRoom.Items.Clear;
     cbbRoom.Items.Add('全部类别');
     cbbLogic.ItemIndex := 0;

     for i := 0 to DM1.sltRooms.Count - 1 do
     begin
            cbbRoom.Items.Add(DM1.sltRooms.Names[i]);
     end;

     cbbRoom.ItemIndex := 0;

//     frmSearch.FocusControl(edtSearchStr);
end;

function TfrmSearch.prockeyword(KeyType,KeyWord,Flag:string):string;
var
        tmp1:string;
begin
        KeyWord := ' ' + Trim(KeyWord);
        tmp1 := StringReplace(KeyWord,' ','%'' ' + Flag + ' ' + KeyType + ' like ''%', [rfReplaceAll]); 
        Result := copy(tmp1,7,length(tmp1)) + '%'' ';
end;

end.

⌨️ 快捷键说明

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