private void btnDelete2_Click(object sender, EventArgs e) { try { if (cbxList2.SelectedIndex == 0) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _userPhone = _wrt.UserPhones.FirstOrDefault(p => p.Id == id); _wrt.UserPhones.DeleteOnSubmit(_userPhone); _wrt.SubmitChanges(); GetUserPhoneTable(); MessageBox.Show("Entity deleted successfully"); tbxNameIki.Text = ""; } else if (cbxList2.SelectedIndex == 1) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _ManagementPhone = _wrt.ManagementPhones.FirstOrDefault(p => p.Id == id); _wrt.ManagementPhones.DeleteOnSubmit(_ManagementPhone); _wrt.SubmitChanges(); GetManagementPhoneTable(); MessageBox.Show("Entity deleted successfully"); tbxNameIki.Text = ""; } else if (cbxList2.SelectedIndex == 2) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _ManagementShelter = _wrt.ManagementShelters.FirstOrDefault(p => p.Id == id); _wrt.ManagementShelters.DeleteOnSubmit(_ManagementShelter); _wrt.SubmitChanges(); GetManagementShelterTable(); MessageBox.Show("Entity deleted successfully"); tbxNameIki.Text = ""; } else if (cbxList2.SelectedIndex == 3) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _rOf = _wrt.ResponsibleOfManagements.FirstOrDefault(p => p.Id == id); _wrt.ResponsibleOfManagements.DeleteOnSubmit(_rOf); _wrt.SubmitChanges(); GetResponsibleOfManagementTable(); MessageBox.Show("Entity deleted successfully"); tbxNameIki.Text = ""; } else if (cbxList2.SelectedIndex == 4) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _sOu = _wrt.ShelterOfUsers.FirstOrDefault(p => p.Id == id); _wrt.ShelterOfUsers.DeleteOnSubmit(_sOu); _wrt.SubmitChanges(); GetShelterOfUserTable(); MessageBox.Show("Entity deleted successfully"); tbxNameIki.Text = ""; } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
private void btUpdate2_Click(object sender, EventArgs e) { try { if (cbxList2.SelectedIndex == 0) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _userPhone = _wrt.UserPhones.FirstOrDefault(up => up.Id == id); _userPhone.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _userPhone.PhoneId = Convert.ToInt32(cbxPhoneTypeId.SelectedValue); _userPhone.PhoneNumber = tbxNameIki.Text; _wrt.SubmitChanges(); GetUserPhoneTable(); tbxNameIki.Text = ""; MessageBox.Show("Entity updated successfully"); } else if (cbxList2.SelectedIndex == 1) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _ManagementPhone = _wrt.ManagementPhones.FirstOrDefault(up => up.Id == id); _ManagementPhone.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _ManagementPhone.PhoneTypeId = Convert.ToInt32(cbxPhoneTypeId.SelectedValue); _ManagementPhone.PhoneNumber = tbxNameIki.Text; _wrt.SubmitChanges(); GetManagementPhoneTable(); tbxNameIki.Text = ""; MessageBox.Show("Entity updated successfully"); } else if (cbxList2.SelectedIndex == 2) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _ManagementShelter = _wrt.ManagementShelters.FirstOrDefault(up => up.Id == id); _ManagementShelter.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _ManagementShelter.ShelterId = Convert.ToInt32(cbxShelterId.SelectedValue); if (cbxTrue.Checked == true) { _ManagementShelter.Active = true; } else if (cbxFalse.Checked == true) { _ManagementShelter.Active = false; } _wrt.SubmitChanges(); GetManagementShelterTable(); tbxNameIki.Text = ""; cbxTrue.Checked = false; cbxFalse.Checked = false; MessageBox.Show("Entity updated successfully"); } else if (cbxList2.SelectedIndex == 3) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _rOf = _wrt.ResponsibleOfManagements.FirstOrDefault(up => up.Id == id); _rOf.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _rOf.ManagementId = Convert.ToInt32(cbxManagementId.SelectedValue); _wrt.SubmitChanges(); GetResponsibleOfManagementTable(); tbxNameIki.Text = ""; MessageBox.Show("Entity updated successfully"); } else if (cbxList2.SelectedIndex == 4) { int id = Convert.ToInt32(dgwAddPart.CurrentRow.Cells[0].Value); _sOu = _wrt.ShelterOfUsers.FirstOrDefault(up => up.Id == id); _sOu.UserId = Convert.ToInt32(cbxUserId.SelectedValue); _sOu.ShelterId = Convert.ToInt32(cbxShelterId.SelectedValue); if (cbxTrue.Checked == true) { _sOu.Active = true; } else if (cbxFalse.Checked == true) { _sOu.Active = false; } _wrt.SubmitChanges(); GetShelterOfUserTable(); tbxNameIki.Text = ""; cbxTrue.Checked = false; cbxFalse.Checked = false; MessageBox.Show("Entity updated successfully"); } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }