This repository has been archived by the owner on Dec 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExpired.c
240 lines (227 loc) · 5.42 KB
/
Expired.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
#include "Expired.h"
#include "addNewMedicine.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
int leapYear(int in)
{
for(int i=1; i<in-1; i++)
{
if(i%400==0)
{
//leap Year
return 1;
}
else if(i%4==0&&i% 100 !=0)
{
return 1;
//leap Year
}
else
{
return 0;
// non leap year
}
}
}
int daysCount(int dd,int mm,int yy)
{
int n2=0;
for(int i=1; i<yy-1; i++)
{
if(leapYear(i)==1)
{
n2+=366;
}
else
{
n2+=365;
}
}
int ly[12]= {31,29,31,30,31,30,31,31,30,31,30,31};
int nly[12]= {31,28,31,30,31,30,31,31,30,31,30,31};
if(leapYear(yy)==1)
{
for(int i=0; i<mm-1; i++)
{
n2 += ly[i];
}
n2 += dd;
}
else
{
for(int i=0; i<mm-1; i++)
{
n2 += nly[i];
}
n2+=dd;
}
return n2;
}
int days(int d1,int m1, int y1,int d2,int m2,int y2)
{
int d=daysCount(d2,m2,y2)-daysCount(d1,m1,y1);
return d;
}
void expiredTable(){
gotoxy(26,3);
printf("EXPIRY REMAINING DAYS");
gotoxy(25,5);
for(int i=1; i<=23; i++)
{
printf("%c",223);
}
gotoxy(2,6);
for(int i=1; i<=75; i++)
{
printf("%c",196);
}
for(int j=0; j<4; j++)
{
for(int i=0; i<=60; i+=12)
{
gotoxy(17+i,6+j);
printf("%c",179);
}
}
for(int j=0; j<4; j++)
{
gotoxy(2,6+j);
printf("%c",179);
}
gotoxy(8,7);
printf("Name");
gotoxy(20,7);
printf("Address");
gotoxy(31,7);
printf("ExpiryDate");
gotoxy(45,7);
printf("Price");
gotoxy(55,7);
printf("Quantity");
gotoxy(69,7);
printf("Days");
gotoxy(2,9);
for(int i=1; i<=75; i++)
{
printf("%c",196);
}
}
void sort(int *a,int line){
int temp;
for(int i=0;i<6;i++){
for(int j=0;j<6-i;j++){
if(a[j]>a[j+1]){
temp =a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
void ExpiredFile()
{
int daysRemaining;
char date1[12];
int day2, month2, year2;
int day1, month1, year1;
char m1[3],y1[5];
int lineCount=0;
int arr[20];
//Today Date
time_t now;
time(&now);
struct tm *local = localtime(&now);
day2 = local->tm_mday; // get day of month (1 to 31)
month2 = local->tm_mon + 1; // get month of year (0 to 11)
year2 = local->tm_year + 1900; // get year since 1900
FILE *fp;
FILE *fpex;
fp=fopen("Medicine.DAT","r");
fpex=fopen("Expired.DAT","w");
if(fp==NULL||fpex==NULL)
{
gotoxy(10,10);
printf("List not found OR List is Empty...!");
Sleep(3000);
main();
}
int i=0;
while(fscanf(fp,"%s %s %s %f %i %s\n",temp.MedName,temp.expiryDate,temp.manufactureDate,&temp.price,&temp.quantity,temp.racks)!=EOF)
{
strncpy(date1,temp.expiryDate,10);
day1=atoi(date1);
for(int i=0; i<2; i++)
{
m1[i]=date1[i+3];
}
month1=atoi(m1);
for(int i=0; i<4; i++)
{
y1[i]=date1[i+6];
}
year1=atoi(y1);
daysRemaining=days(day2,month2,year2,day1,month1,year1);
if(daysRemaining<0){
daysRemaining=0;
}
arr[lineCount]=daysRemaining;
fprintf(fpex,"%s %s %d %f %d %s\n",temp.MedName,temp.expiryDate,daysRemaining,temp.price,temp.quantity,temp.racks);
lineCount++;
}
fclose(fpex);
fclose(fp);
//
FILE *fpexp;
//FILE *fpsort;
fpexp = fopen("Expired.DAT","r");
// fpsort =fopen("temp.DAT","r");
// int counter=0;
// while(fscanf(fpexp,"%s %s %d %f %d %s\n",temp.MedName,temp.expiryDate,&daysRemaining,&temp.price,&temp.quantity,temp.racks)!=EOF)
// {
// gotoxy(7,10+counter);
// printf("%s",temp.MedName);
// gotoxy(20,10+counter);
// printf("%s",temp.racks);
// gotoxy(30,10+counter);
// printf("%s",temp.expiryDate);
// gotoxy(45,10+counter);
// printf("%.2f",temp.price);
// gotoxy(57,10+counter);
// printf("%d",temp.quantity);
// gotoxy(70,10+counter);
// printf("%d",daysRemaining);
// counter++;
// }
sort(arr,lineCount);
// if(getche())
// {
// main();
// }
int counter=0;
for(int i=0;i<lineCount;i++){
rewind(fpexp);
while(fscanf(fpexp,"%s %s %d %f %d %s\n",temp.MedName,temp.expiryDate,&daysRemaining,&temp.price,&temp.quantity,temp.racks)!=EOF)
{
if(arr[i]==daysRemaining){
gotoxy(7,10+counter);
printf("%s",temp.MedName);
gotoxy(20,10+counter);
printf("%s",temp.racks);
gotoxy(30,10+counter);
printf("%s",temp.expiryDate);
gotoxy(45,10+counter);
printf("%.2f",temp.price);
gotoxy(57,10+counter);
printf("%d",temp.quantity);
gotoxy(70,10+counter);
printf("%d",daysRemaining);
counter++;
}
}
}
if(getche())
{
main();
}
}