Exemplo n.º 1
0
        private void btnSaveBook_Click(object sender, EventArgs e)
        {
            try
            {
                //FmBooks fmBooks = new FmBooks();
                if (cbGenreBook.Text.Equals("Select the  book genre:") && cbGenreBook.SelectedIndex < 0)
                {
                    MessageBox.Show("Please, select a genre the book!");
                    cbGenreBook.Focus();
                }
                else
                {
                    if (bookControl.checkISBNControl(mtxtISBN.Text) && lblTitleAddBook.Text.Equals("Add a new book"))
                    {
                        MessageBox.Show("This ISBN has existed in our database");
                        mtxtISBN.Clear();
                        mtxtISBN.Focus();
                    }
                    else
                    {
                        if (lblTitleAddBook.Text.Equals("Add a new book"))
                        {
                            string result = bookControl.insertBooksControl(mtxtISBN.Text, txtTitleBook.Text, txtAuthorBook.Text, txtYearBook.Text, txteditoraBook.Text, cbGenreBook.SelectedItem.ToString(), txtAmountBook.Text, txtPriceBook.Text);
                            if (result.Equals("sucess"))
                            {
                                clearAddNewTextBox();
                                panelAddVisible(false);
                                lblTitleAddBook.Text = "";
                                showBooksInDataGrid();
                            }
                            else
                            {
                                MessageBox.Show("Error: its not possible add a book!");
                            }
                            //this.Refresh();


                            //fmBooks.refreshForm();
                            //this.Close();
                            //fmBooks.ValidaEnableButtons();
                        }
                        else if (lblTitleAddBook.Text.Equals("Update data"))
                        {
                            string str = bookControl.updateDataControl(id, mtxtISBN.Text, txtTitleBook.Text, txtAuthorBook.Text, txtYearBook.Text, txteditoraBook.Text, cbGenreBook.SelectedItem.ToString(), txtAmountBook.Text, txtPriceBook.Text);
                            if (str.Equals("sucess"))
                            {
                                MessageBox.Show("Update finished with sucess!");
                                this.Refresh();
                                clearAddNewTextBox();
                                panelAddVisible(false);
                                lblTitleAddBook.Text = "";
                                mtxtISBN.ReadOnly    = false;
                                showBooksInDataGrid();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }