void New() { tblPaziresh = new tblPaziresh(); SaveType = 1; BindGrid(); ClsTools.ClearContent(pnlNewEdit); btnDelete.Enabled = false; }
void UpdateRow() { try { HospitalEntities db = new HospitalEntities(); tblPaziresh = db.tblPazireshes.Find(tblPaziresh.PazireshID); if (tblPaziresh == null) { FarsiMessagbox.Show(ClsMessage.ErrNotFound, "خطا", FMessageBoxButtons.Ok, FMessageBoxIcon.Error); return; } tblPaziresh.NameBimar = txtName_.Text; tblPaziresh.LastNameBimar = txtLastName_.Text; tblPaziresh.CodeMelliBimar = txtCodeMelli_.Text; tblPaziresh.CodeBimeBimar = txtCodeBime.Text; tblPaziresh.PezeshkID = (int)cmbPezeshk_.SelectedValue; tblPaziresh.OtaghID = (int)cmbOtagh_.SelectedValue; db.Entry(tblPaziresh).State = EntityState.Modified; //db.Entry(tblPersonnel).Property(x => x).IsModified = true; db.Entry(tblPaziresh).Property(x => x.TarikhPaziresh).IsModified = false; 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 DeleteRow() { try { HospitalEntities db = new HospitalEntities(); tblPaziresh = db.tblPazireshes.Find(tblPaziresh.PazireshID); db.tblPazireshes.Remove(tblPaziresh); 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 InsertRow() { try { HospitalEntities db = new HospitalEntities(); tblPaziresh tblPaziresh = new tblPaziresh(); tblPaziresh.NameBimar = txtName_.Text; tblPaziresh.LastNameBimar = txtLastName_.Text; tblPaziresh.CodeMelliBimar = txtCodeMelli_.Text; tblPaziresh.CodeBimeBimar = txtCodeBime.Text; tblPaziresh.PezeshkID = (int)cmbPezeshk_.SelectedValue; tblPaziresh.OtaghID = (int)cmbOtagh_.SelectedValue; tblPaziresh.TarikhPaziresh = ClsTools.ShamsiDate(); db.tblPazireshes.Add(tblPaziresh); 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); } }