示例#1
0
        private void buttonSearchBook_Click(object sender, EventArgs e)
        {
            int choice = comboBoxBook.SelectedIndex;

            switch (choice)
            {
            case -1:
                MessageBox.Show("Please select the search option");
                break;

            case 0:
                Books book = BooksDA.Search(Convert.ToInt32(textBoxEnterInformation.Text));
                if (book != null)
                {
                    textBoxISBN.Text          = book.ISBN.ToString();
                    textBoxTitle.Text         = book.Title;
                    textBoxAuthor.Text        = book.BookAuthor;
                    textBoxYearPublished.Text = (book.BookYearPublished).ToString();
                    textBoxQOH.Text           = (book.BookQOH).ToString();
                    textBoxUnitPrice.Text     = (book.BookUnitePrice).ToString();



                    textBoxISBN.Enabled = false;
                }

                else
                {
                    MessageBox.Show("ISBN not Found!");
                    textBoxEnterInformation.Clear();
                    textBoxEnterInformation.Focus();
                }
                break;

            case 1:
                Books boo = BooksDA.SearchTitle(textBoxEnterInformation.Text);
                if (boo != null)
                {
                    textBoxISBN.Text          = (boo.ISBN).ToString();
                    textBoxTitle.Text         = boo.Title;
                    textBoxAuthor.Text        = boo.BookAuthor;
                    textBoxYearPublished.Text = (boo.BookYearPublished).ToString();
                    textBoxQOH.Text           = (boo.BookQOH).ToString();
                    textBoxUnitPrice.Text     = (boo.BookUnitePrice).ToString();

                    textBoxISBN.Enabled = false;
                }

                else
                {
                    MessageBox.Show("Title not Found!");
                    textBoxEnterInformation.Clear();
                    textBoxEnterInformation.Focus();
                }
                break;

            default:
                break;
            }
        }
        private void buttonSearchBook_Click(object sender, EventArgs e)
        {
            Books book = BooksDA.Search(Convert.ToInt32(textBoxBookSearcher.Text));

            if (book != null)
            {
                textBoxBookSearcher.Text = book.Title;

                textBoxBookSearcher.Clear();
            }

            else
            {
                MessageBox.Show("ISBN not Found!");
                textBoxBookSearcher.Clear();
                textBoxBookSearcher.Focus();
            }
        }
        private void buttonBooSearch_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(textBoxBooSearch.Text))
            {
                int choice = comboBoxBooSearch.SelectedIndex;
                switch (choice)
                {
                case -1:
                    MessageBox.Show("Please select the search option");
                    break;

                case 0:     //Search by ISBN Number
                    Books Boo = BooksDA.Search(Convert.ToInt32(textBoxBooSearch.Text));
                    if (Boo != null)
                    {
                        textBoxBooISBN.Text       = Boo.ISBN.ToString();
                        textBoxBooTitle.Text      = Boo.title;
                        comboBoxBooAuthor.Text    = Boo.author;
                        textBoxBooYPublished.Text = Boo.yearPublished;
                        textBoxBooPrice.Text      = Boo.unitPrice.ToString();
                        textBoxBooQOH.Text        = Boo.QOH.ToString();
                        comboBoxBooSuplier.Text   = Boo.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;

                case 1:     //Search by Book Title
                    Books BooTitle = BooksDA.SearchByTitle(textBoxBooSearch.Text);
                    if (BooTitle != null)
                    {
                        textBoxBooISBN.Text       = BooTitle.ISBN.ToString();
                        textBoxBooTitle.Text      = BooTitle.title;
                        comboBoxBooAuthor.Text    = BooTitle.author;
                        textBoxBooYPublished.Text = BooTitle.yearPublished;
                        textBoxBooPrice.Text      = BooTitle.unitPrice.ToString();
                        textBoxBooQOH.Text        = BooTitle.QOH.ToString();
                        comboBoxBooSuplier.Text   = BooTitle.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;


                case 2:     //Search by Book Author
                    Books BooAuthor = BooksDA.SearchByAuthor(textBoxBooSearch.Text);
                    if (BooAuthor != null)
                    {
                        textBoxBooISBN.Text       = BooAuthor.ISBN.ToString();
                        textBoxBooTitle.Text      = BooAuthor.title;
                        comboBoxBooAuthor.Text    = BooAuthor.author;
                        textBoxBooYPublished.Text = BooAuthor.yearPublished;
                        textBoxBooPrice.Text      = BooAuthor.unitPrice.ToString();
                        textBoxBooQOH.Text        = BooAuthor.QOH.ToString();
                        comboBoxBooSuplier.Text   = BooAuthor.publisher;

                        buttonBooDelete.Enabled = true;
                        buttonBooUpdate.Enabled = true;
                    }

                    else
                    {
                        MessageBox.Show("Client not Found!");
                        textBoxBooSearch.Clear();
                        textBoxBooSearch.Focus();
                    }
                    break;

                default:
                    break;
                }
            }
            else
            {
                MessageBox.Show("Please, enter a valid information to search!", "Serach Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBoxBooSearch.Clear();
                textBoxBooSearch.Focus();
            }
        }