private void changeRentButton_Click(object sender, EventArgs e) { ManagerA.addchange = false; InterfaceOfRenter ir = new InterfaceOfRenter(); Renter r = (Renter)renterBindingSource.Current; ir.db = db; ir.r = r; DialogResult dr = ir.ShowDialog(); if (dr == DialogResult.OK) { renterBindingSource.DataSource = db.Renter.ToList(); } }
private void saveButton_Click(object sender, EventArgs e) { if (ManagerA.addchange == true) { if (nameCompanyTb.Text == "" || addressRichTb.Text == "" || phoneMaskTb.Text == "") { MessageBox.Show("Внимание! Необходимо заполнить все поля!", "Ошибка сохранения: пустые поля!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Renter r = new Renter(); r.Name = nameCompanyTb.Text; r.Address = addressRichTb.Text; r.Phone = phoneMaskTb.Text; db.Renter.Add(r); try { db.SaveChanges(); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.InnerException.InnerException.Message); } } } else if (ManagerA.addchange == false) { r.Name = nameCompanyTb.Text; r.Address = addressRichTb.Text; r.Phone = phoneMaskTb.Text; try { db.SaveChanges(); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.InnerException.InnerException.Message); } } }
private void removeButton_Click(object sender, EventArgs e) { Renter r = (Renter)renterBindingSource.Current; DialogResult dr = MessageBox.Show("Вы действтиельно хотите удалить арендатора - " + r.Name.ToString(), "Удаление арендатора", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { db.Renter.Remove(r); try { db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } renterBindingSource.DataSource = db.Renter.ToList(); }