Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
- StdCtrls, ComCtrls, DbCtrls, maskedit;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Usun: TButton;
- Edit6: TEdit;
- Losuj: TButton;
- Edit5: TEdit;
- Wczytaj: TButton;
- Zapisz: TButton;
- Cena: TLabel;
- ComboBox1: TComboBox;
- Edit2: TEdit;
- Edit4: TEdit;
- kolor: TLabel;
- Dodaj: TButton;
- Edit7: TEdit;
- GroupBox1: TGroupBox;
- Producent: TLabel;
- Edit1: TEdit;
- Edit3: TEdit;
- Faktura: TLabel;
- Ilosc_szt: TLabel;
- Model: TLabel;
- Nie: TCheckBox;
- tabelka: TStringGrid;
- Tak: TCheckBox;
- procedure ComboBox1Change(Sender: TObject);
- procedure DBText1Click(Sender: TObject);
- procedure DodajClick(Sender: TObject);
- procedure Edit6Change(Sender: TObject);
- procedure LosujClick(Sender: TObject);
- procedure MaskEdit2EditingDone(Sender: TObject);
- procedure UsunClick(Sender: TObject);
- procedure ZapiszClick(Sender: TObject);
- procedure WczytajClick(Sender: TObject);
- private
- { private declarations }
- public
- { public declarations }
- constructor Create(AOwner: TComponent); override; // optional
- constructor CreateWithDetail(AOwner: TComponent);
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- constructor TForm1.Create(AOwner: TComponent);
- begin
- CreateWithDetail(AOwner);
- tabelka.Cells[0,0] := 'LD';
- tabelka.Cells[1,0] := 'Model';
- tabelka.Cells[2,0] := 'Ilosc szt';
- tabelka.Cells[3,0] := 'Kolor';
- tabelka.Cells[4,0] := 'Cena';
- tabelka.Cells[5,0] := 'Faktura';
- tabelka.Cells[6,0] := 'Producent';
- tabelka.Cells[7,0] := 'Wystawial';
- tabelka.RowCount := 2;
- end;
- constructor TForm1.CreateWithDetail(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- end;
- procedure TForm1.DodajClick(Sender: TObject);
- var
- liczba: integer;
- i, idx:integer;
- begin
- if (length(edit1.text)<1 ) then exit;
- if (length(edit7.text)<1 ) then exit;
- if (length(edit3.text)<1 ) then exit;
- if (Tak.Checked = false and Nie.Checked = false) then exit;
- // if (length(Maskedit1.text)<1 ) then exit;
- if (length(Edit2.text)<1 ) then exit;
- if (length(Edit4.text)<1 ) then exit;
- try
- StrToInt(Edit4.Text);
- except ShowMessage('Podaj liczbe !'); exit;
- end;
- if tabelka.Cells[0, 1] <> '' then tabelka.RowCount:=tabelka.RowCount+1;
- tabelka.Cells[0, tabelka.RowCount-1] := IntToStr(tabelka.rowcount-1);
- tabelka.Cells[1, tabelka.RowCount-1]:= Edit1.Text;
- tabelka.Cells[4, tabelka.RowCount-1]:= edit2.text;
- tabelka.Cells[6, tabelka.RowCount-1]:= Edit3.Text;
- tabelka.Cells[7, tabelka.RowCount-1]:= Edit7.Text;
- tabelka.Cells[3, tabelka.RowCount-1]:= combobox1.Text;
- tabelka.Cells[2, tabelka.RowCount-1]:= edit4.Text;
- if (Nie.Checked) then tabelka.Cells[5,tabelka.RowCount-1] := 'Nie' else tabelka.Cells[5,tabelka.RowCount-1] := 'Tak';
- end;
- procedure TForm1.Edit6Change(Sender: TObject);
- begin
- end;
- procedure TForm1.LosujClick(Sender: TObject);
- begin
- end;
- procedure TForm1.MaskEdit2EditingDone(Sender: TObject);
- begin
- end;
- procedure TForm1.UsunClick(Sender: TObject);
- var
- i,j:word;
- znaleziono:integer;
- usun1: Ansistring;
- begin
- znaleziono := 0;
- for i:=1 to tabelka.RowCount do
- begin
- if (tabelka.Cells[0,i] = usun1) then begin znaleziono := 1; break; end;
- if (znaleziono = 0) then begin ShowMessage('Nie ma takiego elementu !'); exit; end;
- for j := i to tabelka.RowCount do
- begin
- tabelka.Rows[j] := tabelka.Rows[j+1];
- if (tabelka.RowCount > 2) then tabelka.RowCount:=tabelka.rowcount-1 else tabelka.Rows[tabelka.RowCount].Clear;
- end;
- end;
- end;
- procedure TForm1.WczytajClick(Sender: TObject);
- var tf:TextFile;
- x,y: integer;
- row,col:integer;
- tmp:longint;
- tmpStr:string;
- var tf:TextFile;
- tab:array[0..100] of string;
- i: integer;
- row,col:integer;
- begin
- i:= 0; row:= -1; col:= 0;
- if FileExists('C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt') then
- begin
- AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
- reset(tf);
- while not Eof(tf) do
- begin
- Readln(tf, tab[i]);
- if tab[col][1] = '#' then // jeżeli nowy rząd
- begin
- row:= row+1; // zwiększ licznik
- col:= 0;
- end else
- begin
- tabelka.Cells[col-1,row]:= tab[i];
- end;
- col:=col+1;
- i:=i+1;
- end; // while not eof
- closefile(tf);
- end
- else
- ShowMessage('Nie znalazłem pliku !');
- end;
- {
- begin
- if FileExists('C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt') then
- begin
- AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
- reset(tf);
- Readln(tf, Tmp);
- tabelka.ColCount:=Tmp;
- Readln(tf, Tmp);
- tabelka.RowCount:=Tmp ;
- while not Eof(tf) do
- for x:=0 to tabelka.ColCount-1 do
- for y:=0 to tabelka.RowCount-1 do
- begin
- Readln(tf, TmpStr);
- tabelka.Cells[x,y]:=TmpStr;
- end; // while not eof
- closefile(tf);
- end
- else
- ShowMessage('Nie znalazłem pliku !');
- end; }
- procedure TForm1.DBText1Click(Sender: TObject);
- begin
- end;
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- end;
- procedure TForm1.ZapiszClick(Sender: TObject);
- var tf:TextFile;
- c, cc :word;
- begin
- AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
- rewrite(tf);
- writeln(tf, '#');
- for c:=0 to tabelka.RowCount-1 do
- begin
- for cc:=0 to tabelka.ColCount-1 do
- if tabelka.Cells[cc, c] = '' then Writeln(tf, ' ') else
- Writeln(tf, tabelka.Cells[cc, c]);
- writeln(tf, '#');
- end;
- closefile(tf);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement