-
Notifications
You must be signed in to change notification settings - Fork 2
/
HMSC.c
407 lines (381 loc) · 10.3 KB
/
HMSC.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
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
void add(); //FUNCTIONS
void list();
void edit(); //GLOBALLY DECLARED FUNCTIONS N VARIABLE
void delete1();
void search();
void setcolor(int ForgC)
{ WORD wColor;
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut,&csbi))
{
wColor=(csbi.wAttributes & 0xB0)+(ForgC & 0x0B);
// SetConsoleTextAttributes(hStdOut,wColor);
SetConsoleTextAttribute(hStdOut,wColor);
}
}
void login()
{
int a=0,i=0;
char uname[10],c=' ';
char pword[10],code[10];
char user[10]="user";
char pass[10]="pass";
do
{
system("cls");
printf("\n ************************** LOGIN FORM ************************** ");
printf(" \n ENTER USERNAME:-");
scanf("%s", &uname);
printf(" \n ENTER PASSWORD:-");
while(i<10)
{
pword[i]=getch();
c=pword[i];
if(c==13) break;
else printf("*");
i++;
}
pword[i]='\0';
//char code=pword;
i=0;
//scanf("%s",&pword);
if(strcmp(uname,user)==0 && strcmp(pword,pass)==0)
{
printf(" \n\n\n WELCOME !!!! LOGIN IS SUCCESSFUL");
break;
}
else
{
printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL");
a++;
getch();
}
}
while(a<=2);
if (a>2)
{
printf("\nSorry you have entered the wrong username and password for four times!!!");
getch();
}
system("cls");
}
struct CustomerDetails //STRUCTURE DECLARATION
{
char roomnumber[10];
char name[20];
char address[25];
char phonenumber[15];
char nationality[15];
char email[20];
char period[10];
char arrivaldate[10];
}s;
int main(){ // MAIN FUNCTION
int i=0;
time_t t;
time(&t);
char customername;
char choice;
system("cls"); // FOR CLEARING SCREEN
setcolor(15);
printf(" -------------------------------------------------------------------------\n");
printf("| |\n");
printf("| |\n");
printf("| OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO OOOOOO O O OOOOOOO OOOOOO |\n");
printf("| O O O O O O O O O O O O |\n");
printf("| O OOOOO OOOOOO OOOOO OOOOO O O O O O O OOOOO OOOOOO |\n");
printf("| O O O O O O O O O O O O O O |\n");
printf("| OOOOOO O O OOOOOO OOOOOO O OOOOOO O O O OOOOOO OOOOOO |\n");
printf("| |\n");
printf(" -------------------------------------------------------------------------\n");
printf("\t\t*************************************************\n");
printf("\t\t* *\n");
printf("\t\t* ----------------------------- *\n");
printf("\t\t* WELCOME TO HOTEL DESERT CAVE *\n");
printf("\t\t* ----------------------------- *\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t* *\n");
printf("\t\t* Brought To You By code-projects.org *\n");
printf("\t\t* ESP,XYZ *\n");
printf("\t\t* CONTACT US:18-87454575552,035455852 *\n");
printf("\t\t*************************************************\n\n\n");
for(i=0;i<80;i++)
printf("-");
printf("\nCurrent date and time : %s",ctime(&t));
for(i=0;i<80;i++)
printf("-");
printf(" \n Press any key to continue:");
getch();
system("cls");
login();
system("cls");
while (1) // INFINITE LOOP
{
system("cls");
setcolor(10);
for(i=0;i<80;i++)
printf("-");
printf("\n");
printf(" ****************************** |MAIN MENU| ***************************** \n");
for(i=0;i<80;i++)
printf("-");
printf("\n");
setcolor(10);
printf("\t\t *Please enter your choice for menu*:");
printf("\n\n");
printf(" \n Enter 1 -> Book a room");
printf("\n------------------------");
printf(" \n Enter 2 -> View Customer Record");
printf("\n----------------------------------");
printf(" \n Enter 3 -> Delete Customer Record");
printf("\n-----------------------------------");
printf(" \n Enter 4 -> Search Customer Record");
printf("\n-----------------------------------");
printf(" \n Enter 5 -> Edit Record");
printf("\n-----------------------");
printf(" \n Enter 6 -> Exit");
printf("\n-----------------");
printf("\n");
for(i=0;i<80;i++)
printf("-");
printf("\nCurrent date and time : %s",ctime(&t));
for(i=0;i<80;i++)
printf("-");
choice=getche();
choice=toupper(choice);
switch(choice) // SWITCH STATEMENT
{
case '1':
add();break;
case '2':
list();break;
case '3':
delete1();break;
case '4':
search();break;
case '5':
edit();break;
case '6':
system("cls");
printf("\n\n\t *****THANK YOU*****");
printf("\n\t FOR TRUSTING OUR SERVICE");
// Sleep(2000);
exit(0);
break;
default:
system("cls");
printf("Incorrect Input");
printf("\n Press any key to continue");
getch();
}
}
}
void add()
{
FILE *f;
char test;
f=fopen("add.txt","a+");
if(f==0)
{ f=fopen("add.txt","w+");
system("cls");
printf("Please hold on while we set our database in your computer!!");
printf("\n Process completed press any key to continue!! ");
getch();
}
while(1)
{
system("cls");
printf("\n Enter Customer Details:");
printf("\n**************************");
printf("\n Enter Room number:\n");
scanf("\n%s",s.roomnumber);
fflush(stdin);
printf("Enter Name:\n");
scanf("%s",s.name);
printf("Enter Address:\n");
scanf("%s",s.address);
printf("Enter Phone Number:\n");
scanf("%s",s.phonenumber);
printf("Enter Nationality:\n");
scanf("%s",s.nationality);
printf("Enter Email:\n");
scanf(" %s",s.email);
printf("Enter Period(\'x\'days):\n");
scanf("%s",&s.period);
printf("Enter Arrival date(dd\\mm\\yyyy):\n");
scanf("%s",&s.arrivaldate);
fwrite(&s,sizeof(s),1,f);
fflush(stdin);
printf("\n\n1 Room is successfully booked!!");
printf("\n Press esc key to exit, any other key to add another customer detail:");
test=getche();
if(test==27)
break;
}
fclose(f);
}
void list()
{
FILE *f;
int i;
if((f=fopen("add.txt","r"))==NULL)
exit(0);
system("cls");
printf("ROOM ");
printf("NAME\t ");
printf("\tADDRESS ");
printf("\tPHONENUMBER ");
printf("\tNATIONALITY ");
printf("\tEMAIL ");
printf("\t\t PERIOD ");
printf("\t ARRIVALDATE \n");
for(i=0;i<118;i++)
printf("-");
while(fread(&s,sizeof(s),1,f)==1)
{
/*printf("ROOMNUMBER :\t%s\n",s.roomnumber);
printf("NAME:\t%s\n",,s.name);
printf("ADDRESS:\t%s\n",s.address);
printf("PHONENUMBER:\t%s\n",s.phonenumber);
printf("NATIONALITY \n");*/
printf("\n%s \t%s \t\t%s \t\t%s \t%s \t%s \t %s \t %s",s.roomnumber, s.name , s.address , s.phonenumber ,s.nationality ,s.email,s.period, s.arrivaldate);
}
printf("\n");
for(i=0;i<118;i++)
printf("-");
fclose(f);
getch();
}
void delete1()
{
FILE *f,*t;
int i=1;
char roomnumber[20];
if((t=fopen("temp.txt","w"))==NULL)
exit(0);
if((f=fopen("add.txt","r"))==NULL)
exit(0);
system("cls");
printf("Enter the Room Number of the hotel to be deleted from the database: \n");
fflush(stdin);
scanf("%s",roomnumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.roomnumber,roomnumber)==0)
{ i=0;
continue;
}
else
fwrite(&s,sizeof(s),1,t);
}
if(i==1)
{
printf("\n\n Records of Customer in this Room number is not found!!");
//remove("E:/file.txt");
//rename("E:/temp.txt","E:/file.txt");
getch();
fclose(f);
fclose(t);
main();
}
fclose(f);
fclose(t);
remove("add.txt");
rename("temp.txt","add.txt");
printf("\n\nThe Customer is successfully removed....");
fclose(f);
fclose(t);
getch();
}
void search()
{
system("cls");
FILE *f;
char roomnumber[20];
int flag=1;
f=fopen("add.txt","r+");
if(f==0)
exit(0);
fflush(stdin);
printf("Enter Room number of the customer to search its details: \n");
scanf("%s", roomnumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.roomnumber,roomnumber)==0){
flag=0;
printf("\n\tRecord Found\n ");
printf("\nRoom Number:\t%s",s.roomnumber);
printf("\nName:\t%s",s.name);
printf("\nAddress:\t%s",s.address);
printf("\nPhone number:\t%s",s.phonenumber);
printf("\nNationality:\t%s",s.nationality);
printf("\nEmail:\t%s",s.email);
printf("\nPeriod:\t%s",s.period);
printf("\nArrival date:\t%s",s.arrivaldate);
flag=0;
break;
}
}
if(flag==1){
printf("\n\tRequested Customer could not be found!");
}
getch();
fclose(f);
}
void edit()
{
FILE *f;
int k=1;
char roomnumber[20];
long int size=sizeof(s);
if((f=fopen("add.txt","r+"))==NULL)
exit(0);
system("cls");
printf("Enter Room number of the customer to edit:\n\n");
scanf("%[^\n]",roomnumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.roomnumber,roomnumber)==0)
{
k=0;
printf("\nEnter Room Number :");
gets(s.roomnumber);
printf("\nEnter Name :");
fflush(stdin);
scanf("%s",&s.name);
printf("\nEnter Address :");
scanf("%s",&s.address);
printf("\nEnter Phone number :");
scanf("%f",&s.phonenumber);
printf("\nEnter Nationality :");
scanf("%s",&s.nationality);
printf("\nEnter Email :");
scanf("%s",&s.email);
printf("\nEnter Period :");
scanf("%s",&s.period);
printf("\nEnter Arrival date :");
scanf("%s",&s.arrivaldate);
fseek(f,size,SEEK_CUR); //to go to desired position infile
fwrite(&s,sizeof(s),1,f);
break;
}
}
if(k==1){
printf("\n\nTHE RECORD DOESN'T EXIST!!!!");
fclose(f);
getch();
}else{
fclose(f);
printf("\n\n\t\tYOUR RECORD IS SUCCESSFULLY EDITED!!!");
getch();
}
}