-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit3.~cpp
106 lines (85 loc) · 2.87 KB
/
Unit3.~cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit1.h" // ìîäóëü ãîëîâíî¿ ïðîãðàìè
#include "Unit3.h" // ìîäóëü, ùî ì³ñòèòü êëàñè
//---------------------------------------------------------------------------
#pragma package(smart_init)
void TPizza::getdata(AnsiString& a1,AnsiString& a2,AnsiString& a3) //îòðèìóº äàí³
{
strncpy(name,a1.c_str(),50);
weight=StrToInt(a2);
amount=1;
price=StrToInt(a3);
};
//---------------------------------------------------------------------------
void TPizza::ShowError(TEdit& foc) //âèâîäèòü ïîìèëêó ïðè ðåäàãóâàíí³
{
if (Application->MessageBox("Çàïîâí³òü áóäü ëàñêà óñ³ ïîëÿ",
"Ïîìèëêà",MB_OK)==IDOK);
foc.SetFocus();
}
void TPizza::diskRead(int pn) //â³äêðèâຠ³ñíóþ÷èé ôàéë äëÿ ÷èòàííÿ
{
ifstream infile;
infile.open("Pizza.dat",ios::binary);
infile.seekg(pn*sizeof(TPizza));
infile.read((char*)this,sizeof(*this));
};
//---------------------------------------------------------------------------
void TPizza::diskWrite() //â³äêðèòòÿ ôàéëó â ðåæèì³ äîäàâàííÿ â ê³íåöü
{
ofstream outfile;
outfile.open("Pizza.dat",ios::app|ios::binary);
outfile.write((char*)this,sizeof(*this));
};
//---------------------------------------------------------------------------
void TPizza::diskDel() //âèäàëÿº äàí³ ³ç ôàéëó ÿêùî â³í ³ñíóº
{
ofstream outfile;
outfile.open("Pizza.dat",ios::trunc|ios::binary);
outfile.write((char*)this,sizeof(*this));
};
//---------------------------------------------------------------------------
int TPizza::diskCount() //ïîâåðòຠê³ëüê³ñòü åëåìåíò³â ó ôàéë³
{
TPizza per;
ifstream infile;
infile.open("Pizza.dat",ios::binary);
infile.seekg(0,ios::end);
return(int)(infile.tellg()/64);
};
//---------------------------------------------------------------------------
void TViewEvent::ShowData(TStringGrid& tr,int n) //çàïîâíþº òàáëèöþ äàíèìè
{number=n;
tr.Cells[0][n]=IntToStr(number);
tr.Cells[1][n]=name;
tr.Cells[2][n]=IntToStr(weight);
tr.Cells[3][n]=IntToStr(amount);
tr.Cells[4][n]=FloatToStr(price);
};
//---------------------------------------------------------------------------
void TViewEvent::ShowRow(TStringGrid& row) //çàïîâíþº 1 ðÿäîê òàáëèö³
{
row.Cells[0][0]="¹";
row.Cells[1][0]="Íàçâà ïðîäóêö³¿";
row.Cells[2][0]="Âàãà";
row.Cells[3][0]="Ê-ñòü";
row.Cells[4][0]="Ö³íà";
} ;
//---------------------------------------------------------------------------
void TViewEvent::ShowError() //âèâîäèòü ïîìèëêó, ÿêùî íå îáðàíî æîäíîãî îá'ºêòó
{
if (Application->MessageBox("Áóäüòå ëàñêàâ³, ââåä³òü íàçâó ïðîäóêö³¿",
"Ïîìèëêà",MB_OK)==IDOK);
}
//-------------------------------------------------------------------------
void TViewEvent::Look(TStringGrid& tr) //âèêîíóº óñ³ íåîáõ³äí³ ìåòîäè äëÿ âèâåäåííÿ äàíèõ ³ç ôàéëó
{
int n=m.diskCount();
tr.RowCount=n+1;
for(int i=0;i<n;i++)
{
m.diskRead(i);
m.ShowData(tr,i+1);
}
}