示例#1
0
        private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                //  var d = (DataGridView)sender;
                //  var df = d.SelectedCells[0].Value.ToString();
                //  if(df == "Edit") (df == "Delete")

                if (!LoggedInUser.IsAdmin)
                {
                    Base.ShowError("Access Denied", "You do not have the required permission");
                    return;
                }

                //edit column
                if (e.ColumnIndex == 0)
                {
                    var id   = dataGrid.Rows[e.RowIndex].Cells["id"].Value.ToString();
                    var item = _repo.GetCourse(id);
                    if (item != null)
                    {
                        var updateForm = new FrmCourse(item.Id);
                        updateForm.ShowDialog();
                        LoadData();
                    }
                }

                //delete column
                if (e.ColumnIndex == 1)
                {
                    var result = Base.ShowDialog(MessageBoxButtons.YesNo, "Confirm Delete", "Are you sure you want to delete this record?");
                    if (result == DialogResult.Yes)
                    {
                        var id       = dataGrid.Rows[e.RowIndex].Cells["id"].Value.ToString();
                        var response = _repo.DeleteCourse(id);

                        if (response == string.Empty)
                        {
                            Base.ShowInfo("Success", "Course deleted successfully");
                            LoadData();
                        }

                        else
                        {
                            Base.ShowError("Failed", response);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Base.ShowError("Error occured", ex.Message);
            }
        }
        private void grdData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                var    d  = (DataGridView)sender;
                string df = d.SelectedCells[0].Value.ToString();
                //edit column
                if (df == "Edit")
                {
                    int id     = int.Parse(grdData.Rows[e.RowIndex].Cells["id"].Value.ToString());
                    var course = _courseRepo.GetCourse(id);
                    if (course != null)
                    {
                        var updateForm = new CoursesForm(course);
                        updateForm.ShowDialog();
                        //grdData.Refresh();
                        LoadCourses(deptId);
                    }
                }

                //delete column
                if (df == "Delete")      //(e.ColumnIndex == 1)
                {
                    DialogResult result1 = MessageBox.Show("Are you sure you want to delete this record?",
                                                           "Confirm Delete",
                                                           MessageBoxButtons.YesNo);
                    if (result1 == DialogResult.Yes)
                    {
                        int    id       = int.Parse(grdData.Rows[e.RowIndex].Cells["id"].Value.ToString());
                        string response = _courseRepo.DeleteCourse(id);
                        if (response == string.Empty)
                        {
                            MessageBox.Show(this, "Course deleted successfully", "Success", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show(this, response, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        LoadCourses(deptId);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public ActionResult DeleteCou(int id)
 {
     if (Session["UserId"] != null && Session["Accountid"] != null)
     {
         try
         {
             CourseRepo CouRepo = new CourseRepo();
             if (CouRepo.DeleteCourse(id))
             {
                 ViewBag.AlertMsg = "Course details deleted successfully";
             }
             return(RedirectToAction("GetAllCourse"));
         }
         catch
         {
             return(View());
         }
     }
     else
     {
         return(RedirectToAction("Index", "Login"));
     }
 }