private void Button_Click_2(object sender, RoutedEventArgs e) { int insertCounter = 0; int count = 0; //book button try { string BikeID = Convert.ToString(CBBike.SelectedValue).Trim(); TBikeDAL MyDAL = new TBikeDAL(); DateTime Start = Convert.ToDateTime(StartDate.SelectedDate.Value); TimeSpan CheckTime = new TimeSpan(08, 00, 00); TimeSpan endTime = new TimeSpan(16, 00, 00); DataTable ResultTable = new DataTable(); DataTable ResultBikeTable = MyDAL.SelectBicycleByID(CBBike.SelectedValue.ToString().Trim()); int bikeQuantity = Convert.ToInt32(ResultBikeTable.Rows[0]["Quantity"]); ResultTable = MyDAL.ShowBookingTableByBike(CBBike.SelectedValue.ToString().Trim(), ""); if (bikeQuantity != 0) { var dates = new List <DateTime>(); if (ResultTable.Rows.Count == 0) { MyDAL.AddBookingTime(Start, CBBike.SelectedValue.ToString().Trim(), "A", TBCustomer.Text, null, TLUsername.Text, null, null, TBRemarks.Text); MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Information, "Success", "Booking made at :" + Start, "OK"); pop.ShowDialog(); } for (int i = 0; i < ResultTable.Rows.Count; i++) { if (Convert.ToString(ResultTable.Rows[A]["BookingStatus"]).Trim() != "S") { DateTime GetDate = Convert.ToDateTime(ResultTable.Rows[A]["BookingDate"]); if (Start.Date == GetDate && CBBike.SelectedValue.ToString().Trim() == Convert.ToString(ResultTable.Rows[A]["BicycleID"]).ToString().Trim()) { count++; break; } else if (Start.Date > DateTime.Now && Convert.ToDateTime(ResultTable.Rows[A]["BookingDate"]).Date <Start.Date && Start.TimeOfDay> CheckTime && Start.TimeOfDay < endTime) { insertCounter++; A++; } else if (Start.Date < DateTime.Now) { MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Date must be booked 1 day ahead from today", "OK"); pop.ShowDialog(); insertCounter = 0; break; } else if (Start.TimeOfDay < CheckTime || Start.TimeOfDay > endTime) { MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Booking must be booked at 8am-4pm", "OK"); pop.ShowDialog(); insertCounter = 0; break; } else { count = count + 1; A++; } if (ResultTable.Rows.Count <= A) { A = 0; insertCounter++; break; } } else { A++; insertCounter++; } } if (count >= 1) { MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "Sorry Booking not made, This bike has been booked on " + Start.ToLongDateString(), "OK"); count = 0; pop.ShowDialog(); } else if (insertCounter >= 1) { MyDAL.AddBookingTime(Start, CBBike.SelectedValue.ToString().Trim(), "A", TBCustomer.Text, null, TLUsername.Text, null, null, TBRemarks.Text); MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Information, "Success", "Bicycle: " + Convert.ToString(ResultTable.Rows[0]["BicycleName"]).Trim() + ", Booking made at :" + Start.ToLongDateString(), "OK"); insertCounter = 0; pop.ShowDialog(); } } else { MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Warning, "Sorry", "This bike has ran out of stock", "Sad :("); pop.ShowDialog(); } } catch (Exception ex) { MessageBox.PopWindow pop = new MessageBox.PopWindow(AppData.ImageType.Error, "Error", ex.Message, "Sad :("); pop.ShowDialog(); } finally { //dispose all counters A = 0; count = 0; insertCounter = 0; MainWindow main = new MainWindow(); main.Notification(); } }
private void BTNRent_Click(object sender, RoutedEventArgs e) { TBikeDAL MyDAL = new TBikeDAL(); try { TimeSpan duration = TPEnd.SelectedTime.Value - TPStart.SelectedTime.Value; if (CBBike.SelectedIndex != -1) { DataTable ResultTable = MyDAL.ShowBookingTableByCustomer(LBCustomer.Text.Trim(), "A"); string Bike = Convert.ToString(ResultTable.Rows[0]["BicycleID"]); string BikeName = Convert.ToString(ResultTable.Rows[0]["BicycleName"]); string customer = Convert.ToString(ResultTable.Rows[0]["CurrentRenter"]); DateTime bookTime = Convert.ToDateTime(ResultTable.Rows[0]["BookingDate"]); string BookingID = Convert.ToString(ResultTable.Rows[0]["BookingID"]).Trim(); //double Deposit = Convert.ToDouble(ResultTable.Rows[0]["BookingDeposit"]); double Price = Convert.ToDouble(ResultTable.Rows[0]["Price"]); //This is for booked rents if (TPStart.SelectedTime < bookTime.TimeOfDay) { PopWindow pop = new PopWindow(ImageType.Error, "Sorry", "Can't rent time that is before booking time", "Okay"); pop.ShowDialog(); } else { TimeSpan CheckTime = new TimeSpan(08, 00, 00); TimeSpan endTime = new TimeSpan(20, 00, 00); if (TPEnd.SelectedTime < CheckTime || TPEnd.SelectedTime > endTime) { PopWindow pop = new PopWindow(ImageType.Error, "Error", "Please rent in working hours about 8am to 8pm", "Okay"); pop.ShowDialog(); } else { if (TPEnd.SelectedTime - TPStart.SelectedTime <= new TimeSpan(0, 30, 0)) { PopWindow pop = new PopWindow(ImageType.Warning, "Too less time", "Please rent At least 30mins", "Okay"); pop.ShowDialog(); } else { //if bicycle status is Renting, dont rent bike if (Convert.ToString(ResultTable.Rows[0]["BicycleStatus"]) == "R") { PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "This Bike has been rented By, " + customer.Trim(), "Okay"); pop.ShowDialog(); } //if able to rent start process add else { double TotalPrice = (((double)duration.TotalHours) * Price); TotalPrice = System.Math.Round(TotalPrice, 2); ConfirmWindow confirm = new ConfirmWindow(ImageType.Question, "Confirm?", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice, "Yes, Rent Out", "No, Don't Rent"); confirm.ShowDialog(); if (SnackPanel.Visibility == Visibility.Visible) { DataTable ResultTableSnack = MyDAL.SelectSnackBySnackID(CBSnack.SelectedValue.ToString().Trim()); int Sorter = Convert.ToInt32(ResultTableSnack.Rows[0]["Quantity"]); double price = Convert.ToDouble(ResultTableSnack.Rows[0]["Price"]) * Convert.ToInt32(TBQuantity.Text); string Snack = Convert.ToString(ResultTableSnack.Rows[0]["SnackName"]).Trim(); confirm = new ConfirmWindow(ImageType.Question, "Confirm?", "Snack: " + Snack + " , Total Price: " + price, "Confirm", "No, Don't Confirm"); confirm.ShowDialog(); if (Sorter >= Convert.ToInt32(TBQuantity.Text) && confirm.Confirmed) { MyDAL.AddSnackSales(CBSnack.SelectedValue.ToString().Trim(), Convert.ToInt32(TBQuantity.Text), LBCustomer.Text.Trim(), price, TLUsername.Text.Trim(), BookingID); } else if (confirm.Confirmed == false) { confirm.Confirmed = false; } else { PopWindow poper = new PopWindow(ImageType.Warning, "Can't Sale!!", "Item lack of stock, please Restock", "OK"); poper.ShowDialog(); confirm.Confirmed = false; } } //MessageBox.Show("Rented For " + LBCustomer.Text + " Duration is " + Convert.ToString(duration.Hours).Trim() + " Hours","Question",MessageBoxButton.YesNo,MessageBoxImage.Information); if (confirm.Confirmed) { MyDAL.UpdateBikeStatus(Bike, LBCustomer.Text.Trim(), "R", "", null, null, TLUsername.Text); MyDAL.UpdateBookingDate(Convert.ToDateTime(LBBookingDate.Text), Bike, LBCustomer.Text.Trim(), TotalPrice, "R", TLUsername.Text.Trim(), TPStart.SelectedTime, TPEnd.SelectedTime, TBRemarks.Text); PopWindow pop = new PopWindow(ImageType.Information, "Success rent", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice + " ,has been Rented", "OK"); CBBike.SelectedIndex = 0; stack1.Visibility = Visibility.Hidden; TPStart.Visibility = Visibility.Hidden; TPEnd.Visibility = Visibility.Hidden; } else { PopWindow pop = new PopWindow(ImageType.Warning, "Cancel", "Rented Canceled by " + TLUsername.Text, "Okay"); pop.ShowDialog(); } } } } } } // This is for adding new rent else if (TPStart.SelectedTime < DateTime.Now.TimeOfDay) { PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "Can't rent time that is before the current time", "Okay"); pop.ShowDialog(); } //Must select a bicycle inorder to proceed next step... else if (CBBicycle.SelectedIndex != -1) { TimeSpan CheckTime = new TimeSpan(08, 00, 00); TimeSpan endTime = new TimeSpan(20, 00, 00); if (stack1.Visibility != Visibility.Hidden) { if (TPEnd.SelectedTime < CheckTime || TPEnd.SelectedTime > endTime) { PopWindow pop = new PopWindow(ImageType.Warning, "Error", "Please rent in working hours about 8am to 8pm", "Okay"); pop.ShowDialog(); } else { if (TPEnd.SelectedTime - TPStart.SelectedTime <= new TimeSpan(0, 30, 0)) { PopWindow pop = new PopWindow(ImageType.Warning, "Error", "Please rent At least 30mins", "Okay"); pop.ShowDialog(); } else { DataTable ResultTable = MyDAL.SelectBicycleByID(CBBicycle.SelectedValue.ToString().Trim()); string Bike = Convert.ToString(ResultTable.Rows[0]["BicycleID"]); string BikeName = Convert.ToString(ResultTable.Rows[0]["BicycleName"]); string customer = TBCustomer.Text; //double Deposit = Convert.ToDouble(ResultTable.Rows[0]["BookingDeposit"]); double Price = Convert.ToDouble(ResultTable.Rows[0]["Price"]); if (Convert.ToString(ResultTable.Rows[0]["BicycleStatus"]) == "R") { PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "This Bike has been rented By, " + customer.Trim(), "Okay"); pop.ShowDialog(); } //if able to rent start process add else { double TotalPrice = (((double)duration.TotalHours) * Price); TotalPrice = System.Math.Round(TotalPrice, 2); ConfirmWindow con = new ConfirmWindow(ImageType.Question, "Confirm", "Bicycle " + BikeName + ", for Renter " + LBCustomer.Text + ", Duration is " + duration + " Hours, " + " Total Price: RM" + TotalPrice, "Yes, Rent", "No, Don't"); con.ShowDialog(); if (SnackPanel.Visibility == Visibility.Visible) { DataTable ResultTableSnack = MyDAL.SelectSnackBySnackID(CBSnack.SelectedValue.ToString().Trim()); int Sorter = Convert.ToInt32(ResultTableSnack.Rows[0]["Quantity"]); double price = Convert.ToDouble(ResultTableSnack.Rows[0]["Price"]) * Convert.ToInt32(TBQuantity.Text); string Snack = Convert.ToString(ResultTableSnack.Rows[0]["SnackName"]).Trim(); con = new ConfirmWindow(ImageType.Question, "Confirm?", "Snack: " + Snack + " , Total Price: " + price, "Confirm", "No, Don't Confirm"); con.ShowDialog(); if (Sorter >= Convert.ToInt32(TBQuantity.Text) && con.Confirmed) { MyDAL.AddSnackSales(CBSnack.SelectedValue.ToString().Trim(), Convert.ToInt32(TBQuantity.Text), LBCustomer.Text.Trim(), price, TLUsername.Text.Trim(), ""); } else if (con.Confirmed == false) { con.Confirmed = false; } else { PopWindow poper = new PopWindow(ImageType.Warning, "Can't Sale!!", "Item lack of stock, please Restock", "OK"); poper.ShowDialog(); con.Confirmed = false; } } //MessageBox.Show("Rented For " + LBCustomer.Text + " Duration is " + Convert.ToString(duration.Hours).Trim() + " Hours","Question",MessageBoxButton.YesNo,MessageBoxImage.Information); if (con.Confirmed) { MyDAL.AddBookingTime(DateTime.Now.Date, Bike, "R", LBCustomer.Text.Trim(), TotalPrice, TLUsername.Text.Trim(), TPStart.SelectedTime, TPEnd.SelectedTime, TBRemarks.Text); PopWindow pop = new PopWindow(ImageType.Information, "Complete", "Rented Out by " + TLUsername.Text, "Okay"); pop.ShowDialog(); TBCustomer.Text = ""; CBBicycle.SelectedIndex = 0; stack1.Visibility = Visibility.Hidden; TPStart.Visibility = Visibility.Hidden; TPEnd.Visibility = Visibility.Hidden; } else { PopWindow pop = new PopWindow(ImageType.Warning, "Cancel", "Rented Canceled by " + TLUsername.Text, "Okay"); pop.ShowDialog(); } } } } } else { PopWindow pop = new PopWindow(ImageType.Warning, "Sorry", "Please Click next to proceed rental", "Ok"); pop.ShowDialog(); } } BindComboBox(CBBike); } catch (Exception ex) { PopWindow pop = new PopWindow(ImageType.Information, "Error", ex.Message, "I will Fix this"); pop.ShowDialog(); } }