Смекни!
smekni.com

Разработка программы учета абитуриентов (стр. 4 из 4)

dm.Query1.Open;

end;

except

ShowMessage('НеполучилосьвыполнитьSQL запрос!');

end;

end;

procedure Ta_f.Label3Click(Sender: TObject);

begin

try

dm.Query1.Close;

dm.Query1.SQL.Clear;

dm.Query1.SQL.Add(Edit2.Text);

dm.Query1.Open;

except

ShowMessage('Не получилось выполнить SQL запрос!');

end;

end;

procedure Ta_f.Label6Click(Sender: TObject);

begin

a_r_f.Query1.Active:=False;

a_r_f.Query1.Active:=True;

a_r_f.report1.Preview;

end;

procedure Ta_f.Label8Click(Sender: TObject);

begin

if dm.Table1.Modified

then

dm.Table1.Post;

if dm.Table2.Modified

then

dm.Table2.Post;

Close;

end;

procedure Ta_f.Label9Click(Sender: TObject);

begin

a_r2_f.Query1.Active:=False;

a_r2_f.Query1.Active:=True;

a_r2_f.QuickRep1.Preview;

end;

procedure Ta_f.Button1Click(Sender: TObject);

begin

try

dm.Query1.Close;

dm.Query1.SQL.Clear;

dm.Query1.SQL.Add('select s.s_code, count (a.a_id) total from abiturients a, specialities s where a.a_s_id=s.s_id group by s.s_id,s_code');

dm.Query1.Open;

except

ShowMessage('Не получилось выполнить SQL запрос!');

end;

end;

procedure Ta_f.Label7Click(Sender: TObject);

begin

AboutBox.ShowModal;

end;

procedure Ta_f.FormPaint(Sender: TObject);

begin

dm.Table2.MasterSource:=dm.DataSource1;

dm.Table2.MasterFields:='S_id';

dm.Table2.IndexName:='a_index';

end;

end.

a_about.pas

unit a_about;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,

Buttons, ExtCtrls;

type

TAboutBox = class(TForm)

Panel1: TPanel;

ProgramIcon: TImage;

ProductName: TLabel;

Version: TLabel;

Copyright: TLabel;

Comments: TLabel;

OKButton: TButton;

private

{ Private declarations }

public

{ Public declarations }

end;

var

AboutBox: TAboutBox;

implementation

{$R *.DFM}

end.

a_r.pas

unit a_r;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

ExtCtrls, QuickRpt, Qrctrls, Db, DBTables, TeEngine, Series, TeeProcs,

Chart, DBChart, QrTee;

type

Ta_r_f = class(TForm)

report1: TQuickRep;

Table1: TTable;

DataSource1: TDataSource;

DataSource2: TDataSource;

Table2: TTable;

DetailBand1: TQRBand;

QRSubDetail1: TQRSubDetail;

QRLabel5: TQRLabel;

TitleBand1: TQRBand;

QRLabel10: TQRLabel;

ColumnHeaderBand1: TQRBand;

QRGroup1: TQRGroup;

QRLabel1: TQRLabel;

QRLabel2: TQRLabel;

QRLabel3: TQRLabel;

QRLabel11: TQRLabel;

QRLabel12: TQRLabel;

QRShape2: TQRShape;

QRDBText4: TQRDBText;

QRDBText5: TQRDBText;

QRDBText6: TQRDBText;

QRDBText7: TQRDBText;

QRExpr1: TQRExpr;

QRLabel4: TQRLabel;

QRDBText1: TQRDBText;

QRBand1: TQRBand;

QRExpr2: TQRExpr;

QRLabel6: TQRLabel;

Query1: TQuery;

DataSource3: TDataSource;

QRChart1: TQRChart;

QRDBChart1: TQRDBChart;

Series1: TPieSeries;

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

a_r_f: Ta_r_f;

implementation

uses dm_u;

{$R *.DFM}

procedure Ta_r_f.FormCreate(Sender: TObject);

var

DBPath: String; {путь к базе данных}

begin

if Table1.Active=true

then

Table1.Active:=false;

if Table2.Active=true

then

Table2.Active:=false;

if Query1.Active=True

then

Query1.Active:=False;

DBPath:=ExtractFilePath(Application.ExeName)+'db'; //определение пути к БД

Query1.DatabaseName:=DBPath;

Table1.DatabaseName:=DBPath;

Table1.Open;

Table2.DatabaseName:=DBPath;

Table2.Open;

Query1.Active:=True;

end;

end.

a_r2.pas

unit a_r2;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Db, DBTables, ExtCtrls, QuickRpt, Qrctrls, TeEngine, Series, TeeProcs,

Chart, DBChart, QrTee;

type

Ta_r2_f = class(TForm)

QuickRep1: TQuickRep;

DataSource1: TDataSource;

Query1: TQuery;

QRBand1: TQRBand;

QRLabel1: TQRLabel;

QRBand2: TQRBand;

QRGroup1: TQRGroup;

QRLabel2: TQRLabel;

QRLabel3: TQRLabel;

QRLabel4: TQRLabel;

QRDBText1: TQRDBText;

QRBand3: TQRBand;

QRLabel5: TQRLabel;

QRDBText4: TQRDBText;

QRShape1: TQRShape;

QRDBText2: TQRDBText;

QRDBText3: TQRDBText;

QRBand4: TQRBand;

QRExpr1: TQRExpr;

QRChart1: TQRChart;

QRDBChart1: TQRDBChart;

Series1: TPieSeries;

procedure QuickRep1StartPage(Sender: TCustomQuickRep);

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

a_r2_f: Ta_r2_f;

implementation

{$R *.DFM}

procedure Ta_r2_f.QuickRep1StartPage(Sender: TCustomQuickRep);

begin

QRDBChart1.CheckDatasource(Series1);

end;

procedure Ta_r2_f.FormCreate(Sender: TObject);

var

DBPath: String; {путькбазеданных}

begin

if Query1.Active=True

then

Query1.Active:=False;

DBPath:=ExtractFilePath(Application.ExeName)+'db'; //определение пути к БД

Query1.DatabaseName:=DBPath;

end;

end.

dm_u.pas

unit dm_u;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Db, DBTables;

type

Tdm = class(TDataModule)

Query1: TQuery;

DataSource3: TDataSource;

Table2: TTable;

Table2A_id: TAutoIncField;

Table2A_surname: TStringField;

Table2A_math: TSmallintField;

Table2A_physic: TSmallintField;

Table2A_composition: TSmallintField;

Table2A_s_id: TSmallintField;

Table2sum: TIntegerField;

DataSource2: TDataSource;

Table1: TTable;

DataSource1: TDataSource;

db: TDatabase;

procedure Table2CalcFields(DataSet: TDataSet);

procedure Table2A_mathValidate(Sender: TField);

procedure Table2A_physicValidate(Sender: TField);

procedure Table2A_compositionValidate(Sender: TField);

procedure DataModuleCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

dm: Tdm;

implementation

{$R *.DFM}

procedure Tdm.Table2CalcFields(DataSet: TDataSet);

begin

dm.Table2sum.Value:=dm.Table2A_math.Value+dm.Table2A_physic.Value+dm.Table2A_composition.Value;

end;

procedure Tdm.Table2A_mathValidate(Sender: TField);

begin

if (dm.Table2A_math.Value<2) or (dm.Table2A_math.Value>5)

then

begin

ShowMessage('Оценка допустима только от 2 до 5!');

Abort;

end;

end;

procedure Tdm.Table2A_physicValidate(Sender: TField);

begin

if (dm.Table2A_physic.Value<2) or (dm.Table2A_physic.Value>5)

then

begin

ShowMessage('Оценка допустима только от 2 до 5!');

Abort;

end;

end;

procedure Tdm.Table2A_compositionValidate(Sender: TField);

begin

if (dm.Table2A_composition.Value<2) or (dm.Table2A_composition.Value>5)

then

begin

ShowMessage('Оценка допустима только от 2 до 5!');

Abort;

end;

end;

procedure Tdm.DataModuleCreate(Sender: TObject);

var

DBPath: String; {путькбазеданных}

begin

with dm do

begin

if table1.Active=True

then

table1.active:=false;

if table2.active=true

then

table2.active:=false;

end;

DBPath:=ExtractFilePath(Application.ExeName)+'db'; //определениепутикБД

DM.Table1.DatabaseName:=DBPath; {указатьбазу}

DM.Table1.Open; {открытьтаблицу}

DM.Table2.DatabaseName:=DBPath;

DM.Table2.Open;

Query1.DatabaseName:=DBPath;

end;

end.


Приложение Г

Примеры экранных форм диаграмм и отчетов


Рисунок Г.1 – Количество абитуриентов по специальностям – отчет и диаграмма

Рисунок Г.2 – Сортировка по сумме баллов – отчет и диаграмма