Автор работы: Пользователь скрыл имя, 08 Апреля 2013 в 10:01, реферат
Программа «Футбольные команды и игроки» разработана на языке высокого уровня Borland Delphi. В программе реализованы следующие компоненты:
• База данных, состоящая из 6 таблиц, из которых 4 справочника, одна операционная таблица и одна вспомогательная таблица;
• Пользовательский интерфейс работы с базой данных;
• Защита от ввода неверных данных.
Введение
Постановка задачи
Таблицы БД и связи между ними
Описание внешнего вида пользовательского интерфейса
Описание алгоритма работы программы
Приложения
Текст проекта football.dpr
Текст модуля gl_form.pas
Текст модуля gl_per.pas
Текст модуля igroki.pas
Текст модуля komandi.pas
Текст модуля dob_klyb.pas
Текст модуля stadioni.pas
Текст модуля transfer.pas
Текст модуля ist_trans.pas
form6.komandi.Locate('nom_kom'
loPartialKey]);
form6.komandi.Edit;
form6.ComboBox1.text:=strani.
form6.ComboBox2.Text:=
form6.Caption:='Редактирование
команды '+komandi.fieldbyname('naim').
form6.ShowModal;
end;
procedure TForm5.Button8Click(Sender: TObject);
begin
if edit1.text='' then exit;
if not komandi.Locate('naim', Edit1.Text, [loCaseInsensitive,
loPartialKey]) then
ShowMessage('Запись не найдена');
end;
procedure TForm5.BitBtn1Click(Sender: TObject);
begin
edit1.text:='';
end;
procedure TForm5.Timer1Timer(Sender: TObject);
begin
label21.Caption:=inttostr(
end;
procedure TForm5.Button3Click(Sender: TObject);
begin
komandi.First;
label20.Caption:=komandi.
label18.Caption:=inttostr(
end;
procedure TForm5.Button4Click(Sender: TObject);
begin
komandi.Last;
label20.Caption:=komandi.
label18.Caption:=inttostr(
end;
end.
Текст модуля dob_klyb.pas
unit dob_klyb;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, Mask, DBCtrls, gl_per;
type
TForm6 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
DataSource1: TDataSource;
DataSource2: TDataSource;
komandi: TTable;
strani: TTable;
stadioni: TTable;
DataSource3: TDataSource;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
ComboBox1: TComboBox;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
ComboBox2: TComboBox;
DBEdit8: TDBEdit;
Button1: TButton;
Button2: TButton;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form6: TForm6;
implementation
uses komandi;
{$R *.dfm}
Procedure stran;
begin
form6.strani.First;
while not form6.strani.Eof do
begin
form6.ComboBox1.Items.Add(
form6.strani.Next;
end;
end;
Procedure stadion;
begin
form6.stadioni.First;
form6.ComboBox2.Items.Clear;
while not form6.stadioni.Eof do
begin
form6.ComboBox2.Items.Add(
form6.stadioni.Next;
end;
end;
procedure TForm6.FormActivate(Sender: TObject);
begin
stran; stadion;
komandi.Refresh;
end;
procedure TForm6.Button1Click(Sender: TObject);
var
a2:byte;
begin
a2:=0;
if kdr=1 then begin //режим добавления клуба
if dbedit1.text='' then a2:=1;
if dbedit2.text='' then a2:=1;
if dbedit3.text='' then a2:=1;
if dbedit4.text='' then a2:=1;
if dbedit5.text='' then a2:=1;
if dbedit6.text='' then a2:=1;
if dbedit7.text='' then a2:=1;
if dbedit8.text='' then a2:=1;
if combobox1.text='' then a2:=1;
if combobox1.text='' then a2:=1;
if a2=1 then begin showmessage('Введены не все данные');
exit; end;
strani.Locate('naim_str', Combobox1.Text, [loCaseInsensitive,
loPartialKey]);
komandi.FieldByName('nom_st').
stadioni.Locate('naim_st', Combobox2.Text, [loCaseInsensitive,
loPartialKey]);
komandi.FieldByName('nom_stad'
komandi.Append;
komandi.Refresh;
kdr:=0;
form5.komandi.Refresh;
form6.Close;
end;
a2:=0;
if kdr=2 then begin //режим редактирования клуба
if dbedit1.text='' then a2:=1;
if dbedit2.text='' then a2:=1;
if dbedit3.text='' then a2:=1;
if dbedit4.text='' then a2:=1;
if dbedit5.text='' then a2:=1;
if dbedit6.text='' then a2:=1;
if dbedit7.text='' then a2:=1;
if dbedit8.text='' then a2:=1;
if combobox1.text='' then a2:=1;
if combobox1.text='' then a2:=1;
if a2=1 then begin showmessage('Есть пустые поля'); exit; end;
komandi.Edit;
strani.Locate('naim_str', Combobox1.Text, [loCaseInsensitive,
loPartialKey]);
komandi.FieldByName('nom_st').
stadioni.Locate('naim_st', Combobox2.Text, [loCaseInsensitive,
loPartialKey]);
komandi.FieldByName('nom_stad'
komandi.Append;
komandi.Refresh;
kdr:=0;
form5.komandi.Refresh;
form6.Close;
end;
end;
procedure TForm6.Button2Click(Sender: TObject);
begin
komandi.Cancel;
if kdr=1 then komandi.Delete;
form6.Close;
end;
procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form6.Caption:='Добавление команды';
if kdr=1 then komandi.Delete;
end;
end.
Текст модуля stadioni.pas
unit stadioni;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, gl_per, StdCtrls, Mask, DBCtrls, DB, DBTables, Buttons;
type
TForm7 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Label5: TLabel;
Edit1: TEdit;
Button9: TButton;
BitBtn1: TBitBtn;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
a:byte;
implementation
{$R *.dfm}
procedure TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
gp4:=1;
end;
procedure TForm7.Button1Click(Sender: TObject);
begin
table1.Prior;
end;
procedure TForm7.Button2Click(Sender: TObject);
begin
table1.next;
end;
procedure TForm7.Button3Click(Sender: TObject);
begin
table1.First;
end;
procedure TForm7.Button4Click(Sender: TObject);
begin
table1.Last;
end;
procedure TForm7.FormCreate(Sender: TObject);
begin
a:=0;
end;
procedure TForm7.Button5Click(Sender: TObject);
var
r:integer;
begin
a:=1; //добавление
table1.Last;
r:=table1.fieldbyname('nom_
table1.Insert;
table1.fieldbyname('nom_stad')
button1.Enabled:=false;
button2.Enabled:=false;
button3.Enabled:=false;
button4.Enabled:=false;
button6.Enabled:=false;
button5.Enabled:=false;
button8.Enabled:=true;
dbedit2.ReadOnly:=false;
dbedit3.ReadOnly:=false;
dbedit4.ReadOnly:=false;
end;
procedure TForm7.Button8Click(Sender: TObject);
var
a1:byte;
begin
a1:=0;
if a=1 then begin //добавление
if dbedit2.text='' then a1:=1;
if dbedit3.text='' then a1:=1;
if dbedit4.text='' then a1:=1;
if a1=1 then begin showmessage('Есть пустые поля'); exit; end;
table1.Append;
table1.Refresh;
end;
if a=2 then begin //редактирование
table1.Append;
table1.Refresh;
end;
button1.Enabled:=true;
button2.Enabled:=true;
button3.Enabled:=true;
button4.Enabled:=true;
button6.Enabled:=true;
button5.Enabled:=true;
button8.Enabled:=false;
dbedit2.ReadOnly:=true;
dbedit3.ReadOnly:=true;
dbedit4.ReadOnly:=true;
end;
procedure TForm7.FormActivate(Sender: TObject);
begin
button8.Enabled:=false;
bitbtn1.Caption:='';
end;
procedure TForm7.Button6Click(Sender: TObject);
begin
a:=2; //редактирование
table1.Edit;
button1.Enabled:=false;
button2.Enabled:=false;
button3.Enabled:=false;
button4.Enabled:=false;
button5.Enabled:=false;
button6.Enabled:=false;
button8.Enabled:=true;
dbedit2.ReadOnly:=false;
dbedit3.ReadOnly:=false;
dbedit4.ReadOnly:=false;
end;
procedure TForm7.Button7Click(Sender: TObject);
begin
if application.MessageBox('Вы
mb_iconQuestion+mb_yesno)=
table1.delete;
end;
procedure TForm7.Button9Click(Sender: TObject);
begin
if edit1.text='' then exit;
if not table1.Locate('naim_st', Edit1.Text, [loCaseInsensitive,
loPartialKey]) then
ShowMessage('Запись не найдена');
end;
procedure TForm7.BitBtn1Click(Sender: TObject);
begin
edit1.text:='';
edit1.SetFocus;
end;
end.
Текст модуля transfer.pas
unit transfer;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, gl_per, DB, DBTables, Grids, DBGrids, StdCtrls, ComCtrls, Spin,
ExtCtrls, Buttons;
type
TForm8 = class(TForm)
igroki: TTable;
komandi: TTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
DataSource3: TDataSource;
Label1: TLabel;
Label2: TLabel;
perehodi: TTable;
DBGrid1: TDBGrid;
Label3: TLabel;
Edit1: TEdit;
Button1: TButton;
Label4: TLabel;
Edit2: TEdit;
Label5: TLabel;
ComboBox1: TComboBox;
Label6: TLabel;
DateTimePicker1: TDateTimePicker;
SpinEdit1: TSpinEdit;
Label7: TLabel;
Button2: TButton;
Timer1: TTimer;
ComboBox2: TComboBox;
BitBtn1: TBitBtn;
Label8: TLabel;
Edit3: TEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form8: TForm8;
tkl,nkl:integer;
implementation
{$R *.dfm}
procedure new_klyb;
begin
form8.komandi.First;
form8.ComboBox1.Clear;
while not form8.komandi.Eof do
begin
form8.ComboBox1.Items.Add(
form8.komandi.next;
end;
end;
procedure tek_klyb;
var
a:integer;
begin
a:=form8.igroki.fieldbyname('
form8.komandi.Locate('nom_kom'
loPartialKey]);
form8.edit2.text:=form8.
tkl:=Form8.komandi.
end;
procedure tek_igr;
var
s:string;
begin
s:=form8.igroki.fieldbyname('
form8.igroki.fieldbyname('ima'
form8.igroki.fieldbyname('
form8.edit3.text:=s;
end;
procedure TForm8.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
gp5:=1;
end;
procedure TForm8.Button3Click(Sender: TObject);
begin
tek_klyb;
end;
procedure TForm8.Timer1Timer(Sender: TObject);
begin
new_klyb;
tek_klyb;
tek_igr;
timer1.Enabled:=false;
end;
procedure TForm8.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
tek_klyb;
tek_igr;
end;
procedure TForm8.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
tek_klyb;
tek_igr;
end;
procedure TForm8.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
tek_klyb;
tek_igr;
end;
procedure TForm8.Button2Click(Sender: TObject);
var
s:string;
a:byte;
begin
a:=0;
s:=combobox1.Text;
komandi.Locate('naim', s , [loCaseInsensitive,
loPartialKey]);
nkl:=komandi.fieldbyname('nom_
if edit2.text='' then a:=1;
if combobox1.text='' then a:=1;
if a=1 then begin showmessage('Введены не все данные'); exit; end;
if edit2.text=combobox1.Text then begin
showmessage('Трансфер невозможен. Новый и текущий клубы совпадают!');
exit;
end;
if spinedit1.Value<100 then begin
showmessage(‘Сумма трансфера слишком мала! Такого не может быть!!!');
exit;
end;
perehodi.Insert;
perehodi.FieldByName('nom_igr'
perehodi.FieldByName('st_nom_
perehodi.FieldByName('nw_nom_
perehodi.FieldByName('dat_per'
perehodi.FieldByName('sym').
perehodi.Append;
perehodi.Refresh;
igroki.Edit;
igroki.FieldByName('nom_kom').
igroki.Append;
igroki.Refresh;
showmessage('Успешная операция!');
end;
procedure TForm8.ComboBox2KeyPress(
begin
key:=#0;
end;
procedure TForm8.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if combobox2.text='' then begin
showmessage('Выберите критерий поиска'); edit1.text:=''; exit; end;
if combobox2.text='по номеру' then begin
if not (Key in ['0'..'9',#8,#13]) then
Key := #0;
end;
end;
procedure TForm8.Button1Click(Sender: TObject);
begin
if edit1.text='' then begin showmessage('Нет информации для поиска');
exit; end;
if combobox2.text='по номеру' then begin
if not igroki.Locate('nom_igr', edit1.text , [loCaseInsensitive,
loPartialKey]) then showmessage('Запись не найдена');
end;
if combobox2.text='по фамилии' then begin
if not igroki.Locate('fam', edit1.text , [loCaseInsensitive,
loPartialKey]) then showmessage('Запись не найдена');
end;
end;
procedure TForm8.FormActivate(Sender: TObject);
begin
bitbtn1.Caption:='';
end;
procedure TForm8.BitBtn1Click(Sender: TObject);
begin
edit1.Clear;
end;
end.
Текст модуля ist_trans.pas
unit ist_trans;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, gl_per, DB, DBTables, StdCtrls, Grids, DBGrids, ExtCtrls, Spin;
type
TForm9 = class(TForm)
perehodi: TTable;
komandi: TTable;
igroki: TTable;
DataSource1: TDataSource;
DataSource2: TDataSource;
DataSource3: TDataSource;
Label1: TLabel;
vspom: TTable;
DataSource4: TDataSource;
DBGrid1: TDBGrid;
Timer1: TTimer;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit2: TEdit;
Button4: TButton;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Label4: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Label5: TLabel;
Label6: TLabel;
Button5: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
Button3: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form9: TForm9;
implementation
{$R *.dfm}
procedure zap_vspom;
var
a1,a2,a3:integer;
s,s1,s2:string;
begin
form9.vspom.First;
while not form9.vspom.Eof do
begin
form9.vspom.Next;
form9.vspom.Delete;
end;
form9.perehodi.First;
while not form9.perehodi.eof do
begin
form9.vspom.insert;
s:='';
a1:=form9.perehodi.
form9.igroki.Locate('nom_igr', a1 , [loCaseInsensitive,
loPartialKey]);
s:=form9.igroki.fieldbyname('
+form9.igroki.fieldbyname('
form9.vspom.FieldByName('
a2:=form9.perehodi.
form9.komandi.Locate('nom_kom'
loPartialKey]);
s1:=form9.komandi.fieldbyname(
form9.vspom.FieldByName('s_kl'
a3:=form9.perehodi.