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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "myproject.h"
#include "Unit2.h"
#include "Unit3.h"
#include <stdio.h>
#include <stdlib>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TStanki *Stanki;
//Выключение кнопок изменение и удаление
__fastcall TStanki::TStanki(TComponent* Owner)
: TForm(Owner)
{
bool activ = Stanki->Table->Selected && (int)Stanki->Table->Selected->Data != -1;
Stanki->izmenmenu->Items->Items[1]->Enabled=activ;
Stanki->izmenmenu->Items->Items[2]->Enabled=activ;
}
int N=0;
osnova* b[100];
char naim2[25];
int nomer2;
int type2;
char country2 [30];
short hight2;
short noise2;
char brak2[10];
char data2[11];
char pasport2[25];
short toch2;
char typed2[30];
char typem2 [30];
//derevo* d[100];
//metal* m[100];
//функция очистки Edit
void TDobav :: chist()
{
naim1p->Text="";
nomer1p->Text="";
country1p->Text="";
ves1p->Text="";
noise1p->Text="";
brak1p->Text="";
data1p->Text="";
pasport1p->Text="";
tochnost1p->Text="";
}
//функция заполнения данных в ListView
void TStanki :: zap(int i)
{
TListItem *item = Stanki->Table->Items->Add();
item->Caption=b[i]->Naim();
item->SubItems->Add(b[i]->Nomer());
//if (b[i] -> type == 1)
item->SubItems->Add(b[i]->Typek());
// if (b[i] -> type == 0)
//item->SubItems->Add(typem);
item->SubItems->Add(b[i]->Country());
item->SubItems->Add(b[i]->Hight());
item->SubItems->Add(b[i]->Noise());
item->SubItems->Add(b[i]->Brak());
item->SubItems->Add(b[i]->Data());
item->SubItems->Add(b[i]->Pasport());
item->SubItems->Add(b[i]->Toch());
}
//функция выбора класса с типом
void TDobav :: vibor(k)
{
if (Dobav->Types->ItemIndex == 1)
{ strcpy (typed2, "Деревообрабатывающий");
b[k] = new derevo(naim2, nomer2, country2, hight2, noise2, brak2,
data2, pasport2, toch2, typed2);
}
if (Dobav->Types->ItemIndex == 0)
{ strcpy (typem2, "Металлообрабатывающий");
b[k] = new metal(naim2, nomer2, country2, hight2, noise2, brak2,
data2, pasport2, toch2, typem2);
}
}
//функция считывания данных с Edit
void TDobav :: schit(kk)
{
AnsiString naim1=naim1p->Text;
sprintf(naim2, "%s", naim1);
AnsiString nomer1=nomer1p->Text;
nomer2 = atoi(nomer1.c_str());
AnsiString country1=country1p->Text;
sprintf(country2, "%s", country1);
AnsiString ves1=ves1p->Text;
hight2 = atoi(ves1.c_str());
AnsiString noise1=noise1p->Text;
noise2 = atoi(noise1.c_str());
AnsiString brak1=brak1p->Text;
sprintf(brak2, "%s", brak1);
AnsiString data1=data1p->Text;
sprintf(data2, "%s", data1);
AnsiString pasport1=pasport1p->Text;
sprintf(pasport2, "%s", pasport1);
AnsiString toch1=tochnost1p->Text;
toch2 = atoi(toch1.c_str());
}
//функция добавления данных в ListView
int TDobav :: dobav ()
{
// b[N] = new osnova;
// d[N] = new derevo;
// m[N] = new metal;
schit(N);
vibor(N);
Stanki->zap(N);
N++;
chist();
return(N);
}
//функция изменения данных в ListView
void TDobav :: izmena ()
{ int K = (int)Stanki->Table->Selected->Index;
delete b[K];
schit(K);
vibor(K);
Stanki->Table->Items->Clear();
for(int i = 0; i < N; i++)
{
Stanki->zap(i);
}
chist();
}
//функция удаления данных в ListView
int TStanki :: del()
{
int L = (int)Stanki->Table->Selected->Index;
delete b[L];
for(int g = L; g < N; g++)
{
b[g] = b[g+1];
}
N--;
Stanki->Table->Items->Clear();
for(int l = 0; l < N; l++)
{
Stanki->zap(l);
}
return (N);
}
//функция заполнения данных в ListView с файла
int TStanki :: filer()
{
FILE *in1 = fopen ("chtenie.txt" , "r");
if (in1 == NULL)
{
ShowMessage ("Ошибка открытия файла");
return(0);
}
else
{
int i = N;
while (!feof(in1))
{ memset(naim2, 0, sizeof(naim2));
memset(country2, 0, sizeof(country2));
memset(brak2, 0, sizeof(brak2));
memset(data2, 0, sizeof(data2));
memset(pasport2, 0, sizeof(pasport2));
memset(typem2, 0, sizeof(typem2));
memset(typed2, 0, sizeof(typed2));
nomer2 = 0;
hight2 = 0;
noise2 = 0;
toch2 = 0;
fscanf(in1, "%s %d %d %s %d %d %s %s %s %d ",
naim2, &nomer2, &type2, country2, &hight2, &noise2, brak2, data2,
pasport2, &toch2);
if(type2 == 1)
{
fscanf(in1, "%s", typed2);
b[i] = new derevo(naim2, nomer2, country2, hight2, noise2, brak2,
data2, pasport2, toch2, typed2);
}
if(type2 == 0)
{ fscanf(in1, "%s", typem2);
b[i] = new metal(naim2, nomer2, country2, hight2, noise2, brak2,
data2, pasport2, toch2, typem2);
}
Stanki->zap(i);
i++;
N++;
}
}
fclose (in1);
return (N);
}
//функция сохранения данных в файл
void TStanki :: files()
{
FILE* in1 = fopen("chtenie.txt", "w+");
if(in1 == NULL)
{
ShowMessage("Невозможно открыть файл для записи");
return;
}
else
{
for(int i = 0; i < N; i++)
{
fprintf(in1, "%s %d %d %s %d %d %s %s %s %d %s\n",
b[i]->Naim(), b[i]->Nomer(), b[i]->Type(), b[i]->Country(), b[i]->Hight(), b[i]->Noise(), b[i]->Brak(),
b[i]->Data(), b[i]->Pasport(), b[i]->Toch(), b[i]->Typek());
}
fclose(in1);
}
}
osnova :: osnova (char* Naim, int Nomer, char* Country, short Hight, short Noise, char* Brak,
char* Data, char* Pasport, short Toch)
{
strcpy(naim, Naim);
nomer=Nomer;
strcpy(country, Country);
hight=Hight;
noise=Noise;
strcpy(brak, Brak);
strcpy(data, Data);
strcpy(pasport, Pasport);
toch=Toch;
}
derevo :: derevo(char* Naim, int Nomer, char* Country, short Hight, short Noise, char* Brak,
char* Data, char* Pasport, short Toch, char* Typed) : osnova (Naim, Nomer, Country, Hight, Noise,
Brak, Data, Pasport, Toch)
{
strcpy(typed, Typed);
}
metal :: metal(char* Naim, int Nomer, char* Country, short Hight, short Noise, char* Brak,
char* Data, char* Pasport, short Toch, char* Typem) : osnova (Naim, Nomer, Country, Hight, Noise,
Brak, Data, Pasport, Toch)
{
strcpy(typem, Typem);
}
char* TSearchf :: poisk()
{ char txt[30];
AnsiString txt1=naimp->Text;
sprintf(txt, "%s", txt1);
Stanki->Table->Items->Clear();
for (int i = 0; i < N; i++)
{
for (char* n = b[i]->Naim(); *n; n++)
{
bool zn = true;
for (char* t=txt, *s = n; *t; t++, s++)
if (!*s || *t != *s)
{
zn = false;
break;
}
if (zn)
{
Stanki->zap(i);
}
}
}
return(NULL);
}
void TStanki ::sorti()
{
int i=0, j=0, step=0;
char tmp=0;
for (step = N / 2; step > 0; step /= 2)
for (i = step; i < N; i++)
{
tmp = b[i]->Nomer();
for (j = i; j >= step; j = j - step)
{
if (tmp < (b[j - step]->Nomer()))
b[j] = b[j - step];
else
break;
}
b[j]->Nomer() = tmp; //вот здесь выдает ошибку Lvalue required
}
for (i = 0; i < N; i++)
{
Stanki->zap(i);
}
}
//---------------------------------------------------------------------------
void __fastcall TStanki::exitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TStanki::searchClick(TObject *Sender)
{
Searchf->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TStanki::N1Click(TObject *Sender)
{
Dobav->gotovo->Visible = true;
Dobav->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TStanki::N2Click(TObject *Sender)
{
Dobav->izmeni->Visible = true;
Dobav->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TStanki::N3Click(TObject *Sender)
{
del();
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TStanki::TableMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y)
{
if (Button == mbRight || Button == mbLeft)
{
bool activ = Stanki->Table->Selected && (int)Stanki->Table->Selected->Data != -1;
Stanki->izmenmenu->Items->Items[1]->Enabled=activ;
Stanki->izmenmenu->Items->Items[2]->Enabled=activ;
}
}
//---------------------------------------------------------------------------
void __fastcall TStanki::loadClick(TObject *Sender)
{
Stanki->filer();
}
//---------------------------------------------------------------------------
void __fastcall TStanki::saveClick(TObject *Sender)
{
files();
}
//---------------------------------------------------------------------------
void __fastcall TStanki::sortClick(TObject *Sender)
{
sorti();
}
//--------------------------------------------------------------------------- |