コード例 #1
0
        //Search
        private void buttonAutSearch_Click(object sender, EventArgs e)
        {
            Author aAuthor = new Author();

            if (!string.IsNullOrEmpty(textBoxAutSearch.Text))
            {
                switch (comboBoxAutSearch.SelectedIndex)
                {
                case -1:
                    MessageBox.Show("Please select a valid search option!");
                    return;

                case 0:
                    int tempId;
                    if (!int.TryParse(textBoxAutSearch.Text, out tempId))
                    {
                        MessageBox.Show("Please enter a valid term to be searched.", "No search information!");
                        return;
                    }
                    aAuthor = AuthorDA.SearchID(Convert.ToInt32(textBoxAutSearch.Text));
                    break;

                case 1:
                    aAuthor = AuthorDA.SearchFirst(textBoxAutSearch.Text);
                    break;

                case 2:
                    aAuthor = AuthorDA.SearchLast(textBoxAutSearch.Text);
                    break;
                }

                if (aAuthor == null)
                {
                    MessageBox.Show("Author not found!", "Not found!");
                    textBoxAutSearch.Clear();
                    textBoxAutSearch.Focus();
                    return;
                }

                AuthorDA.ListSearchResult(aAuthor, listViewAuthor);
                return;
            }
            MessageBox.Show("Please enter a valid term to be searched.", "No search information!");
            return;
        }