918博天堂

Server : Microsoft-IIS/10.0
System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586
User : jxgj ( 0)
PHP Version : 7.0.33
Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server
Directory :  D:/tmp_aspnet/root/6b11be23/e503b68d/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : D:/tmp_aspnet/root/6b11be23/e503b68d/App_Web_w108wsth.7.cs
?#pragma checksum "D:\wwwroot\keman\wwwroot\Back\main\Admin_Role_Add.aspx.cs" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "42347739D3E6FE727CF2CED7803DB2FC"

#line 1 "D:\wwwroot\keman\wwwroot\Back\main\Admin_Role_Add.aspx.cs"
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Data.OleDb;
using CoreClass;

public partial class Back_Main_Admin_Role_Add : System.Web.UI.Page
{
    protected CoreClass.PublicFunction pubfun = new PublicFunction();
    protected CoreClass.DBCommon dbc = new DBCommon();
    protected DataTable dtRights;

    protected int id;//adminid
    protected System.Collections.Hashtable hash = new Hashtable();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.pubfun.checkAdminAccessRights(this.Page, "AdminRoles");
        pubfun.RegisterAdminPageClientScriptBlock(Page);
        if (pubfun.IsNumeric(Request.QueryString["id"])) id = Int32.Parse(this.Request.QueryString["id"].Trim());
        if (!IsPostBack)
        {
            this.InitPage();
        }
    }

    private void InitPage()
    {
        string sql;
        if (id > 0)
        {
            sql = "select top 1 * from AdminRoles where Id = " + this.id.ToString();
            OleDbDataReader dr = this.dbc.GetDataReaderBySql(sql);
            if (dr.Read())
            {
                this.iptRoleName.Text = dr["Name"].ToString();
                this.iptOrderNum.Text = dr["OrderNum"].ToString();
            }
            else
            {
                dr.Close();
                Response.Redirect("Admin_Roles.aspx");
                Response.End();
                return;
            }
            dr.Close();

            sql = "Select * From AdminRoleRights Where RoleId=" + this.id.ToString();
            DataTable dt = this.dbc.GetDataTableBySql(sql);
            foreach (DataRow row in dt.Rows)
            {
                this.hash.Add(row["Rights"].ToString(), row["RoleId"].ToString());
            }
            dt.Dispose();
        }

        sql = "Select * from MenuItems where isRights=true Order By OrderNum";
        this.dtRights = this.dbc.GetDataTableBySql(sql);
        this.dtRights.Columns.Add("Readed", typeof(bool));
        foreach (DataRow row in this.dtRights.Rows)
        {
            row["readed"] = false;
        }
        this.lblContainer.Text = this.GenerateMenuBody();
    }

    private string GenerateMenuBody()
    {
        return this.GenerateMenuBody("", 0);
    }

    private string GenerateMenuBody(string pkey, int level)
    {
        StringBuilder sb = new StringBuilder();
        string textweight = "";
        string boxcheck = "";

        foreach (DataRow row in this.dtRights.Rows)
        {
            if (row["pkey"].ToString().Trim() == pkey && Convert.ToBoolean(row["readed"].ToString()) == false)
            {
                row["Readed"] = true;
                if (Boolean.Parse(row["isFolder"].ToString()))
                {
                    textweight = "bold";
                }
                else
                {
                    textweight = "normal";
                }
                if (id > 0)
                {
                    if (this.hash.ContainsKey(row["MenuKey"].ToString()))
                    {
                        boxcheck = " checked";
                    }
                    else
                    {
                        boxcheck = "";
                    }
                }
                sb.Append("<div style=\"text-indent:" + Convert.ToString(20 * level) + "px;margin-top:5px; width:100%; font-weight:" + textweight + "\"><input type=\"checkbox\" name=\"chkRights\" id=\"chk_" + row["MenuKey"].ToString() + "\" parent=\"chk_" + row["PKey"].ToString() + "\" value=\"" + row["MenuKey"].ToString() + "\" onclick=\"javascript:clk('chk_" + row["MenuKey"].ToString() + "');\"" + boxcheck + "/>" + row["MenuTitle"].ToString() + "</div>");
                if (this.dtRights.Select("pkey='" + row["MenuKey"].ToString() + "'").Length > 0)
                {
                    sb.Append(this.GenerateMenuBody(row["MenuKey"].ToString(), level + 1));
                }
            }
        }
        return sb.ToString();
    }
    
    protected void btnOk_Click(object sender, EventArgs e)
    {
        this.saveSetting();
    }

    private void saveSetting()
    {
        if (pubfun.IsBlank(this.iptRoleName.Text))
        {
            pubfun.Alert(Page, "请填写用户组名!");
            iptRoleName.Focus();
            return;
        }
        if (!pubfun.IsNumeric(this.iptOrderNum.Text))
        {
            pubfun.Alert(Page, "排序填写不正确!");
            iptOrderNum.Focus();
            return;
        }
        if (id > 0)
        {
            //批改后的沉名检测及更新
            OleDbCommand cmd = this.dbc.GetCommandBySql("select top 1 * from AdminRoles where Name=@name and Id<>@id");
            cmd.Parameters.Add("@name", OleDbType.VarChar, 100).Value = this.pubfun.SubStringByByte(this.iptRoleName.Text.Trim(), 100);
            cmd.Parameters.Add("@id", OleDbType.VarChar, 5).Value = this.id;
            cmd.Connection.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                this.Response.Write("<script>alert(\"你批改后的用户组已经存在!\");history.go(-1);</script>");
                dr.Close();
                cmd.Connection.Close();
                cmd.Connection.Dispose();
                cmd.Dispose();
                return;
            }
            dr.Close();
            cmd.CommandText = "Update AdminRoles Set Name=@name,ordernum=@ordernum where id=@id";
            cmd.Parameters.Add("@ordernum", OleDbType.VarChar, 5).Value = Int32.Parse(this.iptOrderNum.Text.Trim());
            cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            cmd.Connection.Dispose();

            //更新组权限
            this.dbc.ExcuteSql("delete from AdminRoleRights Where RoleId=" + this.id.ToString());
            if (this.Request.Form["chkRights"] != null)
            {
                cmd = this.dbc.GetCommandBySql("select * from AdminRoleRights Where RoleId=" + this.id.ToString());
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                string[] values = this.Request.Form.GetValues("chkRights");
                for (int i = 0; i < values.Length; i++)
                {
                    dt.Rows.Add(dt.NewRow());
                    dt.Rows[i]["RoleId"] = this.id;
                    dt.Rows[i]["Rights"] = values[i];
                }
                da.InsertCommand = new OleDbCommand("Insert Into AdminRoleRights(RoleId,Rights) values(@RoleId,@rights)");
                da.InsertCommand.Parameters.Add("@RoleId", OleDbType.VarChar, 5, "RoleId");
                da.InsertCommand.Parameters.Add("@rights", OleDbType.VarChar, 50, "Rights");
                da.InsertCommand.Connection = cmd.Connection;
                da.Update(dt);
                da.Dispose();
                cmd.Dispose();
            }
        }
        else
        {
            //沉名检测及增长
            OleDbCommand cmd = this.dbc.GetCommandBySql("select top 1 * from AdminRoles where Name=@name");
            cmd.Parameters.Add("@name", OleDbType.VarChar, 100).Value = this.pubfun.SubStringByByte(this.iptRoleName.Text.Trim(), 100);
            cmd.Connection.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                this.Response.Write("<script>alert(\"你增长的用户组已经存在!\");history.go(-1);</script>");
                dr.Close();
                cmd.Connection.Close();
                cmd.Connection.Dispose();
                cmd.Dispose();
                return;
            }
            dr.Close();
            cmd.CommandText = "Insert Into AdminRoles(Name,ordernum) values(@name,@ordernum)";
            cmd.Parameters.Add("@ordernum", OleDbType.VarChar, 5).Value = Int32.Parse(this.iptOrderNum.Text.Trim());
            cmd.ExecuteNonQuery();

            cmd.CommandText = "select top 1 * from AdminRoles where Name=@name";
            dr = cmd.ExecuteReader();
            dr.Read();
            int roleid = Int32.Parse(dr["Id"].ToString());
            dr.Close();
            cmd.Connection.Close();
            cmd.Connection.Dispose();

            //增长权限
            if (this.Request.Form["chkRights"] != null)
            {
                cmd = this.dbc.GetCommandBySql("select * from AdminRoleRights Where RoleId is null");
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                string[] values = this.Request.Form.GetValues("chkRights");
                for (int i = 0; i < values.Length; i++)
                {
                    dt.Rows.Add(dt.NewRow());
                    dt.Rows[i]["RoleId"] = roleid;
                    dt.Rows[i]["Rights"] = values[i];
                }
                da.InsertCommand = new OleDbCommand("Insert Into AdminRoleRights(RoleId,Rights) values(@RoleId,@Rights)");
                da.InsertCommand.Parameters.Add("@RoleId", OleDbType.VarChar, 5, "RoleId");
                da.InsertCommand.Parameters.Add("@Rights", OleDbType.VarChar, 50, "Rights");
                da.InsertCommand.Connection = cmd.Connection;
                da.Update(dt);
                da.Dispose();
                cmd.Dispose();
            }
        }
        this.AddInfo.Enabled = false;
        pubfun.RegisterStartupScript(Page, "PAGE", "window.location.href='Admin_Roles.aspx';");
        return;
    }
}


#line default
#line hidden