Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
5.8 kB
2
Indexable
Never
void addbooking()
{
	float finalprice;
	Facility facility;
	member identifyMember;
	booking Book[100];
	FILE* memberptr;
	int icount = 0, x = 0, i = 0, count;
	int add;
	char time;

	char member_name[20], member_id[10], facility_id[10] , booking_id[10];
	
	memberptr = fopen("member.dat", "rb");
	
	if (!memberptr)
	{
		
			printf("Cannot open the file\n");
	}


		printf("The Price of Booking for 1 Facility in 1 Hour is RM5\n");
		printf("Enter your Member ID: ");
		scanf(" %s", &member_id);

		while (fread(&identifyMember, sizeof(member),1, memberptr) != 0)
		{
			icount++;
			if (strcmp(member_id, identifyMember.memberID) == 0)
			{
				printf("\n %s\n", identifyMember.memberID);
				printf(" %s\n", identifyMember.memberName);
				printf(" %d\n", identifyMember.memberContact);
				FILE* readbook;
				readbook = fopen("bookingData.bin", "rb");
				if (!readbook)
				{
					printf("Cannot open the file\n");
				}
				printf("\n\nEnter your booking\n\n");
				printf("Booking ID: ");
				scanf(" %s", &booking_id);
				while (fread(&Book, sizeof(booking),1,readbook)!= 0)
				{
					if (strcmp(booking_id, Book[i].bookingID) == 0)
					{
						//
						x++;
						printf("Booking ID was existed\n");
					}
					//next element or booking ID
					i++;
				
				}
				fclose(readbook);
			}
			
		}
	
		//Started to add the booking details in the specific booking ID.
		if (x == 0)
		{

			FILE* enterbooking;
			enterbooking = fopen("bookingData.bin", "ab");
			if (!enterbooking)
			{
				printf("Cannot open the file\n");
			}
			strcpy(Book[i].memberID, identifyMember.memberID);
			strcpy(Book[i].bookingID, booking_id);
			int facilitycount = 0;
			//Start to check facility
			FILE* identifyfacility;
		
		
			identifyfacility = fopen("facility.txt", "r");
			if (!identifyfacility)
			{
				printf("Cannot Open the file");
			}
			printf("Enter your facility ID: ");
			scanf(" %s", &facility_id);
			//Check the facility in Text file 
			while (fscanf(identifyfacility, "%[^,],%[^,],%[^,],%[^,],%[^,],%d", &facility.facilityId, &facility.types,
				&facility.venue, &facility.description, &facility.maxallow))
			{
				//Comparison between users prompt and text file
				if (strcmp(facility_id, facility.facilityId) == 0)
				{
					strcpy(Book[i].facilityID, facility.facilityId);
					
					facilitycount++;
					//Identify the number of customer
					printf("Number of people: ");
					scanf("%d", &Book[i].numofPeople);
					//Comparison between numberofPeople and maxallow

					if (Book[i].numofPeople > 0 && Book[i].numofPeople <= facility.maxallow)
					{
						printf("Enter Today date: ");
						scanf("%d %d %d", &Book[i].todayDate.today_day, &Book[i].todayDate.today_month, &Book[i].todayDate.today_year);
						printf("Enter Booking date:");
						scanf("%d %d %d", &Book[i].bookDate.booking_day, &Book[i].bookDate.booking_month, &Book[i].bookDate.booking_year);

						if (Book[i].bookDate.booking_day > Book[i].todayDate.today_day)
						{
						 if (Book[i].bookDate.booking_month >= Book[i].todayDate.today_month)
							{
							 if (Book[i].bookDate.booking_year >= Book[i].todayDate.today_year)
							 {
								 printf("Enter the AM(A) PM(P): ");
								 scanf(" %c", &time);
								 printf("Enter Times(8am - 10pm)\n");
								 printf("From: ");
								 scanf("%d:%d", &Book[i].bookTime.hours, &Book[i].bookTime.minutes);
								 printf("To: ");
								 scanf("%d:%d", &Book[i].bookTime.endHours, &Book[i].bookTime.endMinutes);
								 //Ensure users prompt correctly
								 if (time == 'A' && Book[i].bookTime.hours <= 7)

								 {

									 printf("Its closed\n");

									 printf("Please enter again: ");

									 printf("From: ");

									 scanf("%d:%d", &Book[i].bookTime.hours, &Book[i].bookTime.minutes);

									 printf("To : ");

									 scanf("%d:%d", &Book[i].bookTime.endHours, &Book[i].bookTime.endMinutes);
									 calculation(time, i, Book[i].bookTime.hours, Book[i].bookTime.minutes,
										 Book[i].bookTime.endHours, Book[i].bookTime.endMinutes);
									 fwrite(&Book, sizeof(booking), 1, enterbooking);
									 i++;
									 printf("Success Book\n");
								 }
								 //Ensure users prompt correctly
								 else if (time == 'P' && Book[i].bookTime.hours >= 11)

								 {

									 printf("Its closed\n");

									 printf("Please enter again: \n");

									 printf("From: ");

									 scanf("%d:%d", &Book[i].bookTime.hours, &Book[i].bookTime.minutes);

									 printf("To : ");

									 scanf("%d:%d", &Book[i].bookTime.endHours, &Book[i].bookTime.endMinutes);
									 calculation(time, i, Book[i].bookTime.hours, Book[i].bookTime.minutes,
										 Book[i].bookTime.endHours, Book[i].bookTime.endMinutes);
									 fwrite(&Book, sizeof(booking), 1, enterbooking);
									 i++;
									 printf("Success Book\n");
								 }
								 calculation(time, i, Book[i].bookTime.hours, Book[i].bookTime.minutes,
									 Book[i].bookTime.endHours, Book[i].bookTime.endMinutes);
			
								 fwrite(&Book, sizeof(booking), 1, enterbooking);
								 i++;
								 displaybooking();
								 printf("Success Book\n");
							
							 }
							 else
							 {
								 printf("Times eror\n");
							 }
							}
						 else
						 {
							 printf("Times eror\n");
						 }
						}
						else
						{
							printf("Times eror\n");
						}
					}
					else
					{
						printf("Facility had full\n");
					}

							}
				else
				{
					printf("Facility eror\n");
				}

						}
			fclose(enterbooking);
			fclose(identifyfacility);
					}

		
				}