-
Notifications
You must be signed in to change notification settings - Fork 0
/
calender.c
1050 lines (901 loc) · 31.6 KB
/
calender.c
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
#include<stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#define MAX_EVENTS 10 //Events Max
#define MAX_DESCRIPTION 100 // 100 Description Max
int shamsiyear,shamsimonth,shamsiday;
int shamsi_now_year,shamsi_now_month,shamsi_now_day;
char key;
typedef struct{
int shamsiday;
int shamsimonth;
int shamsiyear;
char title_event[MAX_DESCRIPTION];
char description_event[MAX_DESCRIPTION]; //event description
}event;
event list[MAX_EVENTS];
int task_index = 0;
int event_index =0;
int selection = 0;
char file[FILENAME_MAX];
char temp[20];
int miladi_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *miladi_month[]={
" ","\n\n\nJanuary","\n\n\nFebruary","\n\n\nMarch","\n\n\nApril","\n\n\nMay","\n\n\nJune",
"\n\n\nJuly","\n\n\nAugust","\n\n\nSeptember","\n\n\nOctober","\n\n\nNovember","\n\n\nDecember"
};
int shamsi_day[]={0,31,31,31,31,31,31,30,30,30,30,30,29};
char *shamsi_month[]={
" ","\n\n\nFarvardin","\n\n\nOrdibehesht","\n\n\nKhordad","\n\n\nTir","\n\n\nMordad","\n\n\nShahrivar",
"\n\n\nMehr","\n\n\nAban","\n\n\nAzar","\n\n\nDey","\n\n\nBahman","\n\n\nEsfand"
};
int inputyear(void)
{
int year;
printf("Please enter a year : ");
scanf("%d", &year);
return year;
}
int determine_miladi_daycode(int year)//starting day of month
{
int daycode;
int day1, day2, day3;
day1 = (year - 1.0)/ 4.0;
day2 = (year - 1.0)/ 100.0;
day3 = (year - 1.0)/ 400.0;
daycode = (year + day1 - day2 + day3) %7;
return daycode;
}
int determine_miladi_year(int year)//kabise or not
{
if(year% 4 == 0 && year%100 != 0 || year%400 == 0){//1996,2000:kabise
miladi_day[2] = 29;//February has 29 days
return 1;
}
else{
miladi_day[2] = 28;//February has 28 days
return 0;
}
}
int determine_shamsi_year(int year){
int reminder = year/33;
if(reminder== 1 || 5 || 9 || 13 || 17 || 22 || 26 ||30){//kabise
shamsi_day[12] = 30;
}
}
void miladi_calendar(int year, int daycode)
{
int month, day;
for ( month = 1; month <= 12; month++ )
{
printf("%s", miladi_month[month]);
printf("\n\nSun Mon Tue Wed Thu Fri Sat\n" );
for ( day = 1; day <= 1 + daycode * 5; day++ )//first date
{
printf(" ");
}
for ( day = 1; day <= miladi_day[month]; day++ )
{
printf("%2d", day );
if ( ( day + daycode ) % 7 > 0 ){// before Sat
printf(" " );
}
else{
printf("\n " );//next line
}
}
daycode = ( daycode + miladi_day[month] ) % 7;// next month
}
}
void shamsi_calender(int year,int daycode)//1 farvardin 98-21 march 2019
{
int month, day;
for ( month = 1; month <= 12; month++ )
{
printf("%s",shamsi_month[month]);
printf("\n\n1sh 2sh 3sh 4sh 5sh jom sha\n" );
for ( day = 1; day <= 1 + daycode * 5; day++ )//first date
{
printf(" ");
}
for ( day = 1; day <= shamsi_day[month]; day++ )// month
{
printf("%2d", day );
if ( ( day + daycode ) % 7 > 0 ){
printf(" " );
}
else{
printf("\n " );
}
}
daycode = ( daycode + shamsi_day[month] ) % 7;// next month
}
}
void print_day(int day)
{
switch( day % 7 ){
case 0:
printf("Friday");
break;
case 1:
printf("Saturday");
break;
case 2:
printf("Sunday");
break;
case 3:
printf("Monday");
break;
case 4:
printf("Tuesday");
break;
case 5:
printf("Wednesday");
break;
case 6:
printf("Thursday");
break;
}
return;
}
int now_time_miladi(void){
int now_year,now_month,now_day;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
now_year = tm.tm_year + 1900;
now_month = tm.tm_mon + 1;
now_day = tm.tm_mday;
printf("now: %d-%02d-%02d %02d:%02d:%02d\n",now_year,now_month,now_day,tm.tm_hour,tm.tm_min,tm.tm_sec);
}
int now_time_shamsi(void){
int now_year,now_month,now_day;//miladi
int leapyear,shamsi_past_day;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
now_year = tm.tm_year + 1900;
now_month = tm.tm_mon + 1;
now_day = tm.tm_mday;
if(now_year% 4 == 0 && now_year%100 != 0 || now_year%400 == 0){
leapyear=1;
}
else{
leapyear=0;
}
switch (now_month){
case 1:{
break;
}
case 2:{
now_day=31+now_day+leapyear;
break;
}
case 3:{
now_day=31+28+leapyear+now_day;
break;
}
case 4:{
now_day=31+28+leapyear+31+now_day;
break;
}
case 5:{
now_day=31+28+leapyear+31+30+now_day;
break;
}
case 6:{
now_day=31+28+leapyear+31
+30+31+now_day;
break;
}
case 7:{
now_day=31+28+leapyear+31+30+31+30+now_day;
break;
}
case 8:{
now_day=31+28+leapyear+31+30+31+30+31+now_day;
break;
}
case 9:{
now_day=31+28+leapyear+31+30+31+30+31+31+now_day;
break;
}
case 10:{
now_day=31+28+leapyear+31+30+31+30+31+31+30+now_day;
break;
}
case 11:{
now_day=31+28+leapyear+31+30+31+30+31+31+30+31+now_day;
break;
}
case 12:{
now_day=31+28+leapyear+31+30+31+30+31+31+30+31+30+now_day;
break;
}
}
shamsi_past_day=now_day+286;
int past_month;
if(shamsi_past_day<=186){//first six month
past_month=shamsi_past_day /31;
shamsi_now_month=past_month+1;
shamsi_now_day=shamsi_past_day %31;
}
if(shamsi_past_day>186){//last six month
past_month=( shamsi_past_day-(6*31) ) /30;
shamsi_now_month=past_month+6+1;
shamsi_now_day=(shamsi_past_day-186) %30;
}
shamsi_now_year=now_year - (621+leapyear);
printf("now: %d-%02d-%02d %02d:%02d:%02d\n",shamsi_now_year,shamsi_now_month,(shamsi_now_day)-1,tm.tm_hour,tm.tm_min,tm.tm_sec);
}
//event
void print_events() {
puts("+---------EVENT---------+\n"
"| 1. New Event |\n"
"| 2. Delete Event |\n"
"| 3. Edit Event |\n"
"| 4. Display Schedule |\n"
"| 5. Exit |\n"
"+-----------------------+\n");
}
event *Eventmemory() {
event *e = (event*)malloc(sizeof(event));//new event in e memory
e->shamsiday =0;
e->shamsimonth =0;
e->shamsiyear =0;
strcpy(e->description_event, "");
return e;
}
event* newEvent(event *e) {
puts("\n+--- EVENT TITLE ---+");
printf("%s", "| Enter a title : ");
fgets(e->title_event, MAX_DESCRIPTION, stdin);
puts("\n+--- EVENT DESCRIPTION ---+");
printf("%s", "| Enter a description: ");
fgets(e->description_event, MAX_DESCRIPTION, stdin);
puts("+-------------------------+\n");
e->shamsiyear = shamsiyear;
e->shamsimonth = shamsimonth;
e->shamsiday = shamsiday;
printf("| Event added in %2d / %2d / %2d.\n", e->shamsiyear,e->shamsimonth,e->shamsiday);
return e;
}
void addEventAtIndex(event list[], const event e, const int i) {
list[i].shamsiyear = e.shamsiyear;
list[i].shamsimonth = e.shamsimonth;
list[i].shamsiday = e.shamsiday;
strcpy(list[i].title_event, e.title_event);
strcpy(list[i].description_event, e.description_event);
}
void sort(event list[], const int size) {//swapping struct
for (int i = 1; i < size; i++) {
for (int j = i; j > 0 && (list[j - 1].shamsimonth >= list[j].shamsimonth && list[j - 1].shamsiday >= list[j].shamsiday); j--) {
int tmpshamsimonth = list[j].shamsimonth;
int tmpshamsiday = list[j].shamsiday;
char tmpdescription[MAX_DESCRIPTION];
strcpy(tmpdescription, list[j].description_event);
char tmptitle_event[MAX_DESCRIPTION];
strcpy(tmptitle_event, list[j].title_event);
int tmpshamsimonth1 = list[j - 1].shamsimonth;
int tmpshamsiday1 = list[j - 1].shamsiday;
char tmpdescription1[MAX_DESCRIPTION];
strcpy(tmpdescription1, list[j - 1].description_event);
char tmptitle_event1[MAX_DESCRIPTION];
strcpy(tmptitle_event1, list[j-1].title_event);
list[j].shamsimonth = tmpshamsimonth1;
list[j].shamsiday = tmpshamsiday1;
strcpy(list[j].description_event, tmpdescription1);
strcpy(list[j].title_event, tmptitle_event1);
list[j - 1].shamsimonth = tmpshamsimonth;
list[j - 1].shamsiday = tmpshamsiday;
strcpy(list[j - 1].description_event, tmpdescription);
strcpy(list[j-1].title_event,tmptitle_event);
}
}
}
void sortInsert(event list[], int *size, event e) {// Add event to event list
addEventAtIndex(list, e, *size); // end of the list
(*size)++;
// Sort
sort(list, *size);
}
void printEvent(const event e) {
printf("%s",e.title_event);
printf("%s",e.description_event);
}
void printEventList(const event list[], const int size,int year,int month,int day) {
char *line = "+-----------------------------------------------+";
printf("%s\n",line);
if (size == 0) {
puts("\n| You have no events!\n");
return;
}
for (int i = 0; i < size; i++) {
if(list[i].shamsiyear==year && list[i].shamsimonth==month && list[i].shamsiday==day){
printf("| [%d] ", i);
printEvent(list[i]);
}
}
putchar('\n');
}
void deleteEvent(event list[], int *size) {
if (*size == 0) { //empty
puts("\n| Event list already empty.\n");
return;
}
char temp[21];
int id;
char *line = "\n+--------------------------------+";
printf("%s\n| DELETE EVENT |%s\n\n", line, line);
for (int i = 0; i < *size; i++) { //event list
printf("| [%d] ", i);
printEvent(list[i]);
}
printf("%s", "\n| Enter the ID of an event to delete: ");
fgets(temp, 21, stdin);
id = atoi(temp);
if (id > *size - 1) {
printf("\n| No event located at %d\n", id);
return;
}
printf("| Event [%d] deleted successfully.\n\n", id);
if (id != (*size - 1)) { //the last event deleted
sort(list, *size);
}
(*size)--; //size of the list
}
void editevent(event list[], int *size){
if (*size == 0) { //empty
puts("\n| Event list already empty.\n");
return;
}
char temp[21];
int id;
char *line = "\n+--------------------------------+";
printf("%s\n| EDIT EVENT |%s\n\n", line, line);
for (int i = 0; i < *size; i++) { //event list
printf("| [%d] ", i);
printEvent(list[i]);
}
printf("%s", "\n| Enter the ID of an event to edit: ");//delet
fgets(temp, 21, stdin);
id = atoi(temp);//convert string to int
if (id > *size - 1) {
printf("\n| No event located at %d\n", id);
return;
}
if (id != (*size - 1)) { //the last event deleted
sort(list, *size);
}
(*size)--; //size of the list
id=id-1;
sortInsert(list, &(id), *newEvent(&list[id]));//new event
printf("| Event [%d] edited successfully.\n\n", id);
}
int search(const event e, char searchevent[]){
if (strstr(e.title_event, searchevent) != NULL)
{
printf("\n %d//%d//%d: %s, %s", e.shamsiyear, e.shamsimonth, e.shamsiday, e.title_event, e.description_event);
Sleep(2000);
return 1;
}
else
return 0;
}
//task
typedef struct{
int shamsiday;
int shamsimonth;
int shamsiyear;
char title_task[MAX_DESCRIPTION];
char description_task[MAX_DESCRIPTION];
char done[100];//DONE OR NOT
}task;
task list_task[MAX_EVENTS];
void print_tasks(){
puts("+---------TASK---------+\n"
"| 1. New Task |\n"
"| 2. Delete Task |\n"
"| 3. Edit Task |\n"
"| 4. Display Schedule |\n"
"| 5. Done ? |\n"
"| 6. Exit |\n"
"+-----------------------+\n");
}
task *Taskmemory() {
task *t = (task*)malloc(sizeof(task));//new task in e memory
t->shamsiday =0;
t->shamsimonth =0;
t->shamsiyear =0;
strcpy(t->description_task, "");
strcpy(t->done, "");
return t;
}
task* newTask(task *t) {
puts("\n+--- TASK TITLE ---+");
printf("%s", "| Enter a title : ");
fgets(t->title_task, MAX_DESCRIPTION, stdin);
puts("\n+--- TASK DESCRIPTION ---+");
printf("%s", "| Enter a description: ");
fgets(t->description_task, MAX_DESCRIPTION, stdin);
puts("+-------------------------+\n");
printf("| Task added in %2d / %2d / %2d.\n",shamsiyear,shamsimonth,shamsiday);
return t;
}
void addTaskAtIndex(task list[], const task t, const int i) {
list_task[i].shamsiyear = t.shamsiyear;
list_task[i].shamsimonth = t.shamsimonth;
list_task[i].shamsiday = t.shamsiday;
strcpy(list_task[i].title_task, t.title_task);
strcpy(list_task[i].description_task, t.description_task);
strcpy(list_task[i].done, t.done);
}
void sorttask(task list_task[], const int size) {
for (int i = 1; i < size; i++) {
for (int j = i; j > 0 && (list_task[j - 1].shamsimonth >= list_task[j].shamsimonth && list_task[j - 1].shamsiday >= list_task[j].shamsiday); j--) {
int tmpshamsimonth = list_task[j].shamsimonth;
int tmpshamsiday = list_task[j].shamsiday;
char tmpdescription[MAX_DESCRIPTION];
strcpy(tmpdescription, list_task[j].description_task);
char tmptitle_task[MAX_DESCRIPTION];
strcpy(tmptitle_task, list_task[j].title_task);
int tmpshamsimonth1 = list_task[j - 1].shamsimonth;
int tmpshamsiday1 = list_task[j - 1].shamsiday;
char tmpdescription1[MAX_DESCRIPTION];
strcpy(tmpdescription1, list_task[j - 1].description_task);
char tmptitle_task1[MAX_DESCRIPTION];
strcpy(tmptitle_task1, list_task[j-1].title_task);
list_task[j].shamsimonth = tmpshamsimonth1;
list_task[j].shamsiday = tmpshamsiday1;
strcpy(list_task[j].description_task, tmpdescription1);
strcpy(list_task[j].title_task, tmptitle_task1);
list_task[j - 1].shamsimonth = tmpshamsimonth;
list_task[j - 1].shamsiday = tmpshamsiday;
strcpy(list_task[j - 1].description_task, tmpdescription);
strcpy(list_task[j-1].title_task,tmptitle_task);
}
}
}
void sortInsert_task(task list_task[], int *size, task t) {// Add task to event list
addTaskAtIndex(list_task, t, *size); // end of the list
(*size)++;
// Sort
sorttask(list_task, *size);
}
void printTask(const task t) {
printf("%s",t.title_task);
printf("%s",t.description_task);
}
void printdone(const task t){
printf("%s\n",t.done);//DONE OR NOT
}
void printTaskList(const task list_task[], const int size,int year,int month,int day) {
char *line = "+-----------------------------------------------+";
printf("%s\n",line);
if (size == 0) {
puts("\n| You have no tasks!\n");
return;
}
for (int i = 0; i < size; i++) {
//if(list_task[i].shamsiyear==year && list_task[i].shamsimonth==month && list_task[i].shamsiday==day){
printdone(list_task[i]);
printf("| [%d] ", i);
printTask(list_task[i]);
//}
}
putchar('\n');
}
void deleteTask(task list_task[], int *size) {
if (*size == 0) { //empty
puts("\n| Event list already empty.\n");
return;
}
char temp[21];
int id;
char *line = "\n+--------------------------------+";
printf("%s\n| DELETE TASK |%s\n\n", line, line);
for (int i = 0; i < *size; i++) {
printf("| [%d] ", i);
printTask(list_task[i]);
}
printf("%s", "\n| Enter the ID of an task to delete: ");
fgets(temp, 21, stdin);
id = atoi(temp);
if (id > *size - 1) {
printf("\n| No task located at %d\n", id);
return;
}
printf("| Task [%d] deleted successfully.\n\n", id);
if (id != (*size - 1)) { //the last task deleted
sorttask(list_task, *size);
}
(*size)--; //size of the list
}
void edittask(task list_task[], int *size){
if (*size == 0) { //empty
puts("\n| Task list already empty.\n");
return;
}
char temp[21];
int id;
char *line = "\n+--------------------------------+";
printf("%s\n| DELETE TASK |%s\n\n", line, line);
for (int i = 0; i < *size; i++) {
printf("| [%d] ", i);
printTask(list_task[i]);
}
printf("%s", "\n| Enter the ID of an task to edit: ");//delet
fgets(temp, 21, stdin);
id = atoi(temp);
if (id > *size - 1) {
printf("\n| No task located at %d\n", id);
return;
}
if (id != (*size - 1)) { //the last task deleted
sort(list, *size);
}
(*size)--; //size of the list
id=id-1;
printf("| Event [%d] edited successfully.\n\n", id);
}
void donetask(task list_task[],int *size){
if (*size == 0) { //empty
puts("\n| Task list already empty.\n");
return;
}
char temp[21];
int id;
for (int i = 0; i < *size; i++) { //task list
printf("| [%d] ", i);
printTask(list_task[i]);
}
printf("%s", "\n| Enter the ID of an task that have done: ");
fgets(temp, 21, stdin);
id = atoi(temp);
if (id > *size - 1) {
printf("\n| No task located at %d\n", id);
return;
}
strcpy(list_task[id].done,"Done!");
printf("| Task [%d] done successfully.\n\n", id);
}
void saveList(char *filename, event list[],task list_task[], int size,int size1) {
FILE *f = fopen(filename, "w");
if (f == NULL) {
return;
}
for (int i = 0; i < size; i++) {
fprintf(f, "%d %d %s", list[i].shamsiyear, list[i].shamsiday, (list[i].description_event));
}
for(int i=0 ;i<size1;i++){
fprintf(f, "%d %d %s", list_task[i].shamsiyear, list_task[i].shamsiday, list_task[i].description_task);
}
printf("\n| %d %s successfully saved into \"%s\".\n\n", size, "events and tasks", filename);
fclose(f);
}
void loadList(char *filename, event list[]) {
int size = 1024, pos;
int c;
char *buffer = (char *)malloc(size);
FILE *f = fopen(filename, "r");
if(f) {
do { // read all lines
int pos = 0;
do{ // read one line
c = fgetc(f);
if(c != EOF) {//to end
buffer[pos++] = (char)c;
printf("%s", buffer[pos-1]);
}
if(pos >= size - 1) { // increase buffer length - leave room for 0
size *=2;
buffer = (char*)realloc(buffer, size);
}
}while(c != EOF && c != '\n');
buffer[pos] = 0;
} while(c != EOF);
fclose(f);
getche();
}
free(buffer);
}
//
void calender (void){//shamsi
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_BLUE);
int month, day;
char *day_code;
month=shamsimonth - 1;// 1 farvardin 98 5shanbe
if(shamsimonth <= 6){//firs six month
day=( (month*6)+shamsiday )%7;
}
if(shamsimonth > 6){
day=( (6*31)+(month-6)*30+shamsiday )%7;
}
switch(day){
case 0:{
day_code="4Shanbe";
break;
}
case 1:{
day_code="5Shanbe";
break;
}
case 2:{
day_code="Jomeh";
break;
}
case 3:{
day_code="Shanbe";
break;
}
case 4:{
day_code="1Shanbe";
break;
}
case 5:{
day_code="2Shanbe";
break;
}
case 6:{
day_code="3Shanbe";
break;
}
}
printf("\n\n\t\t %02d / %02d / %02d \n\n\t\t",shamsiyear,shamsimonth,shamsiday);
printf("\n\t\t %s\n",day_code);
printEventList(list, event_index,shamsiyear,shamsimonth,shamsiday);
printTaskList(list_task, task_index,shamsiyear,shamsimonth,shamsiday);
}
char menu(void){
putchar('\n');
printf("Menu\n\n");
printf("1. Shamsi schedule\n");
printf("2. Miladi calender in one year\n");
printf("3. Shamsi calender in one year\n");
printf("4. Search event date\n");
Sleep(2000);
key=getchar();
while (key == '\n'){
key=getchar();
}
return key;
}
int main(void){
menu();
now_time_shamsi();
shamsiyear=shamsi_now_year;//first time
shamsimonth=shamsi_now_month;
shamsiday=shamsi_now_day -1;
system("cls");
while(1){
if(key == '1'){//tasks and events in shamsi calender
char press;
while(press!='M'){
putchar('\n');
now_time_shamsi();//shamsi_now_year,shamsi_now_month,shamsi_now_day//TODAY
calender();//shamsiyear,shamsimonth,shamsiday//CHANGE
printf("\n");
printf("+----------------------------------------------+\n");
printf("\n\t(*) Press N to go to next day.");
printf("\n\t(*) Press P to go to previous day.");
printf("\n\t(*) Press Y to go to next year.");
printf("\n\t(*) Press E to show event list.");
printf("\n\t(*) Press T to show task list.");
printf("\n\t(*) Press S to search or jump to date.");
printf("\n\t(*) Press M to show menu.");
printf("\n\t(*) Press F for save to File.");
printf("\n\t(*) Press L to load File\n.");
printf("+----------------------------------------------+\n");
Sleep(3000);
press=getchar();
switch(press){
case 'N':{//NEXT DAY
if(shamsimonth<=6){//31 days
if(shamsiday<31){
shamsiday++;
}
else{
shamsimonth++;
shamsiday=1;
}
}
else if(shamsimonth>6){//30 days
if(shamsiday<30){
shamsiday++;
}
else{
shamsimonth++;
shamsiday=1;
}
}
break;
}
case 'P':{//previous day
shamsiday--;
if(shamsiday==0){
shamsimonth--;
if(shamsimonth<=6){
shamsiday=31;
}
else{
shamsiday=30;
}
}
break;
}
case 'M':{
menu();
break;
}
case 'S':{//SEARCH BY DATE
printf("Enter the year: ");
scanf("%d",&shamsiyear);
printf("Enter the month: ");
scanf("%d",&shamsimonth);
printf("Enter the day: ");
scanf("%d",&shamsiday);
break;
}
case 'L':{
char filename[20];
printf("%s", "| Please enter a \"filename.txt\": ");
scanf("%s",&filename);
loadList(filename, list);
break;
}
case 'Y':{//next year
shamsiyear++;
determine_shamsi_year(shamsiyear);//kabise year or not
break;
}
case'F':{
if ((event_index) + (task_index) == 0) {
puts("| You have no schedule!\n");
}
else {
printf("%s", "| Please enter a \"filename.txt\": ");
scanf("%20s",&file);
//fgets(file, FILENAME_MAX, stdin);
strtok(file, "\n");
saveList(file, list,list_task, event_index,task_index);
}
break;
}
case 'E':{//new-edit-delet-file
while (selection != 5) {
print_events(); // Print the event menu
printf("%s", "| Please select an option: ");
Sleep(3000);
fgets(temp, 21, stdin);
selection = atoi(temp); //string to int
switch (selection) {
case 1:{ // New Event
if (event_index + 1 >MAX_EVENTS) {
printf("| You can have %d events at one time!\n\n",event_index);
break;
}
sortInsert(list, &event_index, *newEvent(&list[event_index]));//memory
break;
}
case 2:{ // Delete Event
deleteEvent(list, &event_index);
break;
}
case 3:{//edit event
editevent(list,&event_index);
break;
}
case 4:{ // Schedule
printEventList(list,event_index,shamsiyear,shamsimonth,shamsiday);
break;
}
case 5: {// Exit
puts("\n| Thank you!\n");
break;
}
default: {// Error
puts("\n| Error in selection\n");
break;
}
}
}
system("cls");
break;
}
case 'T':{//task:new-edit-delet-DONE
while (selection != 6) {//out
print_tasks(); // Print the task menu
printf("%s", "| Please select an option: ");
Sleep(3000);
fgets(temp, 21, stdin);
selection = atoi(temp); //string to int
switch (selection) {
case 1:{ // New Event
if (task_index + 1 > MAX_EVENTS) {
printf("| You can have %d tasks at one time!\n\n", task_index);
break;
}
sortInsert_task(list_task, &task_index, *newTask(&list_task[task_index]));//memory
break;
}
case 2:{ // Delete
deleteTask(list_task, &task_index);
break;
}
case 3:{//edit
edittask(list_task,&task_index);
break;
}
case 4:{ // Schedule
printTaskList(list_task,task_index,shamsiyear,shamsimonth,shamsiday);
break;
}
case 5:{//done
donetask(list_task,&task_index);
break;
}
case 6: {// Exit
puts("\n| Thank you!\n");
break;
}
default: {// Error
puts("\n| Error in selection\n");
break;
}
}
}
system("cls");
}
}
Sleep(1000);
system("cls");
}