protected void btn_Cancel_Click(object sender, EventArgs e)
 {
     try
     {
         lbl_AssignSecurity.Text = "Assign Privilege";
         LoadGrid();
         Rg_AssignSecurity.DataBind();
         Rm_AssignSecurity.SelectedIndex = 0;
     }
     catch (Exception ex)
     {
         SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_securityprivilages", ex.StackTrace, DateTime.Now);
         Response.Redirect("~/Frm_ErrorPage.aspx");
     }
 }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            RadioButton Chk_FullControl = new RadioButton();

            RadioButton       Chk_View                  = new RadioButton();
            RadioButton       Chk_NotApplicable         = new RadioButton();
            Label             lbl_form_id               = new Label();
            SMHR_TYPESECURITY _obj_Smhr_AssignPrivilage = new SMHR_TYPESECURITY();

            _obj_Smhr_AssignPrivilage.TYPSEC_LOGTYP_ID = Convert.ToInt32(rcmb_Usergroup.SelectedItem.Value);
            _obj_Smhr_AssignPrivilage.SUPER_MODULE_ID  = Convert.ToInt32(rcmb_sup_module.SelectedItem.Value);
            _obj_Smhr_AssignPrivilage.MODULE_ID        = Convert.ToInt32(rcmb_Module.SelectedItem.Value);
            _obj_Smhr_AssignPrivilage.CREATEDBY        = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_AssignPrivilage.CREATEDDATE      = DateTime.Now;
            if (Convert.ToInt32(Session["EMP_ID"]) == (-1))
            {
                _obj_Smhr_AssignPrivilage.TYPESEC_ORG_ID = Convert.ToInt32(rcmb_Organisation.SelectedItem.Value);
            }
            else
            {
                _obj_Smhr_AssignPrivilage.TYPESEC_ORG_ID = Convert.ToInt32(Session["ORG_ID"]);
            }

            _obj_Smhr_AssignPrivilage.LASTMDFBY   = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_AssignPrivilage.LASTMDFDATE = DateTime.Now;
            for (int i = 0; i <= Rg_Securitygrid.Items.Count - 1; i++)
            {
                Chk_FullControl   = Rg_Securitygrid.Items[i].FindControl("Chk_FullControl") as RadioButton;
                lbl_form_id       = Rg_Securitygrid.Items[i].FindControl("LBL_form_ID") as Label;
                Chk_View          = Rg_Securitygrid.Items[i].FindControl("Chk_View") as RadioButton;
                Chk_NotApplicable = Rg_Securitygrid.Items[i].FindControl("Chk_NotApplicable") as RadioButton;

                _obj_Smhr_AssignPrivilage.TYPSEC_FORMS_ID = Convert.ToInt32(lbl_form_id.Text);

                if (Chk_FullControl.Checked)
                {
                    _obj_Smhr_AssignPrivilage.TYPSEC_READ = true;

                    _obj_Smhr_AssignPrivilage.TYPSEC_WRITE = true;
                }

                if (Chk_View.Checked)
                {
                    _obj_Smhr_AssignPrivilage.TYPSEC_READ = true;

                    _obj_Smhr_AssignPrivilage.TYPSEC_WRITE = false;
                }

                if (Chk_NotApplicable.Checked)
                {
                    _obj_Smhr_AssignPrivilage.TYPSEC_READ = false;

                    _obj_Smhr_AssignPrivilage.TYPSEC_WRITE = false;
                }
                if ((Chk_FullControl.Checked == false) && (Chk_View.Checked == false) && (Chk_NotApplicable.Checked == false))
                {
                    _obj_Smhr_AssignPrivilage.TYPSEC_READ = false;

                    _obj_Smhr_AssignPrivilage.TYPSEC_WRITE = false;
                }

                //to check a user group has been assigned selected froms or not
                //_obj_Smhr_AssignPrivilage.OPERATION = operation.Check;
                //_obj_Smhr_AssignPrivilage.TYPSEC_LOGTYP_ID = Convert.ToInt32(rcmb_Usergroup.SelectedItem.Value);
                //_obj_Smhr_AssignPrivilage.TYPSEC_FORMS_ID = Convert.ToInt32(lbl_form_id.Text);
                //if (Convert.ToString(BLL.get_AssignPrivilage(_obj_Smhr_AssignPrivilage).Rows[0]["Count"]) !="0")
                //{
                //    BLL.ShowMessage(this, "This Combination of the Privilage Already Exists");
                //    Rm_AssignSecurity.SelectedIndex = 0;
                //    LoadGrid();
                //    Rg_AssignSecurity.DataBind();
                //    lbl_AssignSecurity.Text = "Assign Privilege";
                //    return;
                //}

                _obj_Smhr_AssignPrivilage.OPERATION = operation.Select3;

                bool status = BLL.set_AssignPrivilage(_obj_Smhr_AssignPrivilage);
            }

            BLL.ShowMessage(this, "Record Updated Successfully");
            Rm_AssignSecurity.SelectedIndex = 0;
            LoadGrid();
            Rg_AssignSecurity.DataBind();
            lbl_AssignSecurity.Text = "Assign Privilege";
            ScriptManager.RegisterStartupScript(this, GetType(), "refresh", "window.setTimeout('window.location.reload(true);',0000);", true);
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_securityprivilages", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                lbl_AssignSecurity.Text         = "Assign Privilege";
                Rm_AssignSecurity.SelectedIndex = 0;
                LoadGrid();
                if (Convert.ToString(Session["FILTER"]) != string.Empty)
                {
                    Rg_AssignSecurity.MasterTableView.FilterExpression = Session["FILTER"].ToString();
                    //foreach (GridColumn column in Rg_AssignSecurity.MasterTableView.RenderColumns)
                    //{
                    //    if (column.SupportsFiltering())
                    //    {
                    //        column.FilterControlAltText = Session["FILTER"].ToString();
                    //    }
                    //}
                    //                 Rg_AssignSecurity.MasterTableView.
                    Rg_AssignSecurity.Rebind();
                }
                Rg_AssignSecurity.DataBind();
                Session.Remove("FILTER");
                Page.Validate();

                //code for security privilage
                Session.Remove("WRITEFACILITY");

                SMHR_LOGININFO _obj_Smhr_LoginInfo = new SMHR_LOGININFO();

                _obj_Smhr_LoginInfo.OPERATION       = operation.Empty1;
                _obj_Smhr_LoginInfo.LOGIN_USERNAME  = Convert.ToString(Session["USERNAME"]).Trim();
                _obj_Smhr_LoginInfo.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]);
                _obj_Smhr_LoginInfo.LOGIN_PASS_CODE = Convert.ToString("Assign Privilages");//SECURITY_RIVILAGES");
                DataTable dtformdtls = BLL.get_LoginInfo(_obj_Smhr_LoginInfo);
                if (dtformdtls.Rows.Count != 0)
                {
                    if ((Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_READ"]) == true) && (Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_WRITE"]) == true))
                    {
                        Session["WRITEFACILITY"] = 1;//WHICH MEANS READ AND WRITE
                    }
                    else if ((Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_READ"]) == true) && (Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_WRITE"]) == false))
                    {
                        Session["WRITEFACILITY"] = 2;//WHICH MEANS READ NO WRITE
                    }
                    else if ((Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_READ"]) == false) && (Convert.ToBoolean(dtformdtls.Rows[0]["TYPSEC_WRITE"]) == false))
                    {
                        Session["WRITEFACILITY"] = 3;//WHICH MEANS NO READ AND NO WRITE
                    }
                }
                else
                {
                    smhr_UNAUTHORIZED _obj_smhr_unauthorized = new smhr_UNAUTHORIZED();
                    _obj_smhr_unauthorized.UNAUTHORIZED_USERID     = Convert.ToInt32(Session["USER_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_FORMID     = Convert.ToInt32(ViewState["FORMS_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_MODULEID   = Convert.ToInt32(ViewState["MODULE_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_ACCESSDATE = Convert.ToDateTime(DateTime.Now.ToString());
                    SMHR.BLL.UnAuthorized_Log(_obj_smhr_unauthorized);
                    Response.Redirect("~/frm_UnAuthorized.aspx", false);
                }

                if (Convert.ToInt32(Session["EMP_ID"]) != (-1))
                {
                    if (Convert.ToInt32(Session["WRITEFACILITY"]) == 2)
                    {
                        Rg_AssignSecurity.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
                        btn_Save.Visible   = false;
                        btn_Update.Visible = false;
                    }
                }
                else if (Convert.ToInt32(Session["WRITEFACILITY"]) == 3)
                {
                    smhr_UNAUTHORIZED _obj_smhr_unauthorized = new smhr_UNAUTHORIZED();
                    _obj_smhr_unauthorized.UNAUTHORIZED_USERID     = Convert.ToInt32(Session["USER_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_FORMID     = Convert.ToInt32(ViewState["FORMS_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_MODULEID   = Convert.ToInt32(ViewState["MODULE_ID"]);
                    _obj_smhr_unauthorized.UNAUTHORIZED_ACCESSDATE = Convert.ToDateTime(DateTime.Now.ToString());
                    SMHR.BLL.UnAuthorized_Log(_obj_smhr_unauthorized);
                    Response.Redirect("~/frm_UnAuthorized.aspx", false);
                    btn_Save.Visible   = true;
                    btn_Update.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_securityprivilages", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }