Создание базы данных "Wc3 Cybersport Data Base"
Курсовой проект - Компьютеры, программирование
Другие курсовые по предмету Компьютеры, программирование
.Карпова Базы данных: модели, разработка, реализация. Уч. пособие СПб: Питер,2001.
Приложение А Листинг программы
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, ExtCtrls, ComCtrls, DBCtrls, Menus,
StdCtrls, Inifiles;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
Players: TDBGrid;
DBNavigator1: TDBNavigator;
ADOTable2: TADOTable;
ADOTable3: TADOTable;
DataSource2: TDataSource;
DataSource3: TDataSource;
Events: TDBGrid;
Clans: TDBGrid;
MyQuery1: TADOQuery;
DataSource4: TDataSource;
TabSheet4: TTabSheet;
ListBox1: TListBox;
DBGrid1: TDBGrid;
StatusBar1: TStatusBar;
Button1: TButton;
PopupMenu1: TPopupMenu;
NewQuery1: TMenuItem;
Deletequery1: TMenuItem;
EditQuery1: TMenuItem;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
Label2: TLabel;
RichEdit1: TRichEdit;
CheckBox1: TCheckBox;
MyQuery2: TADOQuery;
DataSource5: TDataSource;
ADOTable1Nickname: TStringField;
ADOTable1Clan: TStringField;
ADOTable1GameRace: TStringField;
ADOTable1FullName: TStringField;
ADOTable1Age: TBCDField;
ADOTable1Country: TStringField;
ADOTable2Name: TStringField;
ADOTable2FullName: TStringField;
ADOTable2Owner: TStringField;
ADOTable2Players: TBCDField;
ADOTable2Sponsor: TStringField;
ADOTable2FoundationDate: TBCDField;
ADOTable3Name: TStringField;
ADOTable3Sponsor: TStringField;
ADOTable3Prize: TBCDField;
ADOTable3Clanwinner: TStringField;
ADOTable3Playerwinner: TStringField;
ADOTable3Date: TDateTimeField;
PopupMenu2: TPopupMenu;
Report1: TMenuItem;
Button3: TButton;
Button4: TButton;
Procedure NewEditDelete(i:integer);
procedure NewQuery(Name:string; Query : Trichedit;Dodelete:integer);
procedure PageControl1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure NewQuery1Click(Sender: TObject);
procedure Deletequery1Click(Sender: TObject);
procedure EditQuery1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure RichEdit1Change(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
Procedure Normalize(Grid:TDBGrid; Source:TDatasource);
procedure Report1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Name : string;
end;
var
Form1: TForm1;
ini :Tinifile;
implementation
uses Unit2;
{$R *.dfm}
Procedure TForm1.Normalize(Grid:TDBGrid; Source:TDatasource);
var
x:integer;
i:integer;
Begin
// ----------- Normalizing Column Width of DBGrid -----------
For x:=0 to grid.Columns.Count-1 do begin
i:=0;
source.DataSet.First;
repeat
itheni:=length(source.DataSet.Fields[x].Text);">if length(source.DataSet.Fields[x].Text)>i then i:=length(source.DataSet.Fields[x].Text);
source.DataSet.next;
until source.DataSet.Eof;
grid.Columns.Items[x].Width:= i+25;
end;
source.DataSet.First;
end;
Procedure TForm1.NewQuery(Name:string; Query :Trichedit; Dodelete : integer);
// DoDelete = 0 - Add or Edit
// DoDelete = 1 - Delete Query
Var
F : TextFile;
i : Integer;
x : Integer;
begin
AssignFile(F,Extractfilepath(Application.ExeName)+QueryList.lst);
Rewrite(F);
case DoDelete of
0 : Begin
ini.WriteString(Name,0,inttostr(richedit1.Lines.Count));
For i:=0 to query.Lines.Count-1 do begin
ini.WriteString(Name,inttostr(i+1),Query.Lines.Strings[i]);
end;
end;
1 : ini.EraseSection(Name);
end;
For x:=0 to Listbox1.Items.Count-1 do begin
Writeln(F,Listbox1.items.strings[x]);
end;
CloseFile(F);
end;
Procedure TForm1.NewEditDelete(i:integer);
// I = 1 - Add Query
// I = 2 - Edit Query
// I = 3 - Delete Query
var
Del:string;
x:integer;
Label 1;
begin
case i of
1 : begin
Listbox1.Items.Add(edit1.Text);
NewQuery(Edit1.Text,richedit1,0);
end;
2 : Begin
For x:=0 to listbox1.Items.Count-1 do begin
If Listbox1.Selected[x] then Listbox1.Items.Strings[x]:=Edit1.Text;
end;
NewQuery(Edit1.Text,richedit1,0);
end;
3 : Begin
For x:=0 to listbox1.Items.Count-1 do begin
If Listbox1.Selected[x] then begin
Del := Listbox1.items.Strings[x];
Listbox1.DeleteSelected;
Goto 1;
end;
end;
1: NewQuery(Del,richedit1,1);
end;
end;
end;
procedure TForm1.PageControl1Change(Sender: TObject);
begin
If Pagecontrol1.ActivePage=TabSheet1 then DBNavigator1.DataSource:=DataSource1;
If Pagecontrol1.ActivePage=TabSheet2 then DBNavigator1.DataSource:=DataSource2;
If Pagecontrol1.ActivePage=TabSheet3 then DBNavigator1.DataSource:=DataSource3;
If Pagecontrol1.ActivePage=TabSheet4 then DBNavigator1.DataSource:=DataSource4;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
F2:TextFile;
i,x:integer;
s:string;
begin
AdoTable1.Active:=true;
AdoTable2.Active:=true;
AdoTable3.Active:=true;
// ----------- Normalizing Column Width of DBGrid -----------
Normalize(players,datasource1);
Normalize(clans,datasource2);
Normalize(events,datasource3);
ini := TiniFile.Create(extractfilepath(application.ExeName)+Queryes.ini);
AssignFile(F2,Extractfilepath(Application.ExeName)+QueryList.lst);
reset(F2);
Repeat
Readln(F2,s);
Listbox1.Items.Add(s);
until EOF(F2);
closefile(F2);
If Pagecontrol1.ActivePage=TabSheet1 then DBNavigator1.DataSource:=DataSource1;
If Pagecontrol1.ActivePage=TabSheet2 then DBNavigator1.DataSource:=DataSource2;
If Pagecontrol1.ActivePage=TabSheet3 then DBNavigator1.DataSource:=DataSource3;
If Pagecontrol1.ActivePage=TabSheet4 then DBNavigator1.DataSource:=DataSource4;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x :integer;
begin
statusbar1.SimpleText:=Adding new Query...;
Edit1.Text:=;
Richedit1.Text:=;
Button2.Caption:=Add;
for x:=125 to form1.Width+120 do begin
DBGrid1.Left:=DbGrid1.Left+1;
Application.ProcessMessages;
end;
end;
procedure TForm1.NewQuery1Click(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm1.Deletequery1Click(Sender: TObject);
begin
NewEditDelete(3);
statusbar1.SimpleText:=Deleted...;
end;
procedure TForm1.EditQuery1Click(Sender: TObject);
var
x,i :integer;
begin
richedit1.Clear;
Button2.Caption:=Edit;
For x:=0 to listbox1.Items.Count-1 do begin
If listbox1.Selected[x] then begin
Edit1.Text:=Listbox1.Items.Strings[x];
statusbar1.SimpleText:=Modifying +edit1.Text+ Query...;
For i:=0 to strtoint(ini.ReadString(Listbox1.Items.Strings[x],0,))-1 do
begin
richedit1.Lines.add(ini.ReadString(Listbox1.Items.Strings[x],inttostr(i+1),));
end;
end;
end;
for x:=125 to form1.Width+120 do begin
DBGrid1.Left:=DbGrid1.Left+1;
Application.ProcessMessages;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Ini.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
x:integer;
begin
If Button2.Caption=Add then
begin
for x:=0 to listbox1.Items.Count-1 do begin
if edit1.Text=listbox1.Items.Strings[x] then begin
messagedlg(