Exemple #1
0
        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);
            }
        }
Exemple #2
0
 void New()
 {
     tblOtagh = new tblOtagh();
     SaveType = 1;
     BindGrid();
     ClsTools.ClearContent(pnlNewEdit);
     btnDelete.Enabled = false;
 }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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);
            }
        }