public void GetByForm(RoomAssessment am) { am.ID_Staff = (int)cbbStaff.EditValue; am.ID_Year = (int)cbbYear.SelectedValue; am.Purport = txtPurport.Text; am.ID_Room = id; }
private void btnDelete_Click(object sender, EventArgs e) { if (txtID.Text == "") { MessageBox.Show("Choose Assessment"); } else { DialogResult dr = MessageBox.Show("Do you want delete this assessment?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == dr) { try { RoomAssessment tg = new RoomAssessment(); int id = Convert.ToInt32(txtID.Text); tg = context.RoomAssessments.Where(p => p.ID == id).FirstOrDefault(); context.RoomAssessments.Remove(tg); context.SaveChanges(); MessageBox.Show("Deleted"); LoadDL(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (ok == true) { try { RoomAssessment tg = new RoomAssessment(); GetByForm(tg); var year = context.RoomAssessments.Where(p => p.ID_Year == tg.ID_Year).FirstOrDefault(); if (year != null) { MessageBox.Show("The rating of this year entered"); } else { context.RoomAssessments.Add(tg); context.SaveChanges(); MessageBox.Show("Done"); LoadDL(); btnAdd.Enabled = true; btnEdit.Enabled = true; btnDelete.Enabled = true; btnSave.Enabled = false; btnCancel.Enabled = false; groupBox1.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { int id = Convert.ToInt32(gridAssessment.GetFocusedRowCellValue("IDOfAssessment").ToString()); var tg = context.RoomAssessments.Where(p => p.ID == id).FirstOrDefault(); GetByForm(tg); // context.RoomAssessments.Add(tg); context.SaveChanges(); MessageBox.Show("Done"); LoadDL(); btnAdd.Enabled = true; btnEdit.Enabled = true; btnDelete.Enabled = true; btnSave.Enabled = false; btnCancel.Enabled = false; groupBox1.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }