-
Notifications
You must be signed in to change notification settings - Fork 0
/
tombolamax_generate.pas
355 lines (298 loc) · 9.09 KB
/
tombolamax_generate.pas
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
unit tombolamax_generate;
{$mode ObjFPC}{$H+}
interface
uses
Classes, Variants, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtDlgs, ExtCtrls, LR_DSet, LR_Class,
BCButton, BCTrackbarUpdown, BCLabel, BGRASpeedButton, BCListBox;
type
TColonna = record
Min, Max, Tot :Integer;
end;
TCartella = array[0..8, 1..3] of Integer;
TGruppoCartelle = array [1..6] of TCartella;
{ TFormGenerate }
TFormGenerate = class(TForm)
BCLabel1: TBCLabel;
BCLabel2: TBCLabel;
BCLabel3: TBCLabel;
frReportCartelleBack: TfrReport;
ImageNumeri: TImage;
ImageCartella: TImage;
OpenPictureDialog: TOpenPictureDialog;
panSfondo: TBCPaperPanel;
btPictureNumeri: TBGRASpeedButton;
btPictureCartella: TBGRASpeedButton;
cbBackImage: TCheckBox;
edPictureCartella: TEdit;
edTitolo: TEdit;
edPictureNumeri: TEdit;
frReportCartelle: TfrReport;
totCartelle: TBCTrackbarUpdown;
btGenerate: TBCButton;
frCartelle: TfrUserDataset;
procedure btPictureNumeriClick(Sender: TObject);
procedure cbBackImageChange(Sender: TObject);
procedure frReportCartelleAfterPrint(Sender: TfrReport);
procedure frReportCartelleEnterRect(Memo: TStringList; View: TfrView);
procedure frReportCartelleGetValue(const ParName: String; var ParValue: Variant);
procedure btGenerateClick(Sender: TObject);
procedure frCartelleCheckEOF(Sender: TObject; var Eof: Boolean);
procedure frCartelleFirst(Sender: TObject);
procedure frCartelleNext(Sender: TObject);
procedure totCartelleEnter(Sender: TObject);
private
pictureNumeri, pictureCartella :String;
curCartella :Integer;
Cartelle: array of TCartella;
Duplicati, DuplicatiCon : array of Integer;
FrontPrinted :Boolean;
function CreaGruppoCartelle: TGruppoCartelle;
function InDuplicati(NumCartella: Integer):Boolean;
public
end;
var
FormGenerate: TFormGenerate;
myPath: String='';
implementation
{$R *.lfm}
{ TFormGenerate }
procedure TFormGenerate.btGenerateClick(Sender: TObject);
var
i, k, j, NumGruppi,
NumCartInizio :Integer;
curGruppo :TGruppoCartelle;
//duplicates:Boolean;
msg:String;
begin
FrontPrinted :=False;
totCartelleEnter(nil);
Application.ProcessMessages;
NumGruppi :=totCartelle.Value div 6;
SetLength(Cartelle, totCartelle.Value);
SetLength(Duplicati, 0);
SetLength(DuplicatiCon, 0);
for i := 0 to NumGruppi-1 do
begin
NumCartInizio :=i*6;
curGruppo :=CreaGruppoCartelle;
(*
repeat
duplicates :=False;
curGruppo :=CreaGruppoCartelle;
for k :=1 to 6 do
for j:=1 to 6 do
if CompareMem(@curGruppo[k], @lastGruppo[j], Length(TCartella)) then
begin
duplicates :=True;
Break;
end;
if duplicates then
begin
//ShowMessage('DUPLICATI');
Sleep(Random(50));
Randomize;
end;
until not(duplicates);
*)
for k :=0 to 5 do Cartelle[NumCartInizio+k] :=curGruppo[k+1];
//lastGruppo :=curGruppo;
end;
for k :=Low(Cartelle) to High(Cartelle)-1 do
begin
for j:=k+1 to High(Cartelle) do
if CompareMem(@Cartelle[k], @Cartelle[j], Sizeof(TCartella)) then
begin
SetLength(Duplicati, Length(Duplicati) + 1);
Duplicati[High(Duplicati)] := j;
SetLength(DuplicatiCon, Length(DuplicatiCon) + 1);
DuplicatiCon[High(DuplicatiCon)] := k;
end;
end;
if Length(Duplicati)>0 then
begin
msg:='';
for i:=Low(Duplicati) to High(Duplicati) do msg:=msg+#13#10+IntToStr(DuplicatiCon[i]+1)+' e '+IntToStr(Duplicati[i]+1);
ShowMessage('DUPLICATI '+ msg);
end;
frReportCartelle.LoadFromFile(myPath+'report\report4.lrf');
frReportCartelle.ShowReport;
if FrontPrinted and cbBackImage.Checked then
begin
if (MessageDlg('Inserisci di nuovo le Cartelle nella Stampante per Stampare Il retro', mtConfirmation, [mbOk, mbCancel], 0) = mrOk) then
begin
frReportCartelleBack.LoadFromFile(myPath+'report\report4-back.lrf');
frReportCartelleBack.ShowReport;
end;
end;
end;
procedure TFormGenerate.frReportCartelleGetValue(const ParName: String; var ParValue: Variant);
var
iPos :Integer;
Riga, Colonna, Numero :Integer;
begin
iPos :=Pos(',', ParName);
if iPos>0
then begin
Riga :=StrToInt(Copy(ParName, 1, iPos-1));
Colonna :=StrToInt(Copy(ParName, iPos+1, 255));
Numero :=Cartelle[curCartella][Colonna, Riga];
if (Numero>0)
then ParValue :=IntToStr(Numero)
else ParValue:='';
end
else begin
if ParName='NUMCART'
then ParValue :=IntToStr(curCartella+1)
else
if ParName='TITOLO'
then ParValue :=edTitolo.Text
else ParValue :='';
end;
end;
procedure TFormGenerate.frReportCartelleEnterRect(Memo: TStringList; View: TfrView);
begin
if View.Name = 'PictureNumeri'
then begin if FileExists(pictureNumeri) then (View as TfrPictureView).Picture.LoadFromFile(pictureNumeri); end
else
if View.Name = 'PictureCartella'
then begin if FileExists(pictureCartella) then (View as TfrPictureView).Picture.LoadFromFile(pictureCartella); end;
end;
procedure TFormGenerate.btPictureNumeriClick(Sender: TObject);
begin
if OpenPictureDialog.Execute
then if (Sender=btPictureNumeri)
then begin
pictureNumeri:=OpenPictureDialog.FileName;
edPictureNumeri.Text:=pictureNumeri;
ImageNumeri.Picture.LoadFromFile(pictureNumeri);
end
else begin
pictureCartella:=OpenPictureDialog.FileName;
edpictureCartella.Text:=pictureCartella;
ImageCartella.Picture.LoadFromFile(pictureCartella);
end;
end;
procedure TFormGenerate.cbBackImageChange(Sender: TObject);
begin
if cbBackImage.Checked
then begin
panSfondo.Enabled:=True;
edPictureCartella.Text:='';
pictureCartella:='';
btPictureCartella.Click;
end;
end;
procedure TFormGenerate.frReportCartelleAfterPrint(Sender: TfrReport);
begin
FrontPrinted :=True;
end;
procedure TFormGenerate.frCartelleCheckEOF(Sender: TObject; var Eof: Boolean);
begin
Eof := (curCartella>High(Cartelle));
end;
procedure TFormGenerate.frCartelleFirst(Sender: TObject);
var
Eof:Boolean;
begin
curCartella :=Low(Cartelle);
Eof := False;
while inDuplicati(curCartella) and not(Eof) do
begin
Inc(curCartella);
Eof := (curCartella>High(Cartelle));
if Eof then frReportCartelle.Terminated:=True;
end;
end;
procedure TFormGenerate.frCartelleNext(Sender: TObject);
var
Eof:Boolean;
begin
repeat
Inc(curCartella);
Eof := (curCartella>High(Cartelle));
if Eof then frReportCartelle.Terminated:=True;
until not(inDuplicati(curCartella)) or Eof;
end;
procedure TFormGenerate.totCartelleEnter(Sender: TObject);
begin
if (totCartelle.Value mod 12 <> 0)
then totCartelle.Value :=((totCartelle.Value div 12)+1)*12;
end;
function TFormGenerate.CreaGruppoCartelle: TGruppoCartelle;
var
Colonne :array[0..8] of TColonna;
Numeri :array[1..90] of Integer;
i, k,
Colonna, Appoggio,
DaInvertire1, DaInvertire2,
Cartella :Integer;
Posizione, OrdineCartella : array[1..6] of Integer;
begin
Sleep(Random(50)+Random(10)); //Avoid the same ranseed of previous Group
Randomize;
for i := 1 to 90 do Numeri[i] := i;
FillChar(Result, Sizeof(Result), 0);
for Colonna := 0 to 8 do
begin
Colonne[Colonna].Min := 0 + Colonna * 10;
Colonne[Colonna].Max := 9 + Colonna * 10;
Colonne[Colonna].Tot := 10;
end;
Colonne[0].Min := 1;
Colonne[0].Tot := 9;
Colonne[8].Max := 90;
Colonne[8].Tot := 11;
for Colonna := 0 to 8 do
for i := 1 to 100 do
begin
DaInvertire1 := Random(Colonne[Colonna].Tot)+1;
DaInvertire2 := Random(Colonne[Colonna].Tot)+1;
Appoggio := Numeri[DaInvertire1 + Colonne[Colonna].Min - 1];
Numeri[DaInvertire1 + Colonne[Colonna].Min - 1] := Numeri[DaInvertire2 + Colonne[Colonna].Min - 1];
Numeri[DaInvertire2 + Colonne[Colonna].Min - 1] := Appoggio;
end;
for i := 1 to 6 do Posizione[i] := Random(3)+1;
Cartella := 1;
for Colonna := 0 to 8 do
for i := Colonne[Colonna].Min to Colonne[Colonna].Max do
begin
Result[Cartella, Colonna, Posizione[Cartella]] := Numeri[i];
Posizione[Cartella] := Posizione[Cartella] + 1;
if (Posizione[Cartella] > 3) then Posizione[Cartella] := 1;
Cartella := Cartella + 1;
if (Cartella > 6) Then Cartella := 1;
end;
i:=1;
while (i<=6) do
begin
OrdineCartella[i] := Random(6)+1;
for k := 1 to i - 1 do
begin
if OrdineCartella[i] = OrdineCartella[k] then
begin
i := i - 1;
break;
end;
end;
Inc(i);
end;
end;
function TFormGenerate.InDuplicati(NumCartella: Integer): Boolean;
var
i :Integer;
begin
Result :=False;
for i :=Low(Duplicati) to High(Duplicati) do
begin
Result := (NumCartella=Duplicati[i]);
if Result then break;
end;
end;
initialization
{$ifopt D+}
//myPath :='..\..\';
myPath:= ExpandFileName('..\..\', ExtractFilePath(ParamStr(0)));
{$else}
myPath:= ExtractFilePath(ParamStr(0));
{$endif}
end.