bool ConfirmLibrarian() { ConfirmForm conForm = new ConfirmForm(); DialogResult conResult = conForm.ShowDialog(this); if (conResult == DialogResult.Cancel) { return(false); } if (conForm.idTextBox.Text.ToUpper().Equals("ADMIN") && conForm.surnameTextBox.Text.ToUpper().Equals("PASSWORD")) { var adminForm = new AdminForm(); DialogResult dialogResult = adminForm.ShowDialog(this); return(true); } int id = int.Parse(conForm.idTextBox.Text); string surname = conForm.surnameTextBox.Text; LibrarianRepository librRep = new LibrarianRepository(); var librarian = librRep.FindById(id); if (librarian == null || librarian.Surname.ToUpper() != surname.ToUpper()) { return(false); } _librarianId = id; return(true); }
private void findByIdButton_Click(object sender, EventArgs e) { var librarianRepository = new LibrarianRepository(); if (string.IsNullOrEmpty(idNumericUpDown.Value.ToString())) { SetDataGridView(); return; } List <Librarian> librarians = new List <Librarian>(); Librarian librarian = librarianRepository.FindById((int)idNumericUpDown.Value); librarians.Add(librarian); if (librarian == null) { dataGridView1.DataSource = "No readers found"; return; } dataGridView1.DataSource = librarians.Select(r => new { r.Id, r.Name, r.Surname, r.Patronymic, r.DateOfBirth, r.TelephoneNumber }).ToList(); }
public void changeButton_Click(object sender, EventArgs e) { if (!(dataGridView1.SelectedRows.Count > 0)) { return; } var addLibrarianForm = new AddLibrarianForm(); var librarianRepository = new LibrarianRepository(); int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Librarian librarian = librarianRepository.FindById(id); addLibrarianForm.nameTextBox.Text = librarian.Name; addLibrarianForm.surnameTextBox.Text = librarian.Surname; addLibrarianForm.patronymicTextBox.Text = librarian.Patronymic; addLibrarianForm.dateTimePicker.Value = librarian.DateOfBirth; addLibrarianForm.telNumberTextBox.Text = librarian.TelephoneNumber; DialogResult dialogResult = addLibrarianForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } string name = addLibrarianForm.nameTextBox.Text; string surname = addLibrarianForm.surnameTextBox.Text; string patronymic = addLibrarianForm.patronymicTextBox.Text; DateTime DoB = addLibrarianForm.dateTimePicker.Value; string telNumber = addLibrarianForm.telNumberTextBox.Text; librarian.Name = name; librarian.Surname = surname; librarian.Patronymic = patronymic; librarian.DateOfBirth = DoB; librarian.TelephoneNumber = telNumber; librarianRepository.Update(librarian); _db.SaveChanges(); SetDataGridView(); }