Смекни!
smekni.com

Проектування дволанкової розподіленої інформаційної системи для роботи з базами даних із використанням (стр. 5 из 6)

TabOrder = 1

object dp2_DBEdit: TDBEdit

Left = 5

Top = 15

Width = 156

Height = 23

Color = clSilver

DataField = 'PROISV'

DataSource = dp_DataSource

Enabled = False

TabOrder = 0

end

end

object pr_GroupBox: TGroupBox

Left = 8

Top = 113

Width = 393

Height = 226

Caption = ' Співробітники'

Font.Charset = RUSSIAN_CHARSET

Font.Color = clWindowText

Font.Height = -13

Font.Name = 'Times New Roman'

Font.Style = [fsBold, fsItalic]

ParentFont = False

TabOrder = 2

object pr_Panel: TPanel

Left = 9

Top = 196

Width = 66

Height = 26

TabOrder = 0

object pr_Label: TLabel

Left = 9

Top = 3

Width = 47

Height = 20

Alignment = taCenter

AutoSize = False

Caption = '1'

Font.Charset = RUSSIAN_CHARSET

Font.Color = clRed

Font.Height = -13

Font.Name = 'Times New Roman'

Font.Style = [fsBold, fsItalic]

ParentFont = False

Layout = tlCenter

end

end

end

object find_Animate: TAnimate

Left = 40

Top = 4

Width = 48

Height = 45

Active = True

CommonAVI = aviFindComputer

StopFrame = 8

end

object GroupBox1: TGroupBox

Left = 8

Top = 340

Width = 393

Height = 77

Caption = 'Поточнийоператор SQL'

Font.Charset = RUSSIAN_CHARSET

Font.Color = clWindowText

Font.Height = -13

Font.Name = 'Times New Roman'

Font.Style = [fsBold, fsItalic]

ParentFont = False

TabOrder = 4

object sql_Label: TLabel

Left = 11

Top = 16

Width = 372

Height = 57

AutoSize = False

Color = clBtnFace

Font.Charset = RUSSIAN_CHARSET

Font.Color = clRed

Font.Height = -13

Font.Name = 'Times New Roman'

Font.Style = [fsBold, fsItalic]

ParentColor = False

ParentFont = False

WordWrap = True

end

end

end

object pr_DBGrid: TDBGrid

Left = 22

Top = 136

Width = 378

Height = 173

DataSource = pr_DataSource

Font.Charset = RUSSIAN_CHARSET

Font.Color = clWindowText

Font.Height = -11

Font.Name = 'Times New Roman'

Font.Style = [fsItalic]

Options = [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit]

ParentFont = False

TabOrder = 0

TitleFont.Charset = RUSSIAN_CHARSET

TitleFont.Color = clWindowText

TitleFont.Height = -11

TitleFont.Name = 'Times New Roman'

TitleFont.Style = [fsItalic]

OnCellClick = pr_DBGridCellClick

OnKeyDown = pr_DBGridKeyDown

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_DBNavigator: TDBNavigator

Left = 96

Top = 320

Width = 304

Height = 18

DataSource = pr_DataSource

VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast]

TabOrder = 2

end

end

object dp_DataSource: TDataSource

DataSet = dp_Query

Left = 110

Top = 58

end

object pr_DataSource: TDataSource

DataSet = pr_Query

Left = 213

Top = 263

end

object dp_Query: TQuery

DatabaseName = 'dbP'

RequestLive = True

SQL.Strings = (

'Select * from Dep where DEP = :PDEP')

Left = 139

Top = 58

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 = 271

Top = 263

end

object pr_Query: TQuery

ObjectView = True

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 = 242

Top = 263

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_QueryAGE: TSmallintField

Alignment = taCenter

DisplayLabel = 'Возраст'

DisplayWidth = 7

FieldKind = fkCalculated

FieldName = 'AGE'

Calculated = True

end

end

object insert_StoredProc: TStoredProc

ObjectView = True

DatabaseName = 'dbP'

StoredProcName = 'INSERTDBP'

Left = 308

Top = 263

ParamData = <

item

DataType = ftString

Name = 'PDEP'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PFAM'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PNAM'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PPAR'

ParamType = ptInput

end

item

DataType = ftInteger

Name = 'PYEAR_B'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PSEX'

ParamType = ptInput

end>

end

object update_StoredProc: TStoredProc

ObjectView = True

DatabaseName = 'dbP'

StoredProcName = 'UPDATEDBP'

Left = 366

Top = 263

ParamData = <

item

DataType = ftString

Name = 'PDEP'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PFAM'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PNAM'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PPAR'

ParamType = ptInput

end

item

DataType = ftInteger

Name = 'PYEAR_B'

ParamType = ptInput

end

item

DataType = ftString

Name = 'PSEX'

ParamType = ptInput

end

item

DataType = ftInteger

Name = 'NUMBER'

ParamType = ptOutput

end>

end

object delete_StoredProc: TStoredProc

ObjectView = True

DatabaseName = 'dbP'

StoredProcName = 'DELETEDBP'

Left = 337

Top = 263

ParamData = <

item

DataType = ftInteger

Name = 'PNUM'

ParamType = ptInput

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;

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;

TComboBox *dp_ComboBox;

TDBEdit *dp2_DBEdit;

TStringField *dp_QueryDEP;

TStringField *dp_QueryPROISV;

TGroupBox *GroupBox1;

TLabel *sql_Label;

TAnimate *Animate1;

TBevel *oper_Bevel;

TShape *oper_Shape;

TImage *Image1;

TQuery *pr_Query;

TSmallintField *pr_QueryNUM;

TStringField *pr_QueryDEP;

TStringField *pr_QueryFAM;

TStringField *pr_QueryNAM;

TStringField *pr_QueryPAR;

TSmallintField *pr_QueryYEAR_B;

TStringField *pr_QuerySEX;

TSmallintField *pr_QueryAGE;

TStoredProc *insert_StoredProc;

TStoredProc *update_StoredProc;

TStoredProc *delete_StoredProc;

TPanel *pr_Panel;

TLabel *pr_Label;

void __fastcall FormCreate(TObject *Sender);

void __fastcall dp_ComboBoxChange(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);

void __fastcall prview_RadioGroupClick(TObject *Sender);

void __fastcall pr_DBGridKeyDown(TObject *Sender, WORD &Key,

TShiftState Shift);

private:// User declarations

public:// User declarations

fastcall Tmain_Form(TComponent* Owner);

unsigned short Year;

unsigned short Month;

unsigned short Day;

bool CanPost;

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"

#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);

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();

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(3000);

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(3000);

pr_Query->SQL->Add(sql_Operator);

} else {

// показ записів за переглядами

sql_Operator =

"Select * from DEP_" + AnsiString(dp_ComboBox->ItemIndex + 1);

sql_Label->Caption = sql_Operator;

Delay(3000);

pr_Query->SQL->Add(sql_Operator);

}

pr_Query->ExecSQL();

pr_Query->Open();

pr_Query->First();

}

//---------------------------------------------------------------------------