public void PlaceBorrowExecute(DataGrid _Customers)
        {
            Customer SelectedCustomer;

            // Try casting SelectedItem to Customer - if it fails, there was nothing selected
            try
            {
                SelectedCustomer = (Customer)_Customers.SelectedItem;
                if (SelectedCustomer == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Message = "Uh Oh! Something went wrong.\nMake sure you've selected a Customer!";
                OnPropertyChanged("Message");
                return;
            }

            // Create new Borrow
            Borrow NewBorrow = new Borrow()
            {
                FKey_Book     = _SelectedBook.PKey,
                FKey_Customer = SelectedCustomer.PKey,
                DateOfBorrow  = DateTime.Now,
                DateOfReturn  = ReturnDate,
                Returned      = false
            };

            // Insert new Borrow into Database
            if (!Access.InsertBorrow(NewBorrow))
            {
                Message = "Uh Oh! Something went wrong.\nCouldn't insert new Borrow into DB!";
                OnPropertyChanged("Message");
                return;
            }
            else
            {
                BorrowWindow.Close();
            }
        }
Пример #2
0
        private void ReturnBookExecute(object _DataGrids)
        {
            var      Elements = (object[])_DataGrids;
            DataGrid _Borrows = (DataGrid)Elements[0];
            DataGrid _Books   = (DataGrid)Elements[1];

            dynamic Data    = (dynamic)_Borrows.SelectedItem;
            Borrow  _Borrow = null;

            // Try casting SelectedItem to Borrow - if it fails, there was nothing selected
            try
            {
                _Borrow = Data._Borrow;
            }
            catch (Exception)
            {
                Message = "Uh Oh! Something went wrong. Make sure you've selected a desired Borrow to return!";
                OnPropertyChanged("Message");
                return;
            }

            if (!Access.ReturnBorrow(_Borrow))
            {
                Message = "Uh Oh! Something went wrong. Couldn't update Borrow as returned in the DB!";
                OnPropertyChanged("Message");
                return;
            }
            else
            {
                Message = "";
                OnPropertyChanged("Message");

                // TODO: Refactor to single Item update... (Needs new StoredProcedure)
                UpdateBorrows();
                UpdateBooks();
                _Borrows.ItemsSource = null;
                _Books.ItemsSource   = null;
                _Borrows.ItemsSource = Borrows;
                _Books.ItemsSource   = Books;
            }
        }