48404 (566512), страница 3
Текст из файла (страница 3)
TitleFont.Height = -11
TitleFont.Name = 'Times New Roman'
TitleFont.Style = [fsItalic]
OnCellClick = pr_DBGridCellClick
Columns = <
item
Expanded = False
FieldName = 'FAM'
Title.Caption = 'Прізвище'
Width = 59
Visible = True
end
item
Expanded = False
FieldName = 'NAM'
Title.Caption = 'ім'#39'я'
Width = 57
Visible = True
end
item
Expanded = False
FieldName = 'PAR'
Title.Caption = 'по батькові'
Width = 67
Visible = True
end
item
Alignment = taCenter
Expanded = False
FieldName = 'YEAR_B'
Title.Caption = 'рік народження'
Width = 85
Visible = True
end
item
Alignment = taCenter
Expanded = False
FieldName = 'SEX'
Title.Caption = 'стать'
Visible = True
end
item
Expanded = False
FieldName = 'AGE'
Title.Caption = 'вік'
Width = 38
Visible = True
end
item
Expanded = False
FieldName = 'CHARACT'
Title.Caption = 'характеристика'
Visible = True
end
item
Expanded = False
FieldName = 'PHOTO'
Title.Caption = 'фото'
Visible = True
end>
end
object pr_Button: TButton
Left = 326
Top = 319
Width = 75
Height = 20
Hint = 'Характеристика, фотография'
Caption = '&Більше ...'
Font.Charset = RUSSIAN_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Times New Roman'
Font.Style = [fsBold, fsItalic]
ParentFont = False
ParentShowHint = False
ShowHint = True
TabOrder = 2
OnClick = pr_ButtonClick
end
object pr_DBNavigator: TDBNavigator
Left = 73
Top = 319
Width = 244
Height = 20
DataSource = pr_DataSource
VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]
TabOrder = 3
end
end
object dp_DataSource: TDataSource
DataSet = dp_Query
Left = 140
Top = 55
end
object pr_DataSource: TDataSource
DataSet = pr_Query
Left = 298
Top = 268
end
object dp_Query: TQuery
DatabaseName = 'dbP'
RequestLive = True
SQL.Strings = (
'Select * from Dep where DEP = :PDEP')
Left = 169
Top = 55
ParamData = <
item
DataType = ftString
Name = 'PDEP'
ParamType = ptUnknown
end>
object dp_QueryDEP: TStringField
FieldName = 'DEP'
Origin = 'DEP.DEP'
Size = 15
end
object dp_QueryPROISV: TStringField
FieldName = 'PROISV'
Origin = 'DEP.PROISV'
Size = 15
end
end
object update_Query: TQuery
DatabaseName = 'dbP'
DataSource = pr_DataSource
RequestLive = True
Left = 356
Top = 268
end
object pr_Query: TQuery
BeforePost = pr_QueryBeforePost
AfterScroll = pr_QueryAfterScroll
OnCalcFields = pr_QueryCalcFields
DatabaseName = 'dbP'
RequestLive = True
SQL.Strings = (
'Select * from Pers where DEP = :DEP order by FAM,NAM,PAR')
Left = 327
Top = 268
ParamData = <
item
DataType = ftString
Name = 'DEP'
ParamType = ptUnknown
end>
object pr_QueryNUM: TSmallintField
FieldName = 'NUM'
Origin = 'PERS.NUM'
end
object pr_QueryDEP: TStringField
FieldName = 'DEP'
Origin = 'PERS.DEP'
Size = 15
end
object pr_QueryFAM: TStringField
FieldName = 'FAM'
Origin = 'PERS.FAM'
end
object pr_QueryNAM: TStringField
FieldName = 'NAM'
Origin = 'PERS.NAM'
end
object pr_QueryPAR: TStringField
FieldName = 'PAR'
Origin = 'PERS.PAR'
end
object pr_QueryYEAR_B: TSmallintField
FieldName = 'YEAR_B'
Origin = 'PERS.YEAR_B'
end
object pr_QuerySEX: TStringField
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "cspin.h"
#include "CSPIN.h"
#include
#include
#include
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
#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);















