Example #1
0
    protected void GridViewRole_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int   index       = e.RowIndex;
        Label _lblRole_ID = (Label)GridViewRole.Rows[e.RowIndex].FindControl("lblRole_ID");

        List <dbo_UserClass> user = dbo_UserDataClass.Search(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, _lblRole_ID.Text, string.Empty, null, string.Empty, string.Empty);

        dbo_RoleClass role = new dbo_RoleClass();

        role.Role_ID = _lblRole_ID.Text;

        dbo_RoleDataClass.Delete(role);

        dbo_RolePermissionClass role_per = new dbo_RolePermissionClass();

        role_per.Role_ID = _lblRole_ID.Text;
        dbo_RolePermissionDataClass.Delete(role_per);

        System.Threading.Thread.Sleep(500);
        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
        Show("ลบข้อมูลสำเร็จ");

        GridViewRole.ShowFooter = false;

        SearchSubmit();
    }
Example #2
0
    public void PrintNodesRecursive(TreeNode oParentNode)
    {
        if (oParentNode.Checked)
        {
            dbo_RolePermissionClass role = new dbo_RolePermissionClass();
            role.Function_Name = oParentNode.ToolTip;
            role.Role_ID       = txtRole_ID.Text;
            string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;
            dbo_RolePermissionDataClass.Add(role, User_ID);
        }

        foreach (TreeNode oSubNode in oParentNode.ChildNodes)
        {
            PrintNodesRecursive(oSubNode);
        }
    }
Example #3
0
    public static bool Delete(dbo_RolePermissionClass clsdbo_RolePermission)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        deleteProcedure = "[dbo].[RolePermissionDelete]";
        SqlCommand    deleteCommand   = new SqlCommand(deleteProcedure, connection);

        deleteCommand.CommandType = CommandType.StoredProcedure;

        if (clsdbo_RolePermission.Role_ID != null)
        {
            deleteCommand.Parameters.AddWithValue("@OldRole_ID", clsdbo_RolePermission.Role_ID);
        }
        else
        {
            deleteCommand.Parameters.AddWithValue("@OldRole_ID", DBNull.Value);
        }


        deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
        deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
        try
        {
            connection.Open();
            deleteCommand.ExecuteNonQuery();
            int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value);
            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(false);
        }
        finally
        {
            connection.Close();
        }
    }
Example #4
0
    private void BindTree(IEnumerable <MenuNode> list, TreeNode parentNode)
    {
        var nodes = list.Where(x => parentNode == null ? x.Parent_MenuID == -1 : x.Parent_MenuID == int.Parse(parentNode.Value));

        foreach (var node in nodes)
        {
            TreeNode newNode = new TreeNode(node.Function_Name, node.MenuID.ToString());


            // newNode
            newNode.ToolTip = node.Function_ID;
            if (node.Function_ID == "0000")
            {
                newNode.ShowCheckBox = false;
            }
            else
            {
                newNode.ShowCheckBox = true;
            }


            dbo_RolePermissionClass item = dbo_RolePermissionDataClass.GetRolePermissionByRole_IDAndFunctionName(txtRole_ID.Text, node.Function_ID);

            newNode.Checked = (item == null ? false : true);

            if (parentNode == null)
            {
                TreeView2.ShowLines = false;
                TreeView2.Nodes.Add(newNode);
            }
            else
            {
                parentNode.ChildNodes.Add(newNode);
            }
            BindTree(list, newNode);
        }
    }
Example #5
0
    public static dbo_RolePermissionClass Select_Record(dbo_RolePermissionClass clsdbo_RolePermissionPara)
    {
        dbo_RolePermissionClass clsdbo_RolePermission = new dbo_RolePermissionClass();
        SqlConnection           connection            = SAMDataClass.GetConnection();
        string     selectProcedure = "[dbo].[RolePermissionSelect]";
        SqlCommand selectCommand   = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;
        selectCommand.Parameters.AddWithValue("@Role_Permission_ID", clsdbo_RolePermissionPara.Role_Permission_ID);
        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_RolePermission.Role_Permission_ID = reader["Role_Permission_ID"] is DBNull ? null : reader["Role_Permission_ID"].ToString();
                clsdbo_RolePermission.Role_ID            = reader["Role_ID"] is DBNull ? null : reader["Role_ID"].ToString();
                clsdbo_RolePermission.Function_Name      = reader["Function_Name"] is DBNull ? null : reader["Function_Name"].ToString();
            }
            else
            {
                clsdbo_RolePermission = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_RolePermission);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_RolePermission);
    }
Example #6
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        dbo_RolePermissionClass role = new dbo_RolePermissionClass();

        role.Role_ID = txtRole_ID.Text;
        dbo_RolePermissionDataClass.Delete(role);

        try
        {
            TreeNode oMainNode = (TreeNode)TreeView2.Nodes[0];


            PrintNodesRecursive(oMainNode);
        }
        catch (Exception ex)
        {
            logger.Error(ex.Message);
        }

        System.Threading.Thread.Sleep(500);
        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
        // Show("บันทึกสำเร็จ");
        //pnlGrid.Visible = true;
        //pnlForm.Visible = false;

        //Response.Redirect(Request.UrlReferrer.ToString());
        //Response.Redirect("../Views/RolePermission.aspx");
        //string script = @"swal(""บันทึกสำเร็จ!"", """", ""success"")";
        //ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAM", script, true);

        string script = string.Format("alert('{0}');window.location ='RolePermission.aspx';", "บันทึกสำเร็จ");

        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAM", script, true);
        pnlGrid.Visible = true;
        pnlForm.Visible = false;
    }
Example #7
0
    public static dbo_RolePermissionClass GetRolePermissionByRole_IDAndFunctionName(string Role_ID, string Function_Name)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        selectProcedure = "GetRolePermissionByRole_IDAndFunctionName";
        SqlCommand    selectCommand   = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;


        if (!string.IsNullOrEmpty(Role_ID))
        {
            selectCommand.Parameters.AddWithValue("@Role_ID", Role_ID);
        }
        else
        {
            selectCommand.Parameters.AddWithValue("@Role_ID", DBNull.Value);
        }

        if (!string.IsNullOrEmpty(Function_Name))
        {
            selectCommand.Parameters.AddWithValue("@Function_Name", Function_Name);
        }
        else
        {
            selectCommand.Parameters.AddWithValue("@Function_Name", DBNull.Value);
        }

        dbo_RolePermissionClass clsdbo_RolePermission = new dbo_RolePermissionClass();

        List <dbo_RolePermissionClass> item = new List <dbo_RolePermissionClass>();

        DataTable dt = new DataTable();

        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_RolePermission.Role_Permission_ID = reader["Role_Permission_ID"] is DBNull ? null : reader["Role_Permission_ID"].ToString();
                clsdbo_RolePermission.Role_ID            = reader["Role_ID"] is DBNull ? null : reader["Role_ID"].ToString();
                clsdbo_RolePermission.Function_Name      = reader["Function_Name"] is DBNull ? null : reader["Function_Name"].ToString();
            }
            else
            {
                clsdbo_RolePermission = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_RolePermission);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_RolePermission);
    }
Example #8
0
    public static bool Update(dbo_RolePermissionClass olddbo_RolePermissionClass,
                              dbo_RolePermissionClass newdbo_RolePermissionClass)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        updateProcedure = "[dbo].[RolePermissionUpdate]";
        SqlCommand    updateCommand   = new SqlCommand(updateProcedure, connection);

        updateCommand.CommandType = CommandType.StoredProcedure;
        if (newdbo_RolePermissionClass.Role_Permission_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewRole_Permission_ID", newdbo_RolePermissionClass.Role_Permission_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewRole_Permission_ID", DBNull.Value);
        }
        if (newdbo_RolePermissionClass.Role_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewRole_ID", newdbo_RolePermissionClass.Role_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewRole_ID", DBNull.Value);
        }
        if (newdbo_RolePermissionClass.Function_Name != null)
        {
            updateCommand.Parameters.AddWithValue("@NewFunction_Name", newdbo_RolePermissionClass.Function_Name);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewFunction_Name", DBNull.Value);
        }
        if (olddbo_RolePermissionClass.Role_Permission_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@OldRole_Permission_ID", olddbo_RolePermissionClass.Role_Permission_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@OldRole_Permission_ID", DBNull.Value);
        }
        if (olddbo_RolePermissionClass.Role_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@OldRole_ID", olddbo_RolePermissionClass.Role_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@OldRole_ID", DBNull.Value);
        }
        if (olddbo_RolePermissionClass.Function_Name != null)
        {
            updateCommand.Parameters.AddWithValue("@OldFunction_Name", olddbo_RolePermissionClass.Function_Name);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@OldFunction_Name", DBNull.Value);
        }
        updateCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
        updateCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
        try
        {
            connection.Open();
            updateCommand.ExecuteNonQuery();
            int count = System.Convert.ToInt32(updateCommand.Parameters["@ReturnValue"].Value);
            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(false);
        }
        finally
        {
            connection.Close();
        }
    }
Example #9
0
    public static bool Add(dbo_RolePermissionClass clsdbo_RolePermission, String Created_By)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        insertProcedure = "[RolePermissionInsert]";
        SqlCommand    insertCommand   = new SqlCommand(insertProcedure, connection);

        insertCommand.CommandType = CommandType.StoredProcedure;

        if (clsdbo_RolePermission.Role_ID != null)
        {
            insertCommand.Parameters.AddWithValue("@Role_ID", clsdbo_RolePermission.Role_ID);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Role_ID", DBNull.Value);
        }


        if (clsdbo_RolePermission.Function_Name != null)
        {
            insertCommand.Parameters.AddWithValue("@Function_Name", clsdbo_RolePermission.Function_Name);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Function_Name", DBNull.Value);
        }

        if (Created_By != null)
        {
            insertCommand.Parameters.AddWithValue("@Created_By", Created_By);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Created_By", DBNull.Value);
        }


        insertCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
        insertCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
        try
        {
            connection.Open();
            insertCommand.ExecuteNonQuery();
            int count = System.Convert.ToInt32(insertCommand.Parameters["@ReturnValue"].Value);
            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(false);
        }
        finally
        {
            connection.Close();
        }
    }