/// <summary> /// Changes the available stock and reserved amount for when a DVD is received back. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReceiveDVD_Click(object sender, RoutedEventArgs e) { var obj = ((FrameworkElement)sender).DataContext as DVD; lblError.Content = ""; if (obj.ReservedAmount >= 1) { obj.ReservedAmount -= 1; BL_DVD.Save(obj); BindData(); } else { lblError.Content = $"No reserved DVD's ({obj.Name}) left to receive."; } }
/// <summary> /// Changes the available stock and reserved amount for a reservation to be made. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnReservation_Click(object sender, RoutedEventArgs e) { var obj = ((FrameworkElement)sender).DataContext as DVD; lblError.Content = ""; if (obj.ReservedAmount <= obj.Stock - 1) { obj.ReservedAmount += 1; BL_DVD.Save(obj); BindData(); } else { lblError.Content = $"No available DVD's ({obj.Name}) for new reservations."; } }
/// <summary> /// Saves the model of the DVD, after validating the input and opens a new DVD form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveNewDVD_Click(object sender, RoutedEventArgs e) { try { if (Validate()) { if (BL_DVD.Save(Model)) { this.Content = new DVDForm(); } } } catch (Exception) { MessageBox.Show("Saving the DVD was unsuccesful, please only enter valid data.", "Save unsuccesful", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Handles the editing of DVD's in the DataGrid. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grdDVDOverview_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { DataGridRow _dgRow = e.Row; var _changedValue = _dgRow.DataContext as DVD; lblError.Content = ""; if (_changedValue.Stock >= _changedValue.ReservedAmount) { BL_DVD.Save(_changedValue); } else { _changedValue.Stock = _changedValue.ReservedAmount; lblError.Content = $"Stock ({_changedValue.Name}) cannot be lower than the current Reserved Amount."; } BindData(); }
/// <summary> /// Determines what has to happen when the collection of DVD changes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DataSourceChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (DVD d in e.NewItems) { BL_DVD.Save(d); } break; case NotifyCollectionChangedAction.Remove: foreach (DVD d in e.OldItems) { BL_DVD.Delete(d); } break; } }