-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
2383 lines (2202 loc) · 70.3 KB
/
main.cpp
File metadata and controls
2383 lines (2202 loc) · 70.3 KB
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Database by Necro
main.cpp
DOS real mode, Borland C++ v3.1, Turbo Vision
15.04.2k-17.04.2k: base interface created, exist unknown bugs,
all database ctrls inactive. Version called VIEWABLE 1,
but it's only quarter-functionality interface demo.
18.04.2k: interface don't causes freeze now.
19.04.2k: both DDriver & DPath dbase ctrls workable,
but DCar has an unknown bug.
20.04.2k: date have been added to the status line, bug with DCar
is not fixed, but it's silent now.
22.04.2k: entire interface & database ctrls (with some exceptions)
are full workable now. Left incomplete: ListType bug, list loader,
delete function for all dataeditors & print function.
27.04.2k: ListType bug have been found & fixed. WPrint dialog created & has half
of it's functionality: no print function & movelist up/down
almost unusable. Added XFill() function that writes given number of
specified character to the file. Version number now is
VIEWABLE 2.
01.05.2k: WPrint movelist up/down still almost unusable, but effect of bug halved:
button preselected & dialog has an input focus. evPrintScope() function
attached to Print_T#() functional set. Most of WPrint bugs are fixed.
Added delete function for the all dataeditors, including WList. Function
workable, but has an unknown bug: stdio::unlink() is not work propertly.
File saving operations do not write trash to the files, used memset(,0,).
Rem'ed code removed, added funcs fsize() & fcopy(). ArtPrev & ArtNext are
cycled now: 0-1=max
02.05.2k: WList now draws entire form then in LoadList mode. Simple
replaced eView->draw() by UpdateView. Added number of
article & filesize to the eView. Ultimate known bug of
WPrint is fixed now. Added ArtNext & ArtPrev keys to
the WPrint form, UpArrow/DownArrow/PageUp/PageDown keys
still avaible. Version number changed to VIEWABLE 3.
03.05.2k: found & fixed delete-function bug. Interface now is better
than last time: WList has auto-selectable buttons ("...")
and receives KeyDown messages (left/right arrows as
"<<"/">>" buttons) now. Keyboard now is better than mouse...
04.05.2k: FileOpen dialog added and seems it's working propertly.
05.05.2k: found & fixed linkage (between DList & Dxxx) bug. Added
"close file" menuitem to reinitialize name of current LST.
Added generator for order number of list.
06.05.2k: field License[21] of DCar was split to three parts. Some
invisible information added to TConfig, and to EXE so well.
Added directory, that must contain *.lst files. Number generator
improved & exists now for WList too.
08.05.2k: it seems, that Print_T0() is now complete. Print_T1() filled
but somethere invalid. Print_T2 & Print_T3 now use code of Print_T1().
Version number changed to VIEWABLE 4.
09.05.2k: Print_Tx() functions for all types of lists is in beta-version now.
Version number now is RELEASE CANDIDATE 1; Usage limit added.
11.05.2k: Print_Tx() (except Print_T1()) rechanged. RELEASE CANDIDATE 2.
13.05.2k: Print_Tx() is complete now.
15.05.2k: Added "Add File" function, DRIVER linked to CAR, WList now
has ergonomic addition: search in bases for first letters of names.
It's a cool thing! RELEASE 1 - COMPLETE.
29.06.2k: Fixed number of bugs: fsize() bug (internal representation of filesize
was a short int); evFileOpen()/evFileAdd() bug (button "Cancel" had no
effect); invisible Print_Tx() bug (date format: dd-dd mmmm yyyy, but
what will happen if start month <> end month ?)
*/
//misc includings:
#include <stdio.h>
#include <io.h>
#include <sys/stat.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
// follow database declarations:
typedef unsigned short TID;
typedef unsigned long ulong;
typedef unsigned short ushort;
struct TDateTime {
char Month[3];
char Day[3];
char Hour[3];
char Min[3];
};
enum BASES{DRIVER=666,CAR,PATH,LIST};
struct DBase
{
TID id;
unsigned long size;//size of article
};
struct DDriver : public DBase
{
char Name[31];// ” ¬¨«¨ï ˆŽ
char TabId[11];//â ¡¥«ìë© ®¬¥à
char DocId[11];//®¬¥à 㤮á⮢¥à¥¨ï
char Class[2];//ª« áá
char Column[2];//®¬¥à ª®«®ë
char Square[2];//®¬¥à ¡à¨£ ¤ë
};
struct DCar : public DBase
{
char SAINum[9];//like A666HB42
char Mark[21];//like ƒ€‡ 2101
char Fuel[51];//ª®«¨ç¥á⢮ £®àî祣®, ¯à®¯¨áìî
char Type;//0=«¥£ª®¢ ï, 1=£àã§®¢ ï, 2= ¢â®¡ãá, 3=ᯥæ.
TID Driver;//áá뫪 ¢®¤¨«ã
char LicenseReg[16];//®¬¥à «¨æ¥§¨¨
char LicenseSer[11];
char LicenseNum[11];
//previous version: License[21]
};
struct DPath : public DBase
{
char Name[51];// §¢ ¨¥
TDateTime StartTime;//¢à¥¬ï ¢ë¥§¤
TDateTime EndTime;//¨ ¢ê¥§¤
char ZeroPath[7];//¤«¨ ã«¥¢®£® ¯à®¡¥£
char QNorm[4];//ª®íä. ¨§¬¥¥¨ï ®à¬ë
};
struct DList :public DBase
{
char sDateTime[17];
TID idPath;
TID idCar;
TID idDriver;
char Path[51];
TDateTime StartTime;
TDateTime EndTime;
char SAINum[9];
char Mark[21];
char Fuel[51];
char Type;
char Driver[31];
char Manager[31];
};
//follow misc declarations:
struct TConfig
{
char STRING[17];
unsigned size;
char Copyright[11];//Necro,2000
char GetOut[17];//—¥£® ãáâ ¢¨«áï?!
char OrgName[51];
char DriverBase[13];
char CarBase[13];
char PathBase[13];//filenames for given databases
char ListDir[13];//directory to save new listfiles
char DisplayAboutBox;//does AboutBox must be displayed?
char TempFile[13];//name for tempfile, that used by delete function
char PrnDevice[13];//name of printer device, such as "PRN" or "LPT1"
unsigned char Seed;//number of printed list
char PrintDate;//field Null1 was replaced by boolean field PrintDate (must program print date to the list, or not?)
ushort TimeRemaining;//usage limit
};
char Month[12][9]={"ï¢ àï","ä¥¢à «ï","¬ àâ "," ¯à¥«ï","¬ ï","¨îï","¨î«ï",
" ¢£ãáâ ","á¥âï¡àï","®ªâï¡àï","®ï¡àï","¤¥ª ¡àï"};
const char *cfgName="ndb.ini";//configuration file for this program
//follow TVision declarations:
#define Uses_TApplication
#define Uses_TKeys
#define Uses_TRect
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_TWindow
#define Uses_TView
//#define Uses_TScroller
#define Uses_TScrollBar
#define Uses_TDialog
#define Uses_TButton
#define Uses_TLabel
#define Uses_TInputLine
#define Uses_TListBox
#define Uses_TStringCollection
#define Uses_MsgBox
#define Uses_TCheckBoxes
#define Uses_TSItem
#define Uses_TMemo
#define Uses_TFileDialog
#define Uses_TColorDialog
#define Uses_TColorGroup
#define Uses_TColorItem
#include <tv.h>
int winNumber=0;
TConfig CFG;//config; global for all objects
ulong fsize(FILE*file)//returns not size, but maximal offset
{
unsigned long p=ftell(file);
fseek(file,0,SEEK_END);
ulong s=ftell(file);
fseek(file,p,SEEK_SET);
return s;
}
ulong fcopy(char* name_dst,char* name_src)
{
char buf;
FILE *dst=fopen(name_dst,"wb");
FILE *src=fopen(name_src,"rb");
ulong size=fsize(src);
for (ulong n=0;n<size;n++) {
fread(&buf,1,1,src);
fwrite(&buf,1,1,dst);
}
fclose(dst);
fclose(src);
return size;
}
void fappend(char* name_dst,char* name_src)
{
char buf;
FILE *dst=fopen(name_dst,"r+b");
FILE *src=fopen(name_src,"rb");
ulong size=fsize(src);
fseek(dst,0,SEEK_END);
for (ulong n=0;n<size;n++) {
fread(&buf,1,1,src);
fwrite(&buf,1,1,dst);
}
fclose(dst);
fclose(src);
}
char UpCase(char ch)
{
if (ch>='a' && ch<='z') return ch-=('a'-'A');
if (ch>=' ' && ch<='¯') return ch-=(' '-'€');
if (ch>='à' && ch<='ï') return ch-=('à'-'');
if (ch=='ñ') return 'ð';
return ch;
}
int compare(char* comp,char* inc)//compares two strings: one complete & one incomplete
//for example: "Necro" & "Nec" (=true)
//but terminating null always must be assigned
{
for (int x=0;x<strlen(inc);x++) {
if (UpCase(comp[x])!=UpCase(inc[x])) {return 0;}
}
return 1;
}
void XFill(FILE*file,char ch,unsigned amount)
{
for (int n=0;n<amount;n++)
fprintf(file,"%c",ch);
}
int Print_T0(DList&list,DDriver&driver,DCar&car,DPath&path)//«¥£ª®¢ ï
{
date d;
getdate(&d);
FILE* file=fopen(CFG.PrnDevice,"ab");
int mon;
sscanf(list.StartTime.Month,"%d",&mon);
//testing area:
XFill(file,'\n',5);// +1
XFill(file,' ',35);// -7 (for all)
fprintf(file,"%02d%02d%02d",d.da_day,d.da_mon,CFG.Seed);
fprintf(file,"\n\r");
XFill(file,' ',10);
if (CFG.PrintDate) {
if (!strcpy(list.StartTime.Day,list.EndTime.Day))
fprintf(file,"%s-%s %s %04d",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);
else fprintf(file,"%s %s %04d",list.StartTime.Day,Month[mon-1],d.da_year);
}
fprintf(file,"\n\r");
XFill(file,'\n',2);
XFill(file,' ',5);
fprintf(file,"%s\n\n\r",CFG.OrgName);
XFill(file,' ',8);
fprintf(file,"%s\n\r",car.Mark);
XFill(file,' ',15);
fprintf(file,"%s\n\r",car.SAINum);
fprintf(file,"%23s %20s\n\n\r",driver.Name,driver.TabId);
fprintf(file,"%25s %10s\n\r",driver.DocId,driver.Class);
fprintf(file,"\n\n\r%17s %10s %7s\n\r",car.LicenseReg,car.LicenseSer,car.LicenseNum);
fprintf(file,"\r\n%25s \n\n\r",list.Path);//unknown item -1
XFill(file,'\n',7);
XFill(file,' ',18);
fprintf(file,"%s:%s\n\n\r",list.StartTime.Hour,list.StartTime.Min);
XFill(file,' ',13);
fprintf(file,"%s\n\n\r",list.Manager);
XFill(file,' ',18);
fprintf(file,"%s:%s\n\r",list.EndTime.Hour,list.EndTime.Min);
XFill(file,' ',13);
fprintf(file,"%s",list.Manager);
fclose(file);
return 0;
//beta2 completed
}//Print_T0()
int Print_T1(DList&list,DDriver&driver,DCar&car,DPath&path)//£àã§®¢ ï
{
date d;
getdate(&d);
int mon;
sscanf(list.StartTime.Month,"%d",&mon);
FILE* file=fopen(CFG.PrnDevice,"at");
XFill(file,' ',46);
fprintf(file,"%02d%02d%02d",d.da_day,d.da_mon,CFG.Seed);
// fprintf(file,"\n\n%63u\n\n\r",CFG.Seed);
XFill(file,' ',32);
//fprintf(file,"%s-%s %s %04d\n\r",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);
if (CFG.PrintDate) {
if (!strcpy(list.StartTime.Day,list.EndTime.Day))
fprintf(file,"%s-%s %s %04d",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);
else fprintf(file,"%s %s %04d",list.StartTime.Day,Month[mon-1],d.da_year);
}
fprintf(file,"\n\r");
XFill(file,' ',8);
fprintf(file,"%s\n\n\n\r",CFG.OrgName);
XFill(file,' ',41);
fprintf(file,"¯® £à 䨪ã\n\r");
XFill(file,' ',41);
fprintf(file,"%s\n\r",driver.Column);
XFill(file,' ',41);
fprintf(file,"%s\n\r",driver.Square);
XFill(file,' ',10);
fprintf(file,"%s\n\r",list.Mark);
fprintf(file,"%28s%34s%3s%4s%3s %s\n\r",list.SAINum,list.StartTime.Day,list.StartTime.Month,
list.StartTime.Hour,list.StartTime.Min,path.ZeroPath);
fprintf(file,"%28s%16s%18s%3s%4s%3s %s\n\r",list.Driver,driver.TabId,
list.EndTime.Day,list.EndTime.Month,list.EndTime.Hour,
list.EndTime.Min,path.ZeroPath);
fprintf(file,"%19s %12s\n\n\r",driver.DocId,driver.Class);
fprintf(file,"%16s %8s %8s\n\r",car.LicenseReg,car.LicenseSer,car.LicenseNum);
XFill(file,'\n',2);
XFill(file,' ',82);
fprintf(file,"%s\n\r",path.QNorm);
XFill(file,'\n',5);
// fprintf(file,"%23s %02s:%02s %02s:%02s\n\n\r",list.Path,list.EndTime.Hour,list.EndTime.Min,list.StartTime.Hour,list.StartTime.Min);
fprintf(file,"%23s\n\n\r",list.Path);
fprintf(file,"%28s\n\r",list.Fuel);
fprintf(file,"%26s",list.Manager);
fclose(file);
return 0;
//alpha
}//Print_T1()
int Print_T2(DList&list,DDriver&driver,DCar&car,DPath&path)// ¢â®¡ãá
{
date d;
getdate(&d);
int mon;
sscanf(list.StartTime.Month,"%d",&mon);
FILE* file=fopen(CFG.PrnDevice,"at");
// fprintf(file,"\n%52u\n\r",CFG.Seed);//-1Y -6X
XFill(file,' ',43);
fprintf(file,"%02d%02d%02d\n\r",d.da_day,d.da_mon,CFG.Seed);
XFill(file,' ',20);
if (CFG.PrintDate) {
if (!strcpy(list.StartTime.Day,list.EndTime.Day))
fprintf(file,"%s-%s %s %04d",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);
else fprintf(file,"%s %s %04d",list.StartTime.Day,Month[mon-1],d.da_year);
};
fprintf(file,"\n\n\r");
// fprintf(file,"%02s-%02s %s %04d\n\n\r",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);//-1Y
XFill(file,' ',18);
fprintf(file,"%s\n\n\r",CFG.OrgName);
//next for A3 only:
XFill(file,' ',66);
fprintf(file,"¯® £à 䨪ã\n\r");
XFill(file,' ',69);
fprintf(file,"%s\n\r",driver.Column);
fprintf(file,"%40s%30s\n\r",car.Mark,driver.Square);
XFill(file,' ',30);
fprintf(file,"%s\n\r",car.SAINum);
fprintf(file,"%34s",driver.Name);
fprintf(file,"%38s",driver.TabId);//for A3
fprintf(file,"\n\n\r");
fprintf(file,"%18s%12s\n\n\n\r",driver.DocId,driver.Class);
fprintf(file,"%21s%10s%12s\n\r",car.LicenseReg,car.LicenseSer,car.LicenseNum);
XFill(file,'\n',5);
fprintf(file,"%16s:%2s%5s\n\r",list.StartTime.Hour,list.StartTime.Min,path.ZeroPath);
fprintf(file,"%16s:%2s%5s",list.EndTime.Hour,list.EndTime.Min,path.ZeroPath);
// fprintf(file,"%31s %2s:%2s%3s:%2s",list.Path,list.EndTime.Hour,list.EndTime.Min,list.StartTime.Hour,list.StartTime.Min);
fprintf(file,"%31s",list.Path);
//it was for A3 only ^
XFill(file,'\n',6);
fprintf(file,"\r%42s\r",path.QNorm);
XFill(file,'\n',6);
fprintf(file,"%25s\n\r",car.Fuel);
fprintf(file,"%30s",list.Manager);
fclose(file);
return 0;
//beta2
}//Print_T2()
int Print_T3(DList&list,DDriver&driver,DCar&car,DPath&path)//ᯥæ.
{
date d;
getdate(&d);
int mon;
sscanf(list.StartTime.Month,"%d",&mon);
FILE* file=fopen(CFG.PrnDevice,"at");
// fprintf(file,"\n\n%50u\n\r",CFG.Seed);//-8X
XFill(file,' ',40);
fprintf(file,"%02d%02d%02d\n\r",d.da_day,d.da_mon,CFG.Seed);
XFill(file,' ',18);
// fprintf(file,"%s-%s %s %04d\n\n\r",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);//-1Y
if (CFG.PrintDate) {
if (!strcpy(list.StartTime.Day,list.EndTime.Day))
fprintf(file,"%s-%s %s %04d",list.StartTime.Day,list.EndTime.Day,Month[mon-1],d.da_year);
else fprintf(file,"%s %s %04d",list.StartTime.Day,Month[mon-1],d.da_year);
}
fprintf(file,"\n\n\r");
XFill(file,' ',10);
fprintf(file,"%s\n\r",CFG.OrgName);
//next for A3 only:
XFill(file,' ',64);
fprintf(file,"¯® £à 䨪ã\n\r");//-1Y
XFill(file,' ',67);
fprintf(file,"%s\n\r",driver.Column);
// XFill(file,' ',67);
// fprintf(file,"%s\n\r",driver.Square);
// XFill(file,' ',20);//maybe Mark & Square must be in same line?
// fprintf(file,"%s\n\r",car.Mark);
fprintf(file,"%40s%30s\n\r",car.Mark,driver.Square);
// fprintf(file, "%40s%30s\n\r",car.Mark,driver.Square);
XFill(file,' ',27);
fprintf(file,"%s\n\r",car.SAINum);
fprintf(file,"%32s",driver.Name);
fprintf(file,"%42s",driver.TabId);//for A3
fprintf(file,"\n\n\r");
fprintf(file,"%38s%8s\n\n\n\r",driver.DocId,driver.Class);
fprintf(file,"%32s%16s%15s\n\r",car.LicenseReg,car.LicenseSer,car.LicenseNum);
XFill(file,'\n',7);
fprintf(file,"%12s:%2s%3s",list.StartTime.Hour,list.StartTime.Min,path.ZeroPath);
fprintf(file,"%44s",path.QNorm);//for A3
fprintf(file,"\r\n\n%12s:%2s%3s\n\r",list.EndTime.Hour,list.EndTime.Min,path.ZeroPath);
XFill(file,'\n',5);
// fprintf(file,"%20s%6s:%2s%9s:%2s\n\r",list.Path,list.EndTime.Hour,list.EndTime.Min,list.StartTime.Hour,list.StartTime.Min);
fprintf(file,"%20s\n\r",list.Path);
XFill(file,'\n',3);
fprintf(file,"%24s\n\r",car.Fuel);
fprintf(file,"%30s",list.Manager);
fclose(file);
return 0;
//beta2
}//Print_T3()
enum {cmnFileOpen = 200,cmnFileNew,cmnFileSave,cmnBaseDriver,cmnBaseCar,
cmnBasePath,cmnHelpAbout,cmnSaveList,cmnLoadList,cmnPrintList,cmnSettingsCFG,
cmnSaveCFG,cmnSaveDriver,cmnSaveCar,cmnSavePath,cmnDialogClose,cmnArtNext,
cmnArtPrev,cmnArtNew,cmnArtDel,cmnArtSave,cmnSelectPath,cmnSelectCar,
cmnSelectDriver,cmnPrintSelected,cmnSettingsNum,cmnFileClose,cmnFileAdd};
class WDriver : public TDialog
{
public:
WDriver();
~WDriver();
void GetState(DDriver&);
void SetState(DDriver);
void handleEvent(TEvent&);
protected:
void ViewUpdate();
TStaticText *tArtInfo;
TInputLine *iName,*iNum,*iDoc,*iClass,*iColumn,*iSquare;
unsigned ptr;//order num of current article, file pointer in articles
unsigned size;//size of the file, in articles
DDriver data;
FILE* file;
};
class WCar : public TDialog
{
public:
WCar();
~WCar();
void GetState(DCar&);
void SetState(DCar);
void handleEvent(TEvent&);
protected:
void ViewUpdate();
void evFindDriver();
unsigned ptr;//order num of current article, file pointer in articles
unsigned size;//size of the file, in articles
DCar data;
FILE* file;
TStaticText *tArtInfo;
TInputLine *iMark,*iSAINum,*iFuel,*iLicenseReg,*iLicenseSer,*iLicenseNum,*iDriver,*iType;
};
class WPath : public TDialog
{
public:
WPath();
~WPath();
void GetState(DPath&);
void SetState(DPath);
void handleEvent(TEvent&);
protected:
void ViewUpdate();
unsigned ptr;//order num of current article, file pointer in articles
unsigned size;//size of the file, in articles
DPath data;
FILE* file;
TStaticText *tArtInfo;
TInputLine *iName,*iNullPath,*iQNorm,
*iIMonth,*iIDay,*iIHour,*iIMinute,//¢à¥¬ï ¢ê¥§¤
*iOMonth,*iODay,*iOHour,*iOMinute;//..¨ ¢ë¥§¤
};
class WList : public TDialog
{
public:
WList(char* listfile,char* Title);//must be create & save new file, which name
//depended on current date (if listfile=0), or open & work on old file,
//which name is a listfile. listfile can be obtained from the FileOpen
// WList();//for fileopen
~WList();
virtual void handleEvent(TEvent&);
void SaveScreen();
void UpdateScreen();
protected:
//base:
void evSaveList();
void evLoadList(int button=0);
void evArtDel();
void evPrintList();
//additional:
void evSelectCar(int button=0);
void evSelectDriver(int button=0);
void evSelectPath(int button=0);
int ArtNum,//number of selected dataunit
IsSelect;//is in dataunit selection mode? (maybe 0 or one of dbase ids)
char Path[200];//path to database
//temporary storages for dataunits:
DPath dPath;
DDriver dDriver;
DCar dCar;
DList dList;//final storage
unsigned ArtSize;//amount of articles in the file
//TVision ctrls:
TInputLine *iPath,*iSAINum,
*iFuel,*iListType,*iDriver,*iManager;//needed special handling
TInputLine *iMark,
*iIMonth,*iIDay,*iIHour,*iIMinute,//¢à¥¬ï ¢ê¥§¤
*iOMonth,*iODay,*iOHour,*iOMinute;//..¨ ¢ë¥§¤
TButton *bNext,*bPrev,*bSPath,*bSCar,*bSDriver;
TInputLine *eView;//dataunit info
};
class WSettings : public TDialog
{
public:
WSettings(TConfig);
~WSettings();
void GetState(TConfig&);
void SetState(TConfig);
virtual void handleEvent(TEvent& event);
protected:
void evSaveCFG();
TInputLine *iDBase,*iCBase,*iPBase,*iListFile,*iTempFile,*iPrnDevice,*iSeed;
TCheckBoxes *cbIsAbout,*cbPrintDate;
};
class WPrint : public TDialog
{
public:
WPrint(char* listfile);
~WPrint();
void SaveScreen();
void UpdateScreen();
virtual void handleEvent(TEvent& event);
protected:
void evPrintScope();
void evArtDel();
signed FirstArt;//article, associated with first checkbox
signed ArtSize;
DPath dPath;
DDriver dDriver;
DCar dCar;
DList dList;//temp storages
TCheckBoxes *cbSelection;//15 selection checkboxes
//TEditor *eView;
TInputLine *iView[15];
char Path[200];
char ERROR;
};
class TApp : public TApplication
{
public:
TApp();
~TApp();
static TStatusLine *initStatusLine( TRect r );
static TMenuBar *initMenuBar( TRect r );
virtual void handleEvent( TEvent& event);
protected:
void evFileNew(char* fname=0);//process WList dialog
void evFileOpen();//process FileOpen dialog
void evHelpAbout();//process About dialog
void evSettingsCFG();//config
void evSettingsNum();
void evBaseDriver();//WDriver
void evBaseCar();//WCar
void evBasePath();//WPath
void evPrintSelected(char* fname=0);//
void evFileAdd();
WList* WndList;//pathlist editor
WSettings* WndSettings;//configuration dialog
WDriver* WndDriver;//->
WCar* WndCar;//->
WPath* WndPath;//database editors
WPrint* WndPrint;
char Path[200];
};
TApp::TApp():TProgInit( &TApp::initStatusLine,
&TApp::initMenuBar,
&TApp::initDeskTop
)
{
randomize();
// char txt[]="PROGRAM DESTROYED BY NECRO: TIME IS UP";
char buff[100];
memset(Path,0,sizeof(Path));
date d;
getdate(&d);
chmod(cfgName,S_IREAD|S_IWRITE);
FILE*f=fopen(cfgName,"r+b");
if (!f) messageBox(mfOKButton|mfError,"” ©« ª®ä¨£ãà æ¨¨ %s ¥¤®áâ㯥",cfgName);
fread(&CFG,sizeof CFG,1,f);
if (CFG.DisplayAboutBox) evHelpAbout();
randomize();
CFG.Seed=0;//10000+random(10000);
sprintf(Path,"%s\\%04d%02d%02d.lst",CFG.ListDir,d.da_year,d.da_mon,d.da_day);
WndList=0;
WndSettings=0;
// CFG.TimeRemaining=20;
// if (CFG.TimeRemaining>0) CFG.TimeRemaining--;
fseek(f,0,SEEK_SET);
fwrite(&CFG,sizeof CFG,1,f);
fclose(f);
/* messageBox(mfInformation|mfOKButton,"Žáâ «®áì § ¯ã᪮¢: %u",CFG.TimeRemaining);
if ((CFG.TimeRemaining<=0) || (!f) || (CFG.Size!=sizeof(CFG))) {
messageBox(mfOKButton|mfInformation,"‚ë ¨áç¥à¯ «¨ ¢à¥¬ï ¨á¯®«ì§®¢ ¨ï ¯à®£à ¬¬ë. ‘«¥¤ãî騩 ¥ñ § ¯ã᪠¬®¦¥â ®ª § âìáï ᬥà⥫ìë¬. à®é ©â¥...");
fcloseall();
chmod(_argv[0],S_IREAD|S_IWRITE);
f=fopen(_argv[0],"r+b");//destroys program file...
fseek(f,50,SEEK_SET);
fprintf(f,txt);
for (int i=0;i<(fsize(f))/10000;i++) {
fwrite(buff,1,100,f);
fseek(f,5000,SEEK_CUR);
};
fclose(f);
exit(1);//...and terminates program session
};*/
}
TApp::~TApp()
{
fcloseall();
}
TStatusLine *TApp::initStatusLine(TRect r)
{
date d;
getdate(&d);
char *buff="‚á¥å ¢ à®â çëå-¯ëå ";
r.a.y = r.b.y - 1; // move top to 1 line above bottom
sprintf(buff,"³%02d.%02d.%04d³",d.da_day,d.da_mon,d.da_year);
return new TStatusLine( r,
*new TStatusDef( 0, 0xFFFF ) +
// set range of help contexts
*new TStatusItem( 0, kbF10, cmMenu ) +
*new TStatusItem( "~Alt-X~ ‚ë室", kbAltX, cmQuit ) +
// define an item
*new TStatusItem( "~Alt-F3~ ‡ ªàëâì", kbAltF3, cmClose )+
// and another one
*new TStatusItem(buff,0,0)+
*new TStatusItem(CFG.OrgName,0,0)
);
}
TMenuBar *TApp::initMenuBar( TRect r )
{
r.b.y = r.a.y + 1; // set bottom line 1 line below top line
return new TMenuBar( r,
*new TSubMenu( "” ©«", kbAltF )+
*new TMenuItem( "®¢ë© «¨áâ", cmnFileNew, kbF4, hcNoContext, "F4" )+
*new TMenuItem( "Žâªàëâì ä ©«", cmnFileOpen, kbF3, hcNoContext, "F3" )+
*new TMenuItem( "‡ ªàëâì ä ©«", cmnFileClose, 0,hcNoContext,"")+
*new TMenuItem( "„®¡ ¢¨âì ä ©«", cmnFileAdd,0,hcNoContext,"")+
*new TMenuItem( "¥ç âì...", cmnPrintSelected, kbAltP, hcNoContext, "Alt+P" )+
newLine()+
*new TMenuItem( "‚ë室", cmQuit, cmQuit, hcNoContext, "Alt-X" )+
*new TSubMenu( " §ë ¤ ëå", kbAltB )+
*new TMenuItem( "‚®¤¨â¥«¨", cmnBaseDriver, kbF5, hcNoContext, "F5" )+
*new TMenuItem( "Œ è¨ë", cmnBaseCar, kbF6, hcNoContext, "F6" )+
*new TMenuItem( "Œ àèàãâë", cmnBasePath, kbF7, hcNoContext, "F7" )+
*new TSubMenu(" áâனª¨",kbAltS)+
*new TMenuItem( "Ю䍣ãà æ¨ï",cmnSettingsCFG,kbAltC,hcNoContext,"Alt+C")+
*new TMenuItem( "®¬¥à «¨áâ ",cmnSettingsNum,kbAltN,hcNoContext,"Alt+N")+
*new TSubMenu("®¬®éì",kbAltH)+
*new TMenuItem("Ž ¯à®£à ¬¬¥...",cmnHelpAbout, kbF1,hcNoContext,"F1")
);
}
void TApp::handleEvent(TEvent& event)
{
fcloseall();
TApplication::handleEvent(event); // act like base!
if( event.what == evCommand )
{
switch( event.message.command )
{
case cmnFileNew:
evFileNew();
break;
case cmnFileOpen:
evFileOpen();
break;
case cmnHelpAbout:
evHelpAbout();
break;
case cmnSettingsCFG:
evSettingsCFG();
break;
case cmnSettingsNum:
evSettingsNum();
break;
case cmnBaseDriver:
evBaseDriver();
break;
case cmnBaseCar:
evBaseCar();
break;
case cmnBasePath:
evBasePath();
break;
case cmnPrintSelected:
evPrintSelected();
break;
case cmnFileAdd:
evFileAdd();
break;
case cmnFileClose:
date d;
getdate(&d);
sprintf(Path,"%s\\%04d%02d%02d.lst",CFG.ListDir,d.da_year,d.da_mon,d.da_day);
break;
default:
return;
}
clearEvent( event ); // clear event after handling
}
}
void TApp::evPrintSelected(char* listfile)
{
char title[230];
sprintf(title,"” ©« %s",Path);
WndPrint=new WPrint(Path);
deskTop->execView(WndPrint);
delete WndPrint;
}
void TApp::evFileNew(char* listfile)
{
char title[230];
sprintf(title,"” ©« %s",Path);
WndList=new WList(Path,title);
deskTop->execView(WndList);
delete WndList;
}
void TApp::evFileAdd()
{
char buf[100];
TFileDialog* fd=new TFileDialog("*.lst","à¨á®¥¤¨¨âì «¨áâ",0,fdOpenButton,0);
if (deskTop->execView(fd)==cmFileOpen) {
fd->getFileName(buf);
fappend(Path,buf);
};
delete fd;
}
void TApp::evFileOpen()
{
TFileDialog* fd=new TFileDialog("*.lst","Žâªàëâì «¨áâ",0,fdOpenButton,0);
if (deskTop->execView(fd)==cmFileOpen) {
fd->getFileName(Path);
};
delete fd;
evFileNew(Path);
}
void TApp::evHelpAbout()
{
TRect r(20,5,52,17);
TDialog *pd = new TDialog( r, "Ž à®£à ¬¬¥" );
if( pd )
{
pd->insert( new TButton( TRect( 11, 9, 21, 11 ), "~O~K", cmOK,
bfNormal ));
pd->insert( new TStaticText( TRect( 4, 2, 30, 3), "¥¤ ªâ®à ã⥢ëå ‹¨á⮢"));
pd->insert( new TStaticText( TRect( 6, 3, 30, 4), "release 1 - complete"));
pd->insert( new TStaticText( TRect( 4, 4, 25, 5), " 15.05.2000"));
pd->insert( new TStaticText( TRect( 4, 5, 30, 6), "€«¥ªá¥© 'Necro' Šãà¤îª®¢"));
pd->insert( new TStaticText( TRect( 4, 6, 30, 7), "£.Š¥¬¥à®¢®, â.616-979"));
pd->insert( new TStaticText( TRect( 2, 7, 30, 8),CFG.OrgName));
deskTop->execView(pd);
}//if
destroy( pd );
}
void TApp::evSettingsCFG()
{
WndSettings=new WSettings(CFG);
deskTop->execView(WndSettings);
delete WndSettings;
}
void TApp::evSettingsNum()
{
TDialog*WNum=new TDialog(TRect(20,10,60,15),"®¬¥à «¨áâ ");
TInputLine*num=new TInputLine(TRect(25,2,32,3),3);
WNum->insert(new TButton(TRect(32,2,38,4),"OK",cmCancel,0));
WNum->insert(num);
WNum->insert(new TLabel(TRect(2,2,25,3),"‚¢¥¤¨â¥ ®¢ë© ®¬¥à:",num));
sprintf(num->data,"%02d",CFG.Seed);
deskTop->execView(WNum);
sscanf(num->data,"%d",&CFG.Seed);
delete WNum;
}
void TApp::evBaseDriver()
{
WDriver *d=new WDriver();
deskTop->execView(d);
delete d;
}
void TApp::evBaseCar()
{
WCar *c=new WCar();
deskTop->execView(c);
delete c;
}
void TApp::evBasePath()
{
WPath*p=new WPath();
deskTop->execView(p);
delete p;
}
/* WSettings */
WSettings::WSettings(TConfig cfg): TDialog(TRect(15,0,70,23)," áâனª¨"),
TWindowInit( &WSettings::initFrame)
{
iDBase=new TInputLine(TRect(35,2,50,3),13);
iCBase=new TInputLine(TRect(35,4,50,5),13);
iPBase=new TInputLine(TRect(35,6,50,7),13);
iListFile=new TInputLine(TRect(35,8,50,9),13);
iTempFile=new TInputLine(TRect(35,10,50,11),13);
iPrnDevice=new TInputLine(TRect(35,12,50,13),13);
iSeed=new TInputLine(TRect(35,14,50,15),3);
cbIsAbout=new TCheckBoxes(TRect(2,16,50,17),new TSItem("®ª §ë¢ âì AboutBox ¯à¨ § ¯ã᪥",0) );
cbPrintDate=new TCheckBoxes(TRect(2,17,50,18),new TSItem("¥ç â âì «¨áâ å ¤ âã",0) );
//inserts all of these ctrls:
insert(iDBase);
insert(iCBase);
insert(iPBase);
insert(iListFile);
insert(iTempFile);
insert(iPrnDevice);
insert(iSeed);
//attach input lines to the labels & create buttons:
insert(new TButton(TRect(19,20,32,22),"Žâ¬¥ ",cmCancel,bfNormal));
insert(cbIsAbout);
insert(cbPrintDate);
insert(new TButton(TRect(3,20,16,22),"OK",cmnSaveCFG,bfNormal));
insert(new TLabel(TRect(1,6,28,7),"ˆ¬ï ä ©« ¡ §ë ¬ àèàã⮢:",iPBase));
insert(new TLabel(TRect(1,4,28,5),"ˆ¬ï ä ©« ¡ §ë ¬ è¨:",iCBase));
insert(new TLabel(TRect(1,2,28,3),"ˆ¬ï ä ©« ¡ §ë ¢®¤¨â¥«¥©:",iDBase));
insert(new TLabel(TRect(1,8,28,9),"Š â «®£ ¤«ï ¯ã⥢ëå «¨á⮢:",iListFile));
insert(new TLabel(TRect(1,10,28,11),"‚६¥ë© ä ©«:",iTempFile));
insert(new TLabel(TRect(1,12,28,13),"“áâனá⢮ ¯¥ç â¨:",iPrnDevice));
insert(new TLabel(TRect(1,14,28,15)," ç «ìë© ®¬¥à (2 § ª ):",iSeed));
SetState(cfg);
}
WSettings::~WSettings()
{
}
void WSettings::GetState(TConfig&cfg)
{
cfg.size=sizeof(cfg);
strcpy(cfg.DriverBase,iDBase->data);
strcpy(cfg.CarBase,iCBase->data);
strcpy(cfg.PathBase,iPBase->data);
strcpy(cfg.ListDir,iListFile->data);
strcpy(cfg.TempFile,iTempFile->data);
strcpy(cfg.PrnDevice,iPrnDevice->data);
sscanf(iSeed->data,"%d",&(cfg.Seed));
strcpy(cfg.STRING,"I need Nastya...");
strcpy(cfg.Copyright,"Necro,2000");
strcpy(cfg.GetOut,"—¥£® ãáâ ¢¨«áï?!");
strcpy(cfg.OrgName,"€’– Š¥¬¥à®¢áª®£® ¯®çâ ¬â â.28-80-64");
cfg.DisplayAboutBox=cbIsAbout->mark(0);
cfg.PrintDate=cbPrintDate->mark(0);
}
void WSettings::SetState(TConfig cfg)
{
if (cfg.size!=sizeof(cfg)) messageBox(mfWarning|mfOKButton,"Žè¨¡ª ¢ ä ©«¥ áâனª¨ %s",cfgName);
strcpy(iDBase->data,cfg.DriverBase);
strcpy(iCBase->data,cfg.CarBase);
strcpy(iPBase->data,cfg.PathBase);
strcpy(iListFile->data,cfg.ListDir);
strcpy(iTempFile->data,cfg.TempFile);
strcpy(iPrnDevice->data,cfg.PrnDevice);
sprintf(iSeed->data,"%02d",cfg.Seed);
if (cfg.DisplayAboutBox) cbIsAbout->press(0);
if (cfg.PrintDate) cbPrintDate->press(0);
redraw();
}
void WSettings::handleEvent(TEvent&event)
{
TDialog::handleEvent(event); // act like base!
if( event.what == evCommand )
{
switch( event.message.command )
{
case cmnSaveCFG:
evSaveCFG();
break;
default:
return;
}//switch
clearEvent( event ); // clear event after handling
}//if