📄 usortrecords.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "uSortRecords.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ABSMain"
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString s, Index;
const AnsiString DataBaseFileName = "../../Data/Demos.abs";
const AnsiString QueryConst = "select * from employee order by ";
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
dbDemos->DatabaseFileName = ExtractFilePath(Application->ExeName) + DataBaseFileName;
dbDemos->Open();
Table->TableName = "employee";
Index = "ByFirstName";
s = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::rgComponentClick(TObject *Sender)
{
if (rgComponent->ItemIndex == 1)
{
mSQL->Enabled = false;
mSQL->Text = "Using ABSTable component for sorting";
}
else
{
mSQL->Enabled = true;
mSQL->Text = s;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::rgSortingClick(TObject *Sender)
{
switch (rgComponent->ItemIndex)
{
case 0: switch (rgSorting->ItemIndex)
{
case 0:
{
mSQL->Text = QueryConst + "FirstName ASC";
Index = "ByFirstName";
};
break;
case 1:
{
mSQL->Text = QueryConst + "LastName DESC";
Index = "ByLastName";
};
break;
case 2:
{
mSQL->Text = QueryConst + "Salary DESC, LastName ASC";
Index = "BySalaryLastName";
};
break;
};
break;
case 1: switch (rgSorting->ItemIndex)
{
case 0:
{
Index = "ByFirstName";
s = QueryConst + "FirstName ASC";
};
break;
case 1:
{
Index = "ByLastName";
s = QueryConst + "LastName DESC";
};
break;
case 2:
{
Index = "BySalaryLastName";
s = QueryConst + "Salary DESC, LastName ASC";
};
break;
};
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
switch (rgComponent->ItemIndex)
{
case 0: {
Query->Close();
DataSource1->DataSet = Query;
Query->SQL->Text = mSQL->Text;
Query->Open();
};
break;
case 1: {
Table->Close();
DataSource1->DataSet = Table;
Table->IndexName = Index;
Table->Open();
};
break;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -