/// <summary> /// Adds a customer to the table on button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addCustomerBtn_Click(object sender, RoutedEventArgs e) { for (int i = 1; i < 7; i++) { var customer = (Button)this.FindName("customer" + i + "_Btn"); if (customer.IsEnabled == false) { customer.IsEnabled = true; var removeBtn = (Button)this.FindName("removeCust" + i + "_Btn"); removeBtn.IsEnabled = true; Customer person = new Customer(); person.Table = ti; person.TableId = ti.Id; db.Customer.Add(person); db.SaveChanges(); customer.Tag = person.Id; customer.Background = Brushes.Green; cus = person; custIndex = i; break; } else { customer.ClearValue(Button.BackgroundProperty); } } }
/// <summary> /// Clears everything in the layout /// </summary> private void DeleteLayout() { Console.WriteLine("Deleting Layout"); foreach (TableInfo t in db.TableInfo.ToList()) { foreach (Customer c in db.Customer.Where(u => u.TableId == t.Id).ToList()) { foreach (Orders o in db.Orders.Where(u => u.CustId == c.Id).ToList()) { db.Orders.Remove(o); } db.Customer.Remove(c); } db.TableInfo.Remove(t); } foreach (Wall w in db.Wall.ToList()) { db.Wall.Remove(w); } db.SaveChanges(); }
/// <summary> /// Saves the new schedule, if using an existing availability, or creates the new availability and saves the new schedule. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveBtn_Click(object sender, RoutedEventArgs e) { bool error = false; string message = ""; if (usingExistingAvailability) { if (newScheduleItem != null) { Debug.WriteLine("using existing availability: " + newScheduleItem.AvailabilityId); //get the mathcing availability newScheduleItem.AvailabilityId = existingAvailability.Id; newScheduleItem.Availability = existingAvailability; //verify the schedule. if (validSchedule(newScheduleItem)) { if (uniqueSchedule(newScheduleItem)) { db.CurrentSchedule.Add(newScheduleItem); message = "Created a new schedule: \n" + "" + newScheduleItem.BlockStartTime.ToShortDateString() + " " + newScheduleItem.BlockStartTime.ToShortTimeString() + "\n" + "to\n" + "" + newScheduleItem.BlockEndTime.ToShortDateString() + " " + newScheduleItem.BlockEndTime.ToShortTimeString(); } else { message = "The employee is already scheduled within this time.\n Please check your entry again."; error = true; } } else { message = "The employee is not available at this time.\n Please check your entry again."; error = true; } } else { //chose an existing availability, but didn't make a schedule. Debug.WriteLine("Didn't set a schedule."); this.Close(); } } else { // verify the new availability if (validAvailability(newAvailability)) { db.CurrentAvailabilities.Add(newAvailability); db.SaveChanges(); //save the new availability so we can get it's ID. //check if we are saving a new schedule too. if (newScheduleItem != null) { newScheduleItem.Availability = newAvailability; newScheduleItem.AvailabilityId = newAvailability.Id; //validate the new schedule if (validSchedule(newScheduleItem)) { if (uniqueSchedule(newScheduleItem)) { db.CurrentSchedule.Add(newScheduleItem); message = "Created a new Availability and Schedule: \n" + "Available: \n" + "" + newAvailability.BlockStartTime.ToShortDateString() + " " + newAvailability.BlockStartTime.ToShortTimeString() + "\n" + "to\n" + "" + newAvailability.BlockEndTime.ToShortDateString() + " " + newAvailability.BlockEndTime.ToShortTimeString() + "\nand\n Scheduled: \n" + "" + newScheduleItem.BlockStartTime.ToShortDateString() + " " + newScheduleItem.BlockStartTime.ToShortTimeString() + "\n" + "to\n" + "" + newScheduleItem.BlockEndTime.ToShortDateString() + " " + newScheduleItem.BlockEndTime.ToShortTimeString(); } else { message = "The employee is already scheduled within this time.\n Please check your entry."; error = true; } } else { message = "The new schedule is not valid, please check your entry."; error = true; } } else { message = "Created a new Availability: \n" + "" + newAvailability.BlockStartTime.ToShortDateString() + " " + newAvailability.BlockStartTime.ToShortTimeString() + "\n" + "to\n" + "" + newAvailability.BlockEndTime.ToShortDateString() + " " + newAvailability.BlockEndTime.ToShortTimeString(); error = false; } } else { message = "New Availability overlaps with an existing availability. \nPlease adjust your dates or times, or delete the orignal availability."; error = true; } } MessageBoxResult result = MessageBox.Show(message, "Message", MessageBoxButton.OK); switch (result) { case MessageBoxResult.OK: if (!error) { db.SaveChanges(); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); TimeSpan twoWeeks = new TimeSpan(24 * 14, 0, 0); DateTime twoWeeksFromToday = today.Add(twoWeeks); CalendarDateRange thisRange = new CalendarDateRange(today, twoWeeksFromToday); parentStaffScreen.reloadScheduleAndAvailabilityTables(thisStaff, thisRange); this.Close(); } break; } }