using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Base;
using AdminRights;

public partial class admin_Rights_RoleAdd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("system", "A1");
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        string Restr = "";
        //常规管理
        string myValue = "";
        foreach (ListItem li in chkBasic.Items)
        {
            if (li.Selected)
            {
                myValue += li.Value + "1,";
            }
            else
            {
                myValue += li.Value + "0,";
            }

        }
        if (myValue != "")
        {
            myValue = myValue.Substring(0, myValue.Length - 1);
        }
        string strBasic = myValue;
        //栏目管理
        myValue = string.Empty;
        foreach (ListItem li in chkColumn.Items)
        {
            if (li.Selected)
            {
                myValue += li.Value + "1,";
            }
            else
            {
                myValue += li.Value + "0,";
            }

        }
        if (myValue != "")
        {
            myValue = myValue.Substring(0, myValue.Length - 1);
        }
        string strColumn = myValue;
        //会员管理
        myValue = string.Empty;
        foreach (ListItem li in chkUser.Items)
        {
            if (li.Selected)
            {
                myValue += li.Value + "1,";
            }
            else
            {
                myValue += li.Value + "0,";
            }

        }
        if (myValue != "")
        {
            myValue = myValue.Substring(0, myValue.Length - 1);
        }
        string strUser = myValue;
        //模板风格
        myValue = string.Empty;
        foreach (ListItem li in chkTemplate.Items)
        {
            if (li.Selected)
            {
                myValue += li.Value + "1,";
            }
            else
            {
                myValue += li.Value + "0,";
            }

        }
        if (myValue != "")
        {
            myValue = myValue.Substring(0, myValue.Length - 1);
        }
        string strTemplate = myValue;
        //系统设置
        myValue = string.Empty;
        foreach (ListItem li in chkSystem.Items)
        {
            if (li.Selected)
            {
                myValue += li.Value + "1,";
            }
            else
            {
                myValue += li.Value + "0,";
            }

        }
        if (myValue != "")
        {
            myValue = myValue.Substring(0, myValue.Length - 1);
        }
        string strSystem = myValue;
        myValue = string.Empty;

        TRole TR = new TRole();
        if (txtRoleName.Text.Trim().Equals(string.Empty))
        {
            Restr += "网站角色，";
        }
        TR.RoleName = txtRoleName.Text;
        TR.Basic = strBasic;
        TR.Column = strColumn;
        TR.User = strUser;
        TR.Template = strTemplate;
        TR.System = strSystem;
        TR.Describe = txtDescribe.Text.Trim();
        IRole Role = new RRole();
        if (!Restr.Trim().Equals(string.Empty))
            Restr = Restr.Substring(0, Restr.Length - 1);
        try
        {
            if (Restr.Trim().Equals(string.Empty))
            {
                if (Role.Insert(TR) == 1)
                    ShowMessage("网站角色添加成功！", "Rights/RoleList.aspx");
            }
            else
            {
                lblMessage.Visible = true;
                lblMessage.Text = Restr + "填写有误！";
            }
        }
        catch (Exception ex)
        {
            ShowMessage("网站角色添加失败！", "Rights/RoleList.aspx");
        }
    }
}
