Текстовая таблица. Нид хелп.
Добавлено: 04 май 2009, 16:31
Собстно имеем базу данных построенную на текстовых файлах.
сейчас там работает только добавление и вывод инфы в таблицы.
ищу помощи в:
сделать удаление выбранной строки
сделать удаление по какому - либо критерию
поиск по критерию
сортировка по критериям
файл с базой прикладываю
пока только работаю с цифрами в полях =)
Сам код
[syntax='delphi']
type Tshifr=record
god:integer;
nom:integer;
end;
Tbenz=record
fam:string[15];
spc:string[15];
shf:Tshifr;
srb:real;
end;
Tusl=record
fam1:string[15];
spc1:string[15];
shf1:Tshifr;
srb1:real;
end;
var
Form1: TForm1;
sp:array[1..50]of Tbenz;
sp1:array[1..50] of Tusl;
n:integer;
f:file of Tbenz;
f1:file of Tusl;
f3:file of Tbenz;
implementation
{$R *.dfm}
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8 : ;
else key := Chr(0);
end;
end;
procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8 : ;
else key := Chr(0);
end;
end;
procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8,',' : ;
else key := Chr(0);
end;
end;
//Ñîçäàåì ôàéë è òàáëèöû
procedure TForm1.FormActivate(Sender: TObject);
begin
assignfile(f,'benz.txt');
assignfile(f1,'usl.txt');
rewrite(f);
rewrite(f1);
n:=0;
StringGrid1.ColCount:=6;
StringGrid1.Cells[1,0]:='Марка';
StringGrid1.Cells[2,0]:='Цена';
StringGrid1.Cells[3,0]:='Остаток';
StringGrid1.Cells[4,0]:='Поставщик';
StringGrid1.Cells[5,0]:='Завезено';
StringGrid2.ColCount:=5;
StringGrid2.Cells[1,0]:='Марка';
StringGrid2.Cells[2,0]:='Кол-Во';
StringGrid2.Cells[3,0]:='Дата';
StringGrid2.Cells[4,0]:='Стоимость';
end;
//íàïîëíåíèå ôàéëà 1
procedure TForm1.Button1Click(Sender: TObject);
begin
n:=n+1;
sp[n].fam:=Edit1.Text;
Edit1.Text:='';
Edit2.SetFocus;
sp[n].spc:=Edit2.Text;
Edit2.Text:='';
Edit3.SetFocus;
sp[n].shf.god:=StrToInt(Edit3.Text);
Edit3.Text:='';
Edit4.SetFocus;
sp[n].shf.nom:=StrToInt(Edit4.Text);
Edit4.Text:='';
Edit5.SetFocus;
sp[n].srb:=StrToFloat(Edit5.Text);
Edit5.Text:='';
Edit1.SetFocus;
write(f,sp[n]);
end;
//2îé ôàéë
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
n:=n+1;
sp1[n].fam1:=Edit7.Text;
Edit7.Text:='';
Edit8.SetFocus;
sp1[n].spc1:=Edit8.Text;
Edit8.Text:='';
Edit9.SetFocus;
sp1[n].shf1.god:=StrToInt(Edit9.Text);
Edit9.Text:='';
Edit10.SetFocus;
sp1[n].shf1.nom:=StrToInt(Edit10.Text);
Edit10.Text:='';
Edit7.SetFocus;
write(f1,sp1[n]);
end;
//âûâîä äàííûõ â òàáëèöó 1
procedure TForm1.Button2Click(Sender: TObject);
var i,k:byte;
begin
assignfile(f,'benz.txt');
reset(f);
k:=0;
for i:=1 to n do
begin
StringGrid1.RowCount:=StringGrid1.RowCount+1; //äîáàâëÿåì ñòðî÷êó
read(f,sp);
StringGrid1.Cells[0,i]:=IntToStr(i);
StringGrid1.Cells[1,i]:=sp.fam;
StringGrid1.Cells[4,i]:=sp.spc;
StringGrid1.Cells[3,i]:=IntToStr(sp.shf.god);
StringGrid1.Cells[2,i]:=IntToStr(sp.shf.nom);
StringGrid1.Cells[5,i]:=FloatToStrF(sp.srb,ffFixed,5,0);
end;
closefile(f);
end;
//2àÿ òàáëèöà
procedure TForm1.BitBtn3Click(Sender: TObject);
var i,k:byte;
begin
assignfile(f1,'usl.txt');
reset(f1);
k:=0;
for i:=1 to n do
begin
StringGrid2.RowCount:=StringGrid2.RowCount+1; //äîáàâëÿåì ñòðî÷êó
read(f1,sp1);
StringGrid2.Cells[0,i]:=IntToStr(i);
StringGrid2.Cells[1,i]:=sp1.fam1;
StringGrid2.Cells[4,i]:=sp1.spc1;
StringGrid2.Cells[3,i]:=IntToStr(sp1.shf1.god);
StringGrid2.Cells[2,i]:=IntToStr(sp1[i].shf1.nom);
StringGrid2.Cells[5,i]:=FloatToStrF(sp1[i].srb1,ffFixed,5,0);
end;
closefile(f1);
end;
end.
[/syntax]
собстно потом буду связывать эти 2 файла меж собой, чтоб стоимость, остаток считались автоматом и поля для ввода этих данных буду удалены.
сейчас там работает только добавление и вывод инфы в таблицы.
ищу помощи в:
сделать удаление выбранной строки
сделать удаление по какому - либо критерию
поиск по критерию
сортировка по критериям
файл с базой прикладываю
пока только работаю с цифрами в полях =)
Сам код
[syntax='delphi']
type Tshifr=record
god:integer;
nom:integer;
end;
Tbenz=record
fam:string[15];
spc:string[15];
shf:Tshifr;
srb:real;
end;
Tusl=record
fam1:string[15];
spc1:string[15];
shf1:Tshifr;
srb1:real;
end;
var
Form1: TForm1;
sp:array[1..50]of Tbenz;
sp1:array[1..50] of Tusl;
n:integer;
f:file of Tbenz;
f1:file of Tusl;
f3:file of Tbenz;
implementation
{$R *.dfm}
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8 : ;
else key := Chr(0);
end;
end;
procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8 : ;
else key := Chr(0);
end;
end;
procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
'0'..'9',#8,',' : ;
else key := Chr(0);
end;
end;
//Ñîçäàåì ôàéë è òàáëèöû
procedure TForm1.FormActivate(Sender: TObject);
begin
assignfile(f,'benz.txt');
assignfile(f1,'usl.txt');
rewrite(f);
rewrite(f1);
n:=0;
StringGrid1.ColCount:=6;
StringGrid1.Cells[1,0]:='Марка';
StringGrid1.Cells[2,0]:='Цена';
StringGrid1.Cells[3,0]:='Остаток';
StringGrid1.Cells[4,0]:='Поставщик';
StringGrid1.Cells[5,0]:='Завезено';
StringGrid2.ColCount:=5;
StringGrid2.Cells[1,0]:='Марка';
StringGrid2.Cells[2,0]:='Кол-Во';
StringGrid2.Cells[3,0]:='Дата';
StringGrid2.Cells[4,0]:='Стоимость';
end;
//íàïîëíåíèå ôàéëà 1
procedure TForm1.Button1Click(Sender: TObject);
begin
n:=n+1;
sp[n].fam:=Edit1.Text;
Edit1.Text:='';
Edit2.SetFocus;
sp[n].spc:=Edit2.Text;
Edit2.Text:='';
Edit3.SetFocus;
sp[n].shf.god:=StrToInt(Edit3.Text);
Edit3.Text:='';
Edit4.SetFocus;
sp[n].shf.nom:=StrToInt(Edit4.Text);
Edit4.Text:='';
Edit5.SetFocus;
sp[n].srb:=StrToFloat(Edit5.Text);
Edit5.Text:='';
Edit1.SetFocus;
write(f,sp[n]);
end;
//2îé ôàéë
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
n:=n+1;
sp1[n].fam1:=Edit7.Text;
Edit7.Text:='';
Edit8.SetFocus;
sp1[n].spc1:=Edit8.Text;
Edit8.Text:='';
Edit9.SetFocus;
sp1[n].shf1.god:=StrToInt(Edit9.Text);
Edit9.Text:='';
Edit10.SetFocus;
sp1[n].shf1.nom:=StrToInt(Edit10.Text);
Edit10.Text:='';
Edit7.SetFocus;
write(f1,sp1[n]);
end;
//âûâîä äàííûõ â òàáëèöó 1
procedure TForm1.Button2Click(Sender: TObject);
var i,k:byte;
begin
assignfile(f,'benz.txt');
reset(f);
k:=0;
for i:=1 to n do
begin
StringGrid1.RowCount:=StringGrid1.RowCount+1; //äîáàâëÿåì ñòðî÷êó
read(f,sp);
StringGrid1.Cells[0,i]:=IntToStr(i);
StringGrid1.Cells[1,i]:=sp.fam;
StringGrid1.Cells[4,i]:=sp.spc;
StringGrid1.Cells[3,i]:=IntToStr(sp.shf.god);
StringGrid1.Cells[2,i]:=IntToStr(sp.shf.nom);
StringGrid1.Cells[5,i]:=FloatToStrF(sp.srb,ffFixed,5,0);
end;
closefile(f);
end;
//2àÿ òàáëèöà
procedure TForm1.BitBtn3Click(Sender: TObject);
var i,k:byte;
begin
assignfile(f1,'usl.txt');
reset(f1);
k:=0;
for i:=1 to n do
begin
StringGrid2.RowCount:=StringGrid2.RowCount+1; //äîáàâëÿåì ñòðî÷êó
read(f1,sp1);
StringGrid2.Cells[0,i]:=IntToStr(i);
StringGrid2.Cells[1,i]:=sp1.fam1;
StringGrid2.Cells[4,i]:=sp1.spc1;
StringGrid2.Cells[3,i]:=IntToStr(sp1.shf1.god);
StringGrid2.Cells[2,i]:=IntToStr(sp1[i].shf1.nom);
StringGrid2.Cells[5,i]:=FloatToStrF(sp1[i].srb1,ffFixed,5,0);
end;
closefile(f1);
end;
end.
[/syntax]
собстно потом буду связывать эти 2 файла меж собой, чтоб стоимость, остаток считались автоматом и поля для ввода этих данных буду удалены.