Piszę program, który ma służyć za dziennik lekcyjny. Oceny, sprawdzanie obecności, uwagi i ma mieć zakładkę dla każdego przedmiotu,wczytuje i zapisuje,czyści wszystkie komórki,dodaje i usuwa zakładki. Jednak utknąłem i nie wiem co robić mam problem z zapisaniem pagecontrol stringgrida do pliku, odczytaniem tego i działaniem klawiszy na otwartych zakładkach.
Oto kod
unit dziennikLekcyjnyGP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ComCtrls, TabNotBk, Grids, ExtCtrls, Tabs, ExtDlgs,ShellAPI;
type
TForm1 = class(TForm)
MainMenu: TMainMenu;
StringGrid1: TStringGrid;
Plik1: TMenuItem;
Koniec2: TMenuItem;
Nowy1: TMenuItem;
Open: TOpenTextFileDialog;
Save: TSaveTextFileDialog;
Zapisz1: TMenuItem;
Wczytaj1: TMenuItem;
Obecnosc1: TMenuItem;
Srednia1: TMenuItem;
PageControl1: TPageControl;
Dodajzak1: TMenuItem;
Zamknijzak1: TMenuItem;
Edit1: TEdit;
procedure Koniec2Click(Sender: TObject);
procedure Wczytaj1Click(Sender: TObject);
procedure Zapisz1Click(Sender: TObject);
procedure Nowy1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Dodajzak1Click(Sender: TObject);
procedure Zamknijzak1Click(Sender: TObject);
procedure Srednia1Click(Sender: TObject);
procedure Obecnosc1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
StringGrid:TStringGrid;
implementation
{$R *.dfm}
procedure wypelnij_tabele(var s:TstringGrid); //przypisuje nazwy do komurek
var i:integer;
begin
with s do begin
Cells[1,0]:='Imie';
Cells[0,1]:='Daty lekcji';
Cells[2,0]:='Nazwisko';
Cells[3,0]:='Oceny';
Cells[12,0]:='Średnia';
Cells[13,0]:='Obecnosc';
Cells[33,0]:='Uwagi';
for i:=1 to 101 do
begin
Cells[13,i+1]:='Obecny';
Cells[14,i+1]:='Obecny';
Cells[15,i+1]:='Obecny';
Cells[16,i+1]:='Obecny';
Cells[17,i+1]:='Obecny';
Cells[18,i+1]:='Obecny';
Cells[19,i+1]:='Obecny';
Cells[20,i+1]:='Obecny';
Cells[21,i+1]:='Obecny';
Cells[22,i+1]:='Obecny';
Cells[23,i+1]:='Obecny';
Cells[24,i+1]:='Obecny';
Cells[25,i+1]:='Obecny';
Cells[26,i+1]:='Obecny';
Cells[27,i+1]:='Obecny';
Cells[28,i+1]:='Obecny';
Cells[29,i+1]:='Obecny';
Cells[30,i+1]:='Obecny';
Cells[31,i+1]:='Obecny';
Cells[32,i+1]:='Obecny';
end;
for i:=1 to 101 do
cells[0,i+1]:=IntToStr(i);
end
end;
procedure TForm1.Dodajzak1Click(Sender: TObject); //Dodaje zakladke
var
TabSheet: TTabSheet;
nazwa:string;
tab:string;
begin //Okienko z pyt o nazwe zakłądki i tworzy stringgrid w pagecontrol
Edit1.Text:=InputBox('Zakładki','Podaj nazwe zakłądki:','Tu wpisz nazwe zakładki');
nazwa:=(Edit1.Text);
TabSheet := TTabSheet.Create(PageControl1);
TabSheet.Caption := nazwa;
TabSheet.PageControl := PageControl1;
StringGrid := TStringGrid.Create (TabSheet);
StringGrid.ColCount := 50;
StringGrid.Align:=alClient;
StringGrid.ScrollBars:=ssBoth;
StringGrid.Options := StringGrid.Options + [goThumbTracking];
StringGrid.Options:= StringGrid.Options + [goEditing];
StringGrid.Options:= StringGrid.Options + [goFixedRowClick];
StringGrid.Options:= StringGrid.Options + [goFixedColClick];
StringGrid.Options:= StringGrid.Options + [goTabs];
StringGrid.Options:= StringGrid.Options + [goRowSizing];
StringGrid.Options:= StringGrid.Options + [goColSizing];
StringGrid.Parent := TabSheet;
wypelnij_tabele(StringGrid);
StringGrid.RowCount := 101;
StringGrid.Visible := True;
end;
procedure TForm1.FormCreate(Sender: TObject); //jest uzywana na onCreat i po nacisknieci nowy
begin //wywoluje procedure wypelnij_tabele
wypelnij_tabele(StringGrid1);
end;
procedure TForm1.Koniec2Click(Sender: TObject); //zamyka program
begin
Close;
end;
procedure TForm1.Nowy1Click(Sender: TObject); //czysni stringrid i wywoluje procedure wypelnij_tabele
var i : integer;
begin
PageControl1.ActivePage.TabIndex;
for i:=0 to stringgrid.ColCount do
begin
stringgrid.Cols[i].Clear;
end;
for i:=0 to stringgrid.RowCount do
begin
stringgrid.Rows[i].Clear;
end;
wypelnij_tabele(StringGrid);
end;
procedure TForm1.Obecnosc1Click(Sender: TObject); //wpisuje nieobennosc do komurki z wybramym nazwiskiem
var
nazwisko,data: String;
i:Integer;
begin
PageControl1.ActivePage.TabIndex;
Edit1.Text:=InputBox('Nie obecni','Podaj nazwisko nieobecnej osoby:','Nazwisko');
nazwisko:=(Edit1.Text);
Edit1.Text:=InputBox('Nie obecni','Podaj date nieobecnosci:','Data');
data:=(Edit1.Text);
for i:=1 to StringGrid.RowCount do
begin
if StringGrid.Cells[0,i+15]=data then
if StringGrid.Cells[2,i]=nazwisko then
begin
StringGrid.Row:=i;//zaznaczanie komorki w danym wierszy
StringGrid.Col:=1;//zaznaczanie komorki w danej kolumnie
StringGrid.Cells[13,i]:='Nie obecny';
end;
end;
end;
procedure TForm1.Srednia1Click(Sender: TObject); //oblicza srednia ocen
var
i:Integer;
A,B,C,D,E,F,G,H,J:real;
begin
PageControl1.ActivePage.TabIndex;
ShowMessage('Oblicza srednia dla 9 ocen');
for i:=1 to StringGrid.RowCount-1 do
begin
A:=StrTofloat(StringGrid.Cells[3,i]);
B:=StrTofloat(StringGrid.Cells[4,i]);
C:=StrTofloat(StringGrid.Cells[5,i]);
D:=StrTofloat(StringGrid.Cells[6,i]);
E:=StrTofloat(StringGrid.Cells[7,i]);
F:=StrTofloat(StringGrid.Cells[8,i]);
G:=StrTofloat(StringGrid.Cells[9,i]);
H:=StrTofloat(StringGrid.Cells[10,i]);
J:=StrTofloat(StringGrid.Cells[11,i]);
StringGrid.Cells[12,i]:=floatToStr((A+B+C+D+E+F+G+H+J)/9);
end;
end;
procedure TForm1.Wczytaj1Click(Sender: TObject); //wczytuje stringgrid po kolumn i wierszy
var
f:textfile;
temp,x,y:integer;
tempstr:string;
begin
if open.Execute then
begin
if FileExists(open.FileName) then
assignfile (f,open.filename);
reset (f);
readln (f,temp);
stringgrid1.colcount:=temp;
readln (f,temp);
stringgrid1.rowcount:=temp;
For X:=0 to stringgrid1.colcount-1 do
For y:=0 to stringgrid1.rowcount-1 do
begin
readln (F, tempstr);
stringgrid1.cells[x,y]:=tempstr;
end;
closefile (f);
end;
end;
procedure TForm1.Zamknijzak1Click(Sender: TObject); //usuwa zakłądke
begin
PageControl1.ActivePage.Free;
end;
procedure TForm1.Zapisz1Click(Sender: TObject); //zapisuje tekst z stringgrid to kol i wirszy
var
f:textfile;
x,y,i:integer;
Stringgrid:Tstringgrid;
begin
for i := 0 to PageControl1.ActivePage.ControlCount -1 do
if PageControl1.ActivePage.Controls[i] is TStringGrid then
begin
StringGrid := PageControl1.ActivePage.Controls[i] as TStringGrid;
PageControl1.ActivePage.Caption := Save.Filename;
end;
if Save.Execute then
assignfile (f,save.filename);
rewrite (f);
writeln (f,stringgrid1.colcount);
writeln (f,stringgrid1.rowcount);
For X:=0 to stringgrid1.colcount-1 do
For y:=0 to stringgrid1.rowcount-1 do
writeln (F, stringgrid1.cells[x,y]);
closefile (f);
end;
end.
dodanie znacznika <code class="delphi"> - fp
- dziennik.zip (486 KB) - ściągnięć: 151