Exemple #1
0
        private void BtTask_Click(object sender, EventArgs e)
        {
            enumGenre genre;

            using (InputForm inputForm = new InputForm("Введите жанр"))
            {
                if (inputForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                genre = EnumHelper.StringToGenre(inputForm.inText.ToString());
                if (genre == enumGenre.Null)
                {
                    MessageBox.Show("Вы ввели некорректный жанр!");
                    return;
                }
            }
            List <Book> bookList = new List <Book>();

            foreach (Book book in books)
            {
                if (book.genre == genre)
                {
                    bookList.Add(book);
                }
            }
            bookList.Sort(new MyComparer());
            string message = "Количество книг с заданным жанром: " + bookList.Count + "\n";

            foreach (Book book in bookList)
            {
                message += book.name + "\n";
            }
            MessageBox.Show(message);
        }
Exemple #2
0
        private void BtTask_Click(object sender, EventArgs e)
        {
            InputKindForm inputKindForm = new InputKindForm();

            if (!(inputKindForm.ShowDialog() == DialogResult.OK && inputKindForm.kind != enumKind.Null))
            {
                if (inputKindForm.DialogResult != DialogResult.OK)
                {
                    MessageBox.Show("Были введены некорректные данные!");
                }
                return;
            }
            enumKind  kind      = inputKindForm.kind;
            InputForm inputForm = new InputForm("Введите максимальную цену");
            int       tempNum   = 0;

            if (!(inputForm.ShowDialog() == DialogResult.OK && Int32.TryParse(inputForm.inText, out tempNum) && tempNum >= 0))
            {
                if (inputForm.DialogResult != DialogResult.OK)
                {
                    MessageBox.Show("Были введены некорректные данные!");
                }
                return;
            }
            List <DataGridViewRow> rowList = new List <DataGridViewRow>();

            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (!(Coffee.StringToKind(row.Cells[1].Value.ToString()) == kind && Double.Parse(row.Cells[4].Value.ToString()) <= tempNum))
                {
                    rowList.Add(row);
                    backList.Add(Coffee.CoffeeToRow(Coffee.RowToCoffee(row), dgv));
                }
            }
            foreach (DataGridViewRow row in rowList)
            {
                dgv.Rows.Remove(row);
            }
            dgv.Sort(dgv.Columns[4], ListSortDirection.Ascending);
        }