Beispiel #1
0
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            EditBookDialog editBookDialog = new EditBookDialog();    //Initiate Window
            String         result;

            editBookDialog.ShowDialog();

            if (editBookDialog.DialogResult == true)
            {
                try
                {
                    string isbn       = editBookDialog.isbnTextBox.Text;
                    string title      = editBookDialog.titleTextBox.Text;
                    string author     = editBookDialog.authorTextBox.Text;
                    double price      = double.Parse(editBookDialog.priceTextBox.Text);
                    int    quantity   = int.Parse(editBookDialog.quantityTextBox.Text);
                    string year       = editBookDialog.yearTextBox.Text;
                    string edition    = editBookDialog.editionTextBox.Text;
                    string publisher  = editBookDialog.publisherTextBox.Text;
                    int    categoryID = int.Parse(editBookDialog.categoryTextBox.Text);
                    int    supplierID = int.Parse(editBookDialog.supplierTextBox.Text);

                    result = bookAddEdit.AddBook(isbn, title, author, price, quantity, year, edition, publisher, categoryID, supplierID);
                    this.UpdateData();
                    MessageBox.Show(result);
                }
                catch (Exception)
                {
                    MessageBox.Show("All fields must be filled out in the correct data format");
                    //throw;
                }
            }
        }
Beispiel #2
0
        private void editButton_Click(object sender, RoutedEventArgs e)
        {
            EditBookDialog editBookDialog = new EditBookDialog();    //Initiate Window
            DataRowView    selectedRow;

            selectedRow = (DataRowView)this.ProductsDataGrid.SelectedItems[0];
            String result;
            String origISBN;

            editBookDialog.isbnTextBox.Text      = selectedRow.Row.ItemArray[0].ToString();
            editBookDialog.titleTextBox.Text     = selectedRow.Row.ItemArray[2].ToString();
            editBookDialog.authorTextBox.Text    = selectedRow.Row.ItemArray[3].ToString();
            editBookDialog.priceTextBox.Text     = selectedRow.Row.ItemArray[4].ToString();
            editBookDialog.quantityTextBox.Text  = selectedRow.Row.ItemArray[8].ToString();
            editBookDialog.yearTextBox.Text      = selectedRow.Row.ItemArray[5].ToString();
            editBookDialog.editionTextBox.Text   = selectedRow.Row.ItemArray[6].ToString();
            editBookDialog.publisherTextBox.Text = selectedRow.Row.ItemArray[7].ToString();
            editBookDialog.categoryTextBox.Text  = selectedRow.Row.ItemArray[9].ToString();
            editBookDialog.supplierTextBox.Text  = selectedRow.Row.ItemArray[10].ToString();

            origISBN = selectedRow.Row.ItemArray[0].ToString();
            editBookDialog.okButton.Content = "Update Book";
            editBookDialog.Owner            = this;

            editBookDialog.ShowDialog();

            if (editBookDialog.DialogResult == true)
            {
                string isbn       = editBookDialog.isbnTextBox.Text;
                string title      = editBookDialog.titleTextBox.Text;
                string author     = editBookDialog.authorTextBox.Text;
                double price      = double.Parse(editBookDialog.priceTextBox.Text);
                int    quantity   = int.Parse(editBookDialog.quantityTextBox.Text);
                string year       = editBookDialog.yearTextBox.Text;
                string edition    = editBookDialog.editionTextBox.Text;
                string publisher  = editBookDialog.publisherTextBox.Text;
                int    categoryID = int.Parse(editBookDialog.categoryTextBox.Text);
                int    supplierID = int.Parse(editBookDialog.supplierTextBox.Text);

                result = bookAddEdit.UpdateBook(origISBN, isbn, title, author, price, quantity, year, edition, publisher, categoryID, supplierID);
                this.UpdateData();     // updates the DataGrid
                MessageBox.Show(result);
            }
        }