Пример #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();
    }
Пример #2
0
    private void ShowFormPanel(string Role_ID)
    {
        pnlGrid.Visible = false;
        pnlForm.Visible = true;


        if (!string.IsNullOrEmpty(Role_ID))
        {
            dbo_RoleClass role = dbo_RoleDataClass.Select_Record(Role_ID);

            txtRole_ID.Text   = role.Role_ID;
            txtRole_Name.Text = role.Role_Name;


            TreeView2.Nodes.Clear();
            TreeView2.ShowLines = false;

            List <MenuNode> RootNode = dbo_RolePermissionDataClass.GetMenuNode(int.Parse(txtRole_ID.Text));
            BindTree(RootNode, null);


            TreeView2.ExpandAll();
            TreeView2.ShowLines = false;
        }
    }
Пример #3
0
    protected void GridViewRole_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int RowIndex = Convert.ToInt32((e.RowIndex).ToString());

        Label        _lblRole_ID = (Label)GridViewRole.Rows[RowIndex].FindControl("lblRole_ID");
        TextBox      _Row_Name   = (TextBox)GridViewRole.Rows[RowIndex].FindControl("txtEditRole_Name");
        DropDownList _Role_Type  = (DropDownList)GridViewRole.Rows[RowIndex].FindControl("ddlEditRole_Type");

        if (string.IsNullOrEmpty(_Row_Name.Text) || _Role_Type.SelectedIndex == 0)
        {
            System.Threading.Thread.Sleep(500);
            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
            Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน");
        }
        else
        {
            dbo_RoleClass role = new dbo_RoleClass()
            {
                Role_ID = _lblRole_ID.Text, Role_Name = _Row_Name.Text, Role_Type = _Role_Type.SelectedValue
            };

            bool   success = false;
            string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;

            success = dbo_RoleDataClass.Update(role, User_ID);


            if (!success)
            {
                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("บันทึกไม่สำเร็จ กรุณาติดต่อผู้ดูแลระบบ");
                //Alert("Error", string.Empty);
            }
            else
            {
                //Alert("Success", string.Empty);

                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("บันทึกสำเร็จ");
                GridViewRole.EditIndex  = -1;
                GridViewRole.ShowFooter = false;

                SearchSubmit();

                //DataTable dt = dbo_RoleDataClass.SelectAll();
                //GridViewRole.DataSource = dt.DefaultView;
                //GridViewRole.DataBind();

                LinkButton btnEdit_ = (LinkButton)GridViewRole.Rows[RowIndex].FindControl("lnkB_SetPermission");
                btnEdit_.Visible = true;
            }
        }
    }
Пример #4
0
    public static bool Delete(dbo_RoleClass clsdbo_Role)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        deleteProcedure = "[RoleDelete]";
        SqlCommand    deleteCommand   = new SqlCommand(deleteProcedure, connection);

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

        //if (clsdbo_Role.Role_Name != null)
        //{
        //    deleteCommand.Parameters.AddWithValue("@OldRole_Name", clsdbo_Role.Role_Name);
        //}
        //else
        //{
        //    deleteCommand.Parameters.AddWithValue("@OldRole_Name", 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();
        }
    }
Пример #5
0
    protected void GridViewRole_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditPermission")
        {
            LinkButton lnkView = (LinkButton)e.CommandSource;
            string     Role_ID = lnkView.CommandArgument;

            ShowFormPanel(Role_ID);
        }
        else if (e.CommandName == "AddNew")
        {
            TextBox      _Row_ID    = (TextBox)GridViewRole.FooterRow.FindControl("txtNewRole_ID");
            TextBox      _Row_Name  = (TextBox)GridViewRole.FooterRow.FindControl("txtNewRole_Name");
            DropDownList _Role_Type = (DropDownList)GridViewRole.FooterRow.FindControl("ddlNewRole_Type");

            if (string.IsNullOrEmpty(_Row_Name.Text) || _Role_Type.SelectedIndex == 0)
            {
                System.Threading.Thread.Sleep(500);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                Show("กรุณากรอกข้อมูลที่จำเป็นให้ครบถ้วน");
            }
            else
            {
                dbo_RoleClass role = new dbo_RoleClass()
                {
                    Role_ID = int.Parse(_Row_ID.Text).ToString("00").ToString(), Role_Name = _Row_Name.Text, Role_Type = _Role_Type.SelectedValue
                };
                string User_ID = HttpContext.Current.Request.Cookies["User_ID"].Value;
                bool   success = dbo_RoleDataClass.Add(role, User_ID);

                if (success)
                {
                    System.Threading.Thread.Sleep(500);
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    Show("บันทึกสำเร็จ");
                }
                else
                {
                    System.Threading.Thread.Sleep(500);
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "SAMWAIT", "myApp.hidePleaseWait();", true);
                    Show("บันทึกไม่สำเร็จ กรุณาติดต่อผู้ดูแลระบบ");
                }

                GridViewRole.ShowFooter = false;
                SearchSubmit();
            }
        }
    }
Пример #6
0
    public static dbo_RoleClass Select_Record(string Role_ID)
    {
        dbo_RoleClass clsdbo_Role     = new dbo_RoleClass();
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        selectProcedure = "[RoleSelect]";
        SqlCommand    selectCommand   = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;
        selectCommand.Parameters.AddWithValue("@Role_ID", Role_ID);
        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_Role.Role_ID   = reader["Role_ID"] is DBNull ? null : reader["Role_ID"].ToString();
                clsdbo_Role.Role_Name = reader["Role_Name"] is DBNull ? null : reader["Role_Name"].ToString();
            }
            else
            {
                clsdbo_Role = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_Role);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_Role);
    }
Пример #7
0
    public static bool Update(dbo_RoleClass newdbo_RoleClass, String Last_Modified_By)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        updateProcedure = "RoleUpdate";
        SqlCommand    updateCommand   = new SqlCommand(updateProcedure, connection);

        updateCommand.CommandType = CommandType.StoredProcedure;
        if (newdbo_RoleClass.Role_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewRole_ID", newdbo_RoleClass.Role_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewRole_ID", DBNull.Value);
        }
        if (newdbo_RoleClass.Role_Name != null)
        {
            updateCommand.Parameters.AddWithValue("@NewRole_Name", newdbo_RoleClass.Role_Name);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewRole_Name", DBNull.Value);
        }
        if (newdbo_RoleClass.Role_Type != null)
        {
            updateCommand.Parameters.AddWithValue("@RoleType", newdbo_RoleClass.Role_Type);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@RoleType", DBNull.Value);
        }
        if (Last_Modified_By != null)
        {
            updateCommand.Parameters.AddWithValue("@Last_Modified_By", Last_Modified_By);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@Last_Modified_By", 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();
        }
    }
Пример #8
0
    public static bool Add(dbo_RoleClass clsdbo_Role, String Created_By)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        insertProcedure = "[RoleInsert]";
        SqlCommand    insertCommand   = new SqlCommand(insertProcedure, connection);

        insertCommand.CommandType = CommandType.StoredProcedure;
        if (clsdbo_Role.Role_ID != null)
        {
            insertCommand.Parameters.AddWithValue("@Role_ID", clsdbo_Role.Role_ID);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Role_ID", DBNull.Value);
        }
        if (clsdbo_Role.Role_Name != null)
        {
            insertCommand.Parameters.AddWithValue("@Role_Name", clsdbo_Role.Role_Name);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@Role_Name", DBNull.Value);
        }
        if (clsdbo_Role.Role_Type != null)
        {
            insertCommand.Parameters.AddWithValue("@RoleType", clsdbo_Role.Role_Type);
        }
        else
        {
            insertCommand.Parameters.AddWithValue("@RoleType", 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();
        }
    }