FieldName = 'SEX'
Origin = 'PERS.SEX'
Size = 1
end
object pr_QueryCHARACT: TBlobField
FieldName = 'CHARACT'
Origin = 'PERS.CHARACT'
BlobType = ftMemo
Size = 1
end
object pr_QueryPHOTO: TBlobField
FieldName = 'PHOTO'
Origin = 'PERS.PHOTO'
BlobType = ftGraphic
Size = 1
end
object pr_QueryAGE: TSmallintField
Alignment = taCenter
DisplayLabel = 'Возраст'
DisplayWidth = 7
FieldKind = fkCalculated
FieldName = 'AGE'
Calculated = True
end
end
end
Підлеглуформу character_Form наведенонамал. 1.14.
Малюнок 1.14
Текстовий опис цієї форми наведено нижче:
object character_Form: Tcharacter_Form
Left = 237
Top = 95
Width = 318
Height = 226
Caption = 'Характеристика'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
Position = poDefaultPosOnly
PixelsPerInch = 96
TextHeight = 13
object character_DBMemo: TDBMemo
Left = 0
Top = 0
Width = 195
Height = 194
Align = alClient
Alignment = taCenter
DataField = 'Charact'
DataSource = main_Form.pr_DataSource
ScrollBars = ssVertical
TabOrder = 0
end
object PPhoto: TPanel
Left = 195
Top = 0
Width = 115
Height = 194
Align = alRight
Caption = 'PPhoto'
TabOrder = 1
object photo_DBImage: TDBImage
Left = 5
Top = 42
Width = 105
Height = 105
DataField = 'Photo'
DataSource = main_Form.pr_DataSource
TabOrder = 0
end
end
end
Для функціонування прикладення розроблено програму:
Файл Udb.h
#ifndef UdbH
#define UdbH
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <DBCtrls.hpp>
#include <DBGrids.hpp>
#include <ExtCtrls.hpp>
#include <Grids.hpp>
#include <Mask.hpp>
#include <Db.hpp>
#include <DBTables.hpp>
#include "cspin.h"
#include "CSPIN.h"
#include <jpeg.hpp>
#include <Buttons.hpp>
#include <Graphics.hpp>
class Tmain_Form : public TForm
{
__published: // IDE-managed Components
TPageControl *PageControl;
TTabSheet *find_TabSheet;
TRadioGroup *sex_RadioGroup;
TEdit *speedfind_Edit;
TDataSource *dp_DataSource;
TDataSource *pr_DataSource;
TTabSheet *TabEdit;
TComboBox *chdp_ComboBox;
TEdit *chfam_Edit;
TEdit *chname_Edit;
TEdit *chgrand_Edit;
TRadioGroup *sex2_RadioGroup;
TButton *chadd_Button;
TButton *chdelete_Button;
TButton *chpost_Button;
TCSpinEdit *chyear_CSpinEdit;
TCSpinEdit *minage_CSpinEdit;
TCSpinEdit *maxage_CSpinEdit;
TPanel *left_Panel;
TPanel *find_TPanel;
TLabel *find_Label;
TGroupBox *dp_GroupBox;
TGroupBox *dp2_GroupBox;
TGroupBox *pr_GroupBox;
TDBGrid *pr_DBGrid;
TButton *pr_Button;
TDBNavigator *pr_DBNavigator;
TGroupBox *ch_GroupBox;
TLabel *chdp_Label;
TLabel *chname_Label;
TLabel *chgrand_Label;
TLabel *chyear_Label;
TLabel *chfam_Label;
TGroupBox *age_GroupBox;
TLabel *minage_Label;
TLabel *maxage_Label;
TGroupBox *speedfind_GroupBox;
TLabel *speedfind_Label;
TImage *speedfind_Image;
TImage *minage_Image;
TImage *maxage_Image;
TAnimate *find_Animate;
TBitBtn *select_BitBtn;
TGroupBox *select_GroupBox;
TQuery *dp_Query;
TQuery *update_Query;
TQuery *pr_Query;
TComboBox *dp_ComboBox;
TDBEdit *dp2_DBEdit;
TStringField *dp_QueryDEP;
TStringField *dp_QueryPROISV;
TSmallintField *pr_QueryNUM;
TStringField *pr_QueryDEP;
TStringField *pr_QueryFAM;
TStringField *pr_QueryNAM;
TStringField *pr_QueryPAR;
TSmallintField *pr_QueryYEAR_B;
TStringField *pr_QuerySEX;
TBlobField *pr_QueryCHARACT;
TBlobField *pr_QueryPHOTO;
TSmallintField *pr_QueryAGE;
TLabel *pr_Label;
TBevel *Bevel1;
TGroupBox *GroupBox1;
TLabel *sql_Label;
TAnimate *Animate1;
TBevel *oper_Bevel;
TShape *oper_Shape;
TImage *Image1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall dp_ComboBoxChange(TObject *Sender);
void __fastcall pr_ButtonClick(TObject *Sender);
void __fastcall speedfind_EditChange(TObject *Sender);
void __fastcall pr_QueryCalcFields(TDataSet *DataSet);
void __fastcall pr_QueryAfterScroll(TDataSet *DataSet);
void __fastcall pr_QueryBeforePost(TDataSet *DataSet);
void __fastcall chadd_ButtonClick(TObject *Sender);
void __fastcall chdelete_ButtonClick(TObject *Sender);
void __fastcall chpost_ButtonClick(TObject *Sender);
void __fastcall PageControlChange(TObject *Sender);
void __fastcall minage_CSpinEditChange(TObject *Sender);
void __fastcall select_BitBtnClick(TObject *Sender);
void __fastcall pr_DBGridCellClick(TColumn *Column);
private: // User declarations
public: // User declarations
__fastcall Tmain_Form(TComponent* Owner);
unsigned short Year;
unsigned short Month;
unsigned short Day;
bool CanPost;
int AllPers, CurrentPers;
AnsiString sql_Operator;
void __fastcall Delay(unsigned long int mSeconds);
};
extern PACKAGE Tmain_Form *main_Form;
#endif
Файл Udb.cpp
#include <vcl.h>
#pragma hdrstop
#include "Udb.h"
#include "Udba.h"
#pragma package(smart_init)
#pragma link "cspin"
#pragma link "CSPIN"
#pragma resource "*.dfm"
Tmain_Form *main_Form;
__fastcall Tmain_Form::Tmain_Form(TComponent* Owner)
: TForm(Owner)
{}
void __fastcall Tmain_Form::FormCreate(TObject *Sender)
{
CanPost = false;
Date().DecodeDate(&Year,&Month,&Day);
// підрахуваннякількостізаписівутаблиці PERS
pr_Query->SQL->Clear();
sql_Operator = "Select * from PERS order by NUM";
sql_Label->Caption = sql_Operator;
pr_Query->SQL->Add(sql_Operator);
pr_Query->Open();
pr_Query->First();
AllPers = 0;
while (!pr_Query->Eof) {
++AllPers;
pr_Query->Next();
}
pr_Query->First();
dp_Query->SQL->Clear();
sql_Operator = "Select * from DEP";
sql_Label->Caption = sql_Operator;
dp_Query->SQL->Add(sql_Operator);
dp_Query->Open();
dp_Query->First();
// Заповнення ComboBox dp_ComboBox та chdp_ComboBox наймуваннямивідділків
dp_ComboBox->Clear();
chdp_ComboBox->Clear();
while (!dp_Query->Eof) {
dp_ComboBox->Items->Add(dp_QueryDEP->AsString);
chdp_ComboBox->Items->Add(dp_QueryDEP->AsString);
dp_Query->Next();
}
dp_ComboBox->Items->Add("усівідділки");
dp_ComboBox->ItemIndex = dp_ComboBox->Items->Count - 1;
dp_ComboBoxChange(Sender);
chdp_ComboBox->ItemIndex = dp_ComboBox->ItemIndex;
PageControl->ActivePage = find_TabSheet;
}
void __fastcall Tmain_Form::dp_ComboBoxChange(TObject *Sender)
{
dp_Query->Close();
dp_Query->SQL->Clear();
sql_Operator = "Select * from DEP where DEP=:PDEP";
sql_Label->Caption = sql_Operator;
Delay(5000);
dp_Query->SQL->Add(sql_Operator);
dp_Query->Params->Items[0]->AsString = dp_ComboBox->Text;
dp_Query->Open();
dp_Query->First();
pr_Query->Close();
pr_Query->SQL->Clear();
if (dp_ComboBox->ItemIndex == dp_ComboBox->Items->Count - 1) {
sql_Operator = "Select * from PERS order by NUM";
sql_Label->Caption = sql_Operator;
Delay(5000);
pr_Query->SQL->Add(sql_Operator);
} else {
sql_Operator = "Select * from PERS where DEP = :DEP order by NUM";
sql_Label->Caption = sql_Operator;
Delay(5000);
pr_Query->SQL->Add(sql_Operator);
pr_Query->Params->Items[0]->AsString = dp_ComboBox->Text;
}
pr_Query->ExecSQL();
pr_Query->Open();
pr_Query->First();
}
void __fastcall Tmain_Form::pr_ButtonClick(TObject *Sender)
{
if (!character_Form->Visible) character_Form->Show();
}
void __fastcall Tmain_Form::speedfind_EditChange(TObject *Sender)
{
TLocateOptions SearchOptions;
pr_Query->Locate("FAM", speedfind_Edit->Text,
SearchOptions << loPartialKey << loCaseInsensitive);
}
void __fastcall Tmain_Form::pr_QueryCalcFields(TDataSet *DataSet)
{
pr_QueryAGE->Value = Year - pr_QueryYEAR_B->Value;
}
void __fastcall Tmain_Form::pr_QueryAfterScroll(TDataSet *DataSet)
{
// поточнаперсона
CurrentPers = pr_QueryNUM->AsInteger;
pr_Label->Caption = IntToStr(CurrentPers);
if (PageControl->ActivePage == TabEdit) {
// відображенняданихпропоточнуперсону
chdp_ComboBox -> ItemIndex =
chdp_ComboBox->Items->IndexOf(pr_QueryDEP->AsString);
chfam_Edit->Text = pr_QueryFAM->AsString;
chname_Edit->Text = pr_QueryNAM->AsString;
chgrand_Edit->Text = pr_QueryPAR->AsString;
chyear_CSpinEdit->Value = pr_QueryYEAR_B->AsInteger;
if (pr_QuerySEX->AsString == "ч") sex2_RadioGroup->ItemIndex = 0;
else sex2_RadioGroup->ItemIndex = 1;
}
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::pr_QueryBeforePost(TDataSet *DataSet)
{
if (!CanPost) {
DataSet->Cancel();
Abort;
}
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::chadd_ButtonClick(TObject *Sender)
{ // додаваннязаписудотаблиці PERS
AnsiString NewSex; // визначеннястаті
if (sex2_RadioGroup->ItemIndex == 0) NewSex = "ч";
else NewSex = "ж";
update_Query->Close();
update_Query->SQL->Clear();
sql_Operator = "Insert into PERS (DEP,FAM,NAM,PAR,YEAR_B,SEX,NUM) values ('"
+ chdp_ComboBox->Text + "','"
+ chfam_Edit->Text + "','"
+ chname_Edit->Text + "','"
+ chgrand_Edit->Text + "','"
+ IntToStr((int)chyear_CSpinEdit->Value) + "','"
+ NewSex + "','"
+ IntToStr(++AllPers) + "')"; // збільшеннякількостізаписівутаблиці PERS
sql_Label->Caption = sql_Operator;
Delay(5000);
update_Query->SQL->Add(sql_Operator);
update_Query->ExecSQL(); // додаваннязапису
pr_Query->Close(); // поновленнявідображенняданихтаблиці PERS
pr_Query->Open();
PageControlChange(Sender);
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::chdelete_ButtonClick(TObject *Sender)
{ // видалення поточного запису з таблиці PERS
if (Application->MessageBox("Ви дійсно бажаєте видалити поточний запис?",
"Підтвердіть видалення запису",
MB_YESNO + MB_ICONEXCLAMATION) == IDYES)
update_Query->Close();
update_Query->SQL->Clear();
sql_Operator = "Delete from PERS where NUM = " + IntToStr(CurrentPers);
sql_Label->Caption = sql_Operator;
Delay(5000);
update_Query->SQL->Add(sql_Operator);
update_Query->ExecSQL(); // видаленнязапису
pr_Query->Close(); // поновленнявідображенняданихталиці PERS
pr_Query->Open();
--AllPers; // зменшеннякількостізаписівутаблиці PERS
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::chpost_ButtonClick(TObject *Sender)
{
AnsiString s, sSQL;
const AnsiString s1 = ",";
s = "";
sSQL = "Update PERS set ";
if (pr_QueryDEP->AsString != chdp_ComboBox->Text) {
s = "відділок";
sSQL += "DEP='" + chdp_ComboBox->Text + "'";
}
if (pr_QueryCHARACT->AsString != chfam_Edit->Text) {
if (s != "") { s += s1; sSQL += s1; }
s += " прізвище";
sSQL += "FAM='" + chfam_Edit->Text + "'";
}
if (pr_QueryCHARACT->AsString != chname_Edit->Text) {
if (s != "") { s += s1; sSQL += s1; }
s += " ім'я";
sSQL += "NAM='" + chname_Edit->Text+"'";
}
if (pr_QueryCHARACT->AsString != chgrand_Edit->Text) {
if (s != "") { s += s1; sSQL += s1; }
s += " побатькові";
sSQL += "PAR='" + chgrand_Edit->Text + "'";
}
if (pr_QueryYEAR_B->AsInteger != chyear_CSpinEdit->Value) {
if (s != "") { s += s1; sSQL += s1; }
s += " рікнародження";
sSQL += "YEAR_B='" + IntToStr((int)(chyear_CSpinEdit->Value));
}
if (pr_QuerySEX->AsBoolean != (sex2_RadioGroup->ItemIndex == 0)) {
if (s != "") { s += s1; sSQL += s1; }
s += " стать";
sSQL += "SEX='";
if(sex2_RadioGroup->ItemIndex == 0) sSQL += "ч'";
else sSQL += "ж'";
}
if (s != "")
if (Application->MessageBox(
("Дійснобажаєтезмінити " + s + "?").c_str(),
"Підтвердіть занесення змін у базу даних",
MB_YESNO + MB_ICONQUESTION) == IDYES)
{ update_Query->Close();
update_Query->SQL->Clear();
sql_Operator = sSQL + " where NUM=" + IntToStr(pr_QueryNUM->AsInteger);
sql_Label->Caption = sql_Operator;
Delay(5000);
update_Query->SQL->Add(sql_Operator);
update_Query->ExecSQL();
pr_Query->Close();
pr_Query->Open();
CanPost = false;
};
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::PageControlChange(TObject *Sender)
{
character_Form->character_DBMemo->ReadOnly =
!(PageControl->ActivePage == TabEdit);
if (PageControl->ActivePage == TabEdit) pr_QueryAfterScroll(pr_Query);
}
//---------------------------------------------------------------------------
void __fastcall Tmain_Form::minage_CSpinEditChange(TObject *Sender)
{
AnsiString s =
"(YEAR_B<=" + IntToStr(int(Year - minage_CSpinEdit->Value)) +
")and(YEAR_B>=" + IntToStr(int(Year - maxage_CSpinEdit->Value)) +
")and(SEX=";
if (!sex_RadioGroup->ItemIndex) s += "'ч')";
else s += "'ж')";
// автоматичне поновлення відбору записів
select_BitBtn->Kind = bkCancel;
select_BitBtn->Caption = "Відмінитивідбір";
pr_Query->Filter = s;
pr_Query->Filtered = true;
}
//---------------------------------------------------------------------------