Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
  9. StdCtrls, ComCtrls, DbCtrls, maskedit;
  10.  
  11. type
  12.  
  13. { TForm1 }
  14.  
  15. TForm1 = class(TForm)
  16. Usun: TButton;
  17. Edit6: TEdit;
  18. Losuj: TButton;
  19. Edit5: TEdit;
  20. Wczytaj: TButton;
  21. Zapisz: TButton;
  22. Cena: TLabel;
  23. ComboBox1: TComboBox;
  24. Edit2: TEdit;
  25. Edit4: TEdit;
  26. kolor: TLabel;
  27. Dodaj: TButton;
  28. Edit7: TEdit;
  29. GroupBox1: TGroupBox;
  30. Producent: TLabel;
  31. Edit1: TEdit;
  32. Edit3: TEdit;
  33. Faktura: TLabel;
  34. Ilosc_szt: TLabel;
  35. Model: TLabel;
  36. Nie: TCheckBox;
  37. tabelka: TStringGrid;
  38. Tak: TCheckBox;
  39.  
  40. procedure ComboBox1Change(Sender: TObject);
  41. procedure DBText1Click(Sender: TObject);
  42. procedure DodajClick(Sender: TObject);
  43. procedure Edit6Change(Sender: TObject);
  44. procedure LosujClick(Sender: TObject);
  45. procedure MaskEdit2EditingDone(Sender: TObject);
  46. procedure UsunClick(Sender: TObject);
  47.  
  48. procedure ZapiszClick(Sender: TObject);
  49. procedure WczytajClick(Sender: TObject);
  50.  
  51.  
  52. private
  53. { private declarations }
  54. public
  55. { public declarations }
  56. constructor Create(AOwner: TComponent); override; // optional
  57. constructor CreateWithDetail(AOwner: TComponent);
  58.  
  59. end;
  60.  
  61. var
  62. Form1: TForm1;
  63.  
  64. implementation
  65.  
  66. {$R *.lfm}
  67.  
  68. { TForm1 }
  69.  
  70.  
  71. constructor TForm1.Create(AOwner: TComponent);
  72. begin
  73. CreateWithDetail(AOwner);
  74. tabelka.Cells[0,0] := 'LD';
  75. tabelka.Cells[1,0] := 'Model';
  76. tabelka.Cells[2,0] := 'Ilosc szt';
  77. tabelka.Cells[3,0] := 'Kolor';
  78. tabelka.Cells[4,0] := 'Cena';
  79. tabelka.Cells[5,0] := 'Faktura';
  80. tabelka.Cells[6,0] := 'Producent';
  81. tabelka.Cells[7,0] := 'Wystawial';
  82. tabelka.RowCount := 2;
  83. end;
  84.  
  85. constructor TForm1.CreateWithDetail(AOwner: TComponent);
  86. begin
  87. inherited Create(AOwner);
  88. end;
  89.  
  90.  
  91. procedure TForm1.DodajClick(Sender: TObject);
  92. var
  93. liczba: integer;
  94. i, idx:integer;
  95. begin
  96. if (length(edit1.text)<1 ) then exit;
  97. if (length(edit7.text)<1 ) then exit;
  98. if (length(edit3.text)<1 ) then exit;
  99.  
  100.  
  101. if (Tak.Checked = false and Nie.Checked = false) then exit;
  102. // if (length(Maskedit1.text)<1 ) then exit;
  103. if (length(Edit2.text)<1 ) then exit;
  104.  
  105.  
  106. if (length(Edit4.text)<1 ) then exit;
  107. try
  108. StrToInt(Edit4.Text);
  109. except ShowMessage('Podaj liczbe !'); exit;
  110. end;
  111. if tabelka.Cells[0, 1] <> '' then tabelka.RowCount:=tabelka.RowCount+1;
  112. tabelka.Cells[0, tabelka.RowCount-1] := IntToStr(tabelka.rowcount-1);
  113. tabelka.Cells[1, tabelka.RowCount-1]:= Edit1.Text;
  114. tabelka.Cells[4, tabelka.RowCount-1]:= edit2.text;
  115. tabelka.Cells[6, tabelka.RowCount-1]:= Edit3.Text;
  116. tabelka.Cells[7, tabelka.RowCount-1]:= Edit7.Text;
  117. tabelka.Cells[3, tabelka.RowCount-1]:= combobox1.Text;
  118. tabelka.Cells[2, tabelka.RowCount-1]:= edit4.Text;
  119. if (Nie.Checked) then tabelka.Cells[5,tabelka.RowCount-1] := 'Nie' else tabelka.Cells[5,tabelka.RowCount-1] := 'Tak';
  120.  
  121. end;
  122.  
  123. procedure TForm1.Edit6Change(Sender: TObject);
  124. begin
  125.  
  126. end;
  127.  
  128. procedure TForm1.LosujClick(Sender: TObject);
  129. begin
  130.  
  131.  
  132. end;
  133.  
  134. procedure TForm1.MaskEdit2EditingDone(Sender: TObject);
  135. begin
  136.  
  137. end;
  138.  
  139. procedure TForm1.UsunClick(Sender: TObject);
  140. var
  141. i,j:word;
  142. znaleziono:integer;
  143. usun1: Ansistring;
  144. begin
  145. znaleziono := 0;
  146. for i:=1 to tabelka.RowCount do
  147. begin
  148. if (tabelka.Cells[0,i] = usun1) then begin znaleziono := 1; break; end;
  149.  
  150. if (znaleziono = 0) then begin ShowMessage('Nie ma takiego elementu !'); exit; end;
  151.  
  152. for j := i to tabelka.RowCount do
  153. begin
  154. tabelka.Rows[j] := tabelka.Rows[j+1];
  155.  
  156. if (tabelka.RowCount > 2) then tabelka.RowCount:=tabelka.rowcount-1 else tabelka.Rows[tabelka.RowCount].Clear;
  157.  
  158. end;
  159. end;
  160.  
  161. end;
  162.  
  163.  
  164.  
  165. procedure TForm1.WczytajClick(Sender: TObject);
  166.  
  167. var tf:TextFile;
  168. x,y: integer;
  169. row,col:integer;
  170. tmp:longint;
  171. tmpStr:string;
  172.  
  173. var tf:TextFile;
  174. tab:array[0..100] of string;
  175. i: integer;
  176. row,col:integer;
  177.  
  178. begin
  179. i:= 0; row:= -1; col:= 0;
  180. if FileExists('C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt') then
  181. begin
  182. AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
  183. reset(tf);
  184.  
  185. while not Eof(tf) do
  186. begin
  187. Readln(tf, tab[i]);
  188. if tab[col][1] = '#' then // jeżeli nowy rząd
  189. begin
  190. row:= row+1; // zwiększ licznik
  191. col:= 0;
  192. end else
  193. begin
  194. tabelka.Cells[col-1,row]:= tab[i];
  195. end;
  196. col:=col+1;
  197. i:=i+1;
  198. end; // while not eof
  199. closefile(tf);
  200. end
  201. else
  202. ShowMessage('Nie znalazłem pliku !');
  203.  
  204. end;
  205. {
  206. begin
  207.  
  208. if FileExists('C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt') then
  209. begin
  210. AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
  211. reset(tf);
  212.  
  213. Readln(tf, Tmp);
  214. tabelka.ColCount:=Tmp;
  215. Readln(tf, Tmp);
  216. tabelka.RowCount:=Tmp ;
  217. while not Eof(tf) do
  218.  
  219. for x:=0 to tabelka.ColCount-1 do
  220. for y:=0 to tabelka.RowCount-1 do
  221. begin
  222. Readln(tf, TmpStr);
  223. tabelka.Cells[x,y]:=TmpStr;
  224.  
  225. end; // while not eof
  226. closefile(tf);
  227. end
  228. else
  229. ShowMessage('Nie znalazłem pliku !');
  230.  
  231. end; }
  232.  
  233.  
  234. procedure TForm1.DBText1Click(Sender: TObject);
  235. begin
  236.  
  237. end;
  238.  
  239. procedure TForm1.ComboBox1Change(Sender: TObject);
  240. begin
  241.  
  242.  
  243. end;
  244.  
  245. procedure TForm1.ZapiszClick(Sender: TObject);
  246.  
  247. var tf:TextFile;
  248. c, cc :word;
  249. begin
  250. AssignFile(tf,'C:\Users\qompaq\Desktop\Algorytmy\ZDinf\projekt_baz\Plik.txt');
  251. rewrite(tf);
  252. writeln(tf, '#');
  253. for c:=0 to tabelka.RowCount-1 do
  254. begin
  255. for cc:=0 to tabelka.ColCount-1 do
  256. if tabelka.Cells[cc, c] = '' then Writeln(tf, ' ') else
  257. Writeln(tf, tabelka.Cells[cc, c]);
  258. writeln(tf, '#');
  259. end;
  260. closefile(tf);
  261. end;
  262.  
  263. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement