void InsertRow() { try { HospitalEntities db = new HospitalEntities(); tblOtagh = new tblOtagh(); tblOtagh.CodeOtagh = txtCodeOtagh_.Text; tblOtagh.BakshID = (int)cmbBakhsh_.SelectedValue; db.tblOtaghs.Add(tblOtagh); db.SaveChanges(); New(); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("\n", errorMessages); var exceptionMessage = string.Concat(ClsMessage.Error, ex.Message, " The validation errors are: ", fullErrorMessage); FarsiMessagbox.Show(exceptionMessage, "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } catch (DbUpdateException ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } catch (Exception ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } }
void New() { tblOtagh = new tblOtagh(); SaveType = 1; BindGrid(); ClsTools.ClearContent(pnlNewEdit); btnDelete.Enabled = false; }
void BindRow() { try { HospitalEntities db = new HospitalEntities(); tblOtagh = db.tblOtaghs.Find(tblOtagh.OtaghID); if (tblOtagh == null) { FarsiMessagbox.Show(ClsMessage.ErrNotFound, "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); return; } txtCodeOtagh_.Text = tblOtagh.CodeOtagh; cmbBakhsh_.SelectedValue = tblOtagh.BakshID; } catch (Exception ex) { FarsiMessagbox.Show(ClsMessage.ErrNotFound + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } }
void DeleteRow() { try { HospitalEntities db = new HospitalEntities(); tblOtagh = db.tblOtaghs.Find(tblOtagh.OtaghID); db.tblOtaghs.Remove(tblOtagh); db.SaveChanges(); New(); } catch (DbUpdateException ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } catch (Exception ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } }
void UpdateRow() { try { HospitalEntities db = new HospitalEntities(); tblOtagh = db.tblOtaghs.Find(tblOtagh.OtaghID); if (tblOtagh == null) { FarsiMessagbox.Show(ClsMessage.ErrNotFound, "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); return; } tblOtagh.CodeOtagh = txtCodeOtagh_.Text; tblOtagh.BakshID = (int)cmbBakhsh_.SelectedValue; db.tblOtaghs.Attach(tblOtagh); db.Entry(tblOtagh).State = EntityState.Modified; db.SaveChanges(); New(); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var fullErrorMessage = string.Join("\n", errorMessages); var exceptionMessage = string.Concat(ClsMessage.Error, ex.Message, " The validation errors are: ", fullErrorMessage); FarsiMessagbox.Show(exceptionMessage, "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } catch (DbUpdateException ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } catch (Exception ex) { FarsiMessagbox.Show(ClsMessage.Error + "\n" + ex.Message.ToString(), "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); } }