Esempio n. 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            User usr = (User)dgvUsers.SelectedRows[0].DataBoundItem;

            if (MessageBox.Show("آیا مایل به حذف این کاربر هستید؟", "حذف " + usr.RealName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading) == DialogResult.Yes)
            {
                ctx.Users.Remove(usr);
                try
                {
                    ctx.SaveChanges();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
                {
                    new frmMsgBox(ex.ToString(), "امکان حذف کاربری که عملیات انجام داده وجود ندارد.").ShowDialog();
                    //MessageBox.Show("امکان حذف کاربری که عملیات انجام داده وجود ندارد.\n\n" + .Remove(500) + "...", "خطا در حذف کاربر", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    ctx.Entry(usr).Reload();
                    return;
                }
                getData();
            }//if
        }
Esempio n. 2
0
        }     //btnNew

        private void btnDelete_Click(object sender, EventArgs e)
        {
            int   id    = (int)dgvShifts.SelectedRows[0].Cells["colID"].Value;
            Shift shift = (from s in ctx.Shifts where s.ID == id select s).First();

            if (new frmMsgBox("آیا مایل به حذف این شیفت هستید؟", "حذف شیفت", MessageBoxButtons.YesNo, MsgBoxIcon.Question).ShowDialog() == DialogResult.Yes)
            {
                ctx.Shifts.Remove(shift);
                try
                {
                    ctx.SaveChanges();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
                {
                    new frmMsgBox(ex.ToString(), "امکان حذف شیفتی که متقاضی در آن ثبت شده وجود ندارد.", MessageBoxButtons.OK, MsgBoxIcon.Error).ShowDialog();
                    ctx.Entry(shift).Reload();
                }
                refreshGrid();
            }//if
        }