private void btnAddPerm_Click(object sender, System.EventArgs e)
 {
     try
     {
         if (Request.QueryString["id"] == null)
         {
             Session["lastpage"] = "admin_groups.aspx";
             Session["error"]    = _functions.ErrorMessage(104);
             Response.Redirect("error.aspx", false);
             return;
         }
         try
         {
             GroupId = Convert.ToInt32(Request.QueryString["id"]);
         }
         catch (FormatException fex)
         {
             Session["lastpage"] = "admin_groups.aspx";
             Session["error"]    = _functions.ErrorMessage(105);
             Response.Redirect("error.aspx", false);
             return;
         }
         perm          = new clsPermissions();
         perm.cAction  = "I";
         perm.iId      = Convert.ToInt32(ddlNewPerm.SelectedValue);
         perm.iOrgId   = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
         perm.iGroupId = GroupId;
         if (perm.GroupsPermissionsDetail() == -1)
         {
             Session["lastpage"] = "admin_groups_permissions.aspx?id=" + GroupId.ToString();
             Session["error"]    = _functions.ErrorMessage(116);
             Response.Redirect("error.aspx", false);
             return;
         }
         else
         {
             Response.Redirect("admin_groups_permissions.aspx?id=" + GroupId.ToString(), false);
         }
     }
     catch (Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"]     = "admin_groups_permissions.aspx?id=" + GroupId.ToString();
         Session["error"]        = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if (perm != null)
         {
             perm.Dispose();
         }
     }
 }
 private void dgPermissions_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
     try
     {
         if (Request.QueryString["id"] == null)
         {
             Session["lastpage"] = "admin_groups.aspx";
             Session["error"]    = _functions.ErrorMessage(104);
             Response.Redirect("error.aspx", false);
             return;
         }
         try
         {
             GroupId = Convert.ToInt32(Request.QueryString["id"]);
         }
         catch (FormatException fex)
         {
             Session["lastpage"] = "admin_groups.aspx";
             Session["error"]    = _functions.ErrorMessage(105);
             Response.Redirect("error.aspx", false);
             return;
         }
         perm          = new clsPermissions();
         perm.cAction  = "D";
         perm.iId      = Convert.ToInt32(e.Item.Cells[0].Text);
         perm.iOrgId   = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
         perm.iGroupId = GroupId;
         if (perm.GroupsPermissionsDetail() == -1)
         {
             Session["lastpage"] = "admin_groups_permissions.aspx?id=" + GroupId.ToString();
             Session["error"]    = _functions.ErrorMessage(116);
             Response.Redirect("error.aspx", false);
             return;
         }
         else
         {
             Response.Redirect("admin_groups_permissions.aspx?id=" + GroupId.ToString(), false);
         }
     }
     catch (Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"]     = "admin_groups_permissions.aspx?id=" + GroupId.ToString();
         Session["error"]        = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if (perm != null)
         {
             perm.Dispose();
         }
     }
 }