private void Foundbutton_Click(object sender, EventArgs e) { if (IDtextbox.Text != "") { int x = -1; try { x = Convert.ToInt32(IDtextbox.Text); } catch { MessageBox.Show("ID должен состоять только из цифр", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); IDtextbox.Focus(); } if (x <= 0) { MessageBox.Show("ID не может быть отрицательным или равным нулю.", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); IDtextbox.Focus(); } else { var query = from c in db.GetStaffTable() where c.Id == Convert.ToInt32(IDtextbox.Text) select c.Id; var a = query.FirstOrDefault(); if (a == 0) { MessageBox.Show("Введен не существующий ID.", "ID не найден", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { panel2.Show(); BirthdayPicker.Value = (from c in db.GetStaffTable() where c.Id == Convert.ToInt32(IDtextbox.Text) select c.Birthday).FirstOrDefault(); Searchtextbox.Enabled = false; IDtextbox.Enabled = false; Foundbutton.Enabled = false; dataGrid.DataSource = from c in db.GetStaffTable() where c.Id == Convert.ToInt32(IDtextbox.Text) select c; } } } else { MessageBox.Show("Заполните поле \"ID\"", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void Foundbutton_Click(object sender, EventArgs e) { if (IDtextbox.Text != "") { int x = -1; try { x = Convert.ToInt32(IDtextbox.Text); } catch { MessageBox.Show("ID должен состоять только из цифр", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); IDtextbox.Focus(); } if (x <= 0) { MessageBox.Show("ID не может быть отрицательным или равным нулю.", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); IDtextbox.Focus(); } else { var query = from c in db.GetBooksTable() join Author_Book in db.GetAuthor_BooksTable() on c.Id equals Author_Book.IdBooks join Author in db.GetAuthorsTable() on Author_Book.IdAuthors equals Author.Id where c.Id == x select c.Id; var a = query.FirstOrDefault(); if (a == 0) { MessageBox.Show("Введен не существующий ID.", "ID не найден", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { panel2.Show(); Searchtextbox.Enabled = false; IDtextbox.Enabled = false; Foundbutton.Enabled = false; dataGrid.DataSource = from c in db.GetBooksTable() join author_Book in db.GetAuthor_BooksTable() on c.Id equals author_Book.IdBooks join Author in db.GetAuthorsTable() on author_Book.IdAuthors equals Author.Id where c.Id == Convert.ToInt32(IDtextbox.Text) select new { c.Id, c.Title, c.Genre, c.Release, c.Count, Author.FirstName, Author.LastName, Current_Count = c.Count - ((from rent in db.GetRentTable() where c.Id == rent.IdBooks select rent.Count).Sum() ?? 0) }; int CountOfAuthors = (from c in db.GetAuthor_BooksTable() where c.IdBooks == Convert.ToInt32(IDtextbox.Text) select c).Count(); switch (CountOfAuthors) { case 1: Author2combobox.Hide(); Author3combobox.Hide(); break; case 2: Author3combobox.Hide(); break; } } } } else { MessageBox.Show("Заполните поле \"ID\"", "Неккоректный ввод", MessageBoxButtons.OK, MessageBoxIcon.Information); } }