/// <summary> /// Eventhandler for changes of the status of a repair (ComboBox) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditStatus(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; RepairOrderModel repair = comboBox.DataContext as RepairOrderModel; string selectedStatus = (string)comboBox.SelectedItem; List <string> allowedStatus = new List <string>(status); if (repair.Employee == null) { allowedStatus.Remove("In progress"); } else { allowedStatus.Remove("Inactive"); allowedStatus.Remove("Waiting for employee"); } if (allowedStatus.Contains(selectedStatus) && repair.Status != selectedStatus) { repair.Status = selectedStatus; db.Entry(repair).State = EntityState.Modified; db.SaveChanges(); Update(); } }
public AddPartsWindow(RepairOrderModel repair) { InitializeComponent(); currentRepair = repair; FillRepairDetails(); FillPartList(); }
/// <summary> /// Eventhandler for changes of the customer of a repair (ComboBox) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditCustomer(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; RepairOrderModel repair = comboBox.DataContext as RepairOrderModel; repair.Customer = comboBox.SelectedItem as CustomerModel; db.Entry(repair).State = EntityState.Modified; db.SaveChanges(); }
/// <summary> /// Opens a dialog where the user can select parts from a list to add them to a repair. WIP /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddPart(object sender, MouseButtonEventArgs e) { e.Handled = false; ListBox listBox = sender as ListBox; RepairOrderModel repair = listBox.DataContext as RepairOrderModel; AddPartsWindow addPartsWindow = new AddPartsWindow(repair); addPartsWindow.ShowDialog(); }
/// <summary> /// Adds blackout dates to the calendar object of the datepicker. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DatePicker_Open(object sender, RoutedEventArgs e) { DatePicker datePicker = sender as DatePicker; RepairOrderModel repair = datePicker.DataContext as RepairOrderModel; //Makes sure the start date can't be changed to anything earlier than now or the last start date. DateTime currentStartDate = ((DateTime)repair.StartDate).AddDays(-1); DateTime maxTime = (currentStartDate > DateTime.Now.AddDays(-1)) ? DateTime.Now.AddDays(-1) : currentStartDate; datePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.MinValue, maxTime)); if (datePicker.Name.Contains("End")) { datePicker.BlackoutDates.AddDatesInPast(); } }
/// <summary> /// Updates the description if it has been changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DescriptionChanged(object sender, RoutedEventArgs e) { DataGridCell cell = sender as DataGridCell; TextBox textBox = cell.Content as TextBox; if (textBox != null) { RepairOrderModel repair = cell.DataContext as RepairOrderModel; repair.Description = textBox.Text; db.Entry(repair).State = EntityState.Modified; db.SaveChanges(); } }
/// <summary> /// Updates the date the use has changed and saves it on the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateDate(object sender, SelectionChangedEventArgs e) { DatePicker datePicker = sender as DatePicker; if (datePicker.IsDropDownOpen) { RepairOrderModel order = datePicker.DataContext as RepairOrderModel; DateTime?orderStart = order.StartDate; DateTime?today = DateTime.Now; DateTime?selected = datePicker.SelectedDate; string name = datePicker.Name; datePicker.IsDropDownOpen = false; if (name.Contains("End")) { if (selected > orderStart && selected > today) { order.EndDate = selected; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); Update(); } } else { if (selected > today) { order.StartDate = selected; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); Update(); } } } }
public void AddRepairOrder() { CustomerModel selectedCustomer = CustomerBox.SelectedItem as CustomerModel; EmployeeModel selectedEmployee = EmployeeBox.SelectedItem as EmployeeModel; DateTime? startDate = StartDateBox.SelectedDate; DateTime? endDate = EndDateBox.SelectedDate; #region Check required fields for nulls bool noNulls = true; if (selectedCustomer == null) { SelectCustomerLabel.Foreground = Brushes.Red; if (!SelectCustomerLabel.Content.ToString().Contains('*')) { SelectCustomerLabel.Content += "*"; } Required(); noNulls = false; } if (startDate == null) { SelectStartDateLabel.Foreground = Brushes.Red; if (!SelectStartDateLabel.Content.ToString().Contains('*')) { SelectStartDateLabel.Content += "*"; } Required(); noNulls = false; } if (endDate == null) { SelectEndDateLabel.Foreground = Brushes.Red; if (!SelectEndDateLabel.Content.ToString().Contains('*')) { SelectEndDateLabel.Content += "*"; } Required(); noNulls = false; } #endregion if (noNulls) { RepairOrderModel repair = new RepairOrderModel { Customer = selectedCustomer, StartDate = startDate, EndDate = endDate, Employee = selectedEmployee, HoursWorked = 0, Status = "Inactive", Description = string.Empty, }; db.Repairs.Add(repair); db.SaveChanges(); data.Repairs = new ObservableCollection <RepairOrderModel>(data.Repairs.Append(repair)); CustomerBox.SelectedItem = null; EmployeeBox.SelectedItem = null; StartDateBox.SelectedDate = null; EndDateBox.SelectedDate = null; ResultLabel.Visibility = Visibility.Visible; ResultLabel.Foreground = Brushes.Green; ResultLabel.Content = "Repair added"; } }