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;

public partial class left : System.Web.UI.Page
{
    public  string style = string.Empty;
    public string strsql = string.Empty;
    public string searchstr = string.Empty;
    public string roleid = string.Empty;
    public string Purview = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        DataSet dsname = DbHelperSQL.Query("select realname,roleid,Purview from etw_admin where etwadminname='" + GetCookie["username"] + "'");
        if (dsname.Tables[0].Rows.Count > 0)
        {
            roleid = dsname.Tables[0].Rows[0]["roleid"].ToString();
            Purview = dsname.Tables[0].Rows[0]["Purview"].ToString();
            if (roleid != "1")
            {
                strsql = "select * from etw_menu where (parentid=0 and id in(select parentid from etw_menu where id in(" + Purview + "))) or (parentid=0 and id in(" + Purview + "))";
                style = "style=\"display:none;\"";
            }
            else
            {
                strsql = "select * from etw_menu where parentid=0 order by orderby ";
            }
            if (!IsPostBack)
            {
                bindData();
            }
        }
    }
    protected void bindData()
    {
        DataSet ds = DbHelperSQL.Query(strsql);
        DataList1.DataSource = ds.Tables[0].DefaultView;
        DataList1.DataBind();
    }
    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem)
        {
            Repeater rpColumnNews = (Repeater)e.Item.FindControl("Repeater1");
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            string strClassID = Convert.ToString(rowv["id"]);
            if (roleid != "1")
            {
                searchstr = "select * from etw_menu where parentid=" + strClassID + " and id in(" + Purview + ") order by orderby";
            }
            else
            {
                searchstr = "select * from etw_menu where parentid=" + strClassID + " order by orderby";
            }
            DataSet ds1 = DbHelperSQL.Query(searchstr);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                rpColumnNews.DataSource = ds1.Tables[0].DefaultView;
                rpColumnNews.DataBind();
            }
        }
    }
    public string Cutlink(string str)
    {
        string mun = string.Empty;
        DataSet ds = DbHelperSQL.Query("select * from etw_menu where id="+str+"");
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows[0]["sqltext"].ToString() != "")
            {
                mun = "( " + DbHelperSQL.GetSingle(ds.Tables[0].Rows[0]["sqltext"].ToString()).ToString() + " )";
            }
            else
            {
                mun = "";
            }
            if (ds.Tables[0].Rows[0]["Url"].ToString() == "")
            {
                str = ds.Tables[0].Rows[0]["menuname"].ToString();
            }
            else
            {
                str = "<a href=\"" + ds.Tables[0].Rows[0]["Url"].ToString() + "\" target=\"mainFrame\">" + ds.Tables[0].Rows[0]["menuname"].ToString() + "" + mun + "</a>";
            }
        }
        return str;
    }
}
