//---------------------------------------------------------------------------
#pragma hdrstop
#include <vcl.h>
#include <string.h>
#include "database.h"
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TWindow *Window;
//---------------------------------------------------------------------------
__fastcall TWindow::TWindow(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TWindow::SearchBtnClick(TObject *Sender)
{
if (!ChooseBox->Checked[0] &&!ChooseBox->Checked[1] &&!ChooseBox->Checked[2])
MessageBox(NULL, L"Оберіть хоча б один із типів пошуку!",
NULL, MB_OK | MB_ICONERROR);
else if (!SearchText->Text.Length())
MessageBox(NULL, L"Введіть ваш запит.",
NULL, MB_OK | MB_ICONASTERISK);
else
{
DB *db;
try {
db = new DB("reg.db");
} catch (DB::Err e)
{
ShowMessage(e.errstr);
exit(1);
}
bool first = false;
AnsiString query = "SELECT * FROM keys WHERE ";
for (int c=0; c<3; c++)
if (ChooseBox->Checked[c])
{
if (first) query+= " OR ";
if (!LookRegister->Checked) query+= "UPPER(";
switch (c)
{
case 0: query+= "name"; break;
case 1: query+= "type"; break;
case 2: query+= "value"; break;
}
if (!LookRegister->Checked) query+= ")";
query+= " LIKE ";
if (!LookRegister->Checked) query+= "UPPER(";
query+= "\"";
if (!FullWord->Checked) query+="\%";
query+= SearchText->Text;
if (!FullWord->Checked) query+="\%";
query+= "\"";
if (!LookRegister->Checked) query+= ")";
first = true;
}
db->SQLRun(query.c_str());
TStringList *Add = new TStringList();
Add->LoadFromFile("out");
remove("out");
FoundList->Clear();
if (!Add->Count)
{
MessageBox(NULL, L"За вашим запитом нічого не знайдено.",
NULL, MB_OK | MB_ICONASTERISK);
delete Add;
return;
}
TListItem *LI = FoundList->Items->Add();
for (int i=0; i<Add->Count; i+=4)
{
LI = FoundList->Items->Add();
LI->Caption = Add->Strings[i];
LI->SubItems->Add(Add->Strings[i+1]);
LI->SubItems->Add(Add->Strings[i+2]);
if (Add->Strings[i+2] == "REG_MULTI_SZ")
{
UnicodeString temp;
while (true)
{
if (Add->Strings[i+3]!= "")
{
temp+=Add->Strings[i+3]+" ";
i+=2;
}
else break;
}
LI->SubItems->Add(temp);
}
else
LI->SubItems->Add(Add->Strings[i+3]);
}
delete Add;
delete LI;
}
}
//---------------------------------------------------------------------------
void __fastcall TWindow::SearchTextKeyPress(TObject *Sender, System::WideChar &Key)
{
if (Key == 13) SearchBtnClick(Sender);
}
//---------------------------------------------------------------------------