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 System.Data.SqlClient;

public partial class SysManage_news : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int sm=0;
        //int menuj = 0;
        string sqltt1= "";
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
            //Response.Write("<script>window.open('main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录','_top');</" + "script>");
        }

        if (Request.QueryString["type"] == null)
        {

            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd;
            if (Request.QueryString["id"] != null)
            {
                smd = new SqlCommand("select gnid from UserAdmin where id=" + Session["WtoRightid"], conn);
                sqltt1 = Convert.ToString(smd.ExecuteScalar());
                smd = new SqlCommand("select smallid from DataMasterAdditionalControl where bigid=" + Request.QueryString["id"].Trim() + " and zt='y' order by sort", conn);
            }
            else
            {

                if (Session["WtoRightLX"].ToString() == "2")
                {
                    smd = new SqlCommand("select top 1 bigid  from DataMasterAdditionalControl order by sort", conn);
                    sm = Convert.ToInt32(smd.ExecuteScalar());
                }
                else
                {
                    smd = new SqlCommand("select gnid from UserAdmin where id=" + Session["WtoRightid"], conn);
                    sqltt1 = Convert.ToString(smd.ExecuteScalar());
                    if (sqltt1 != "")
                    {
                        string[] sqltt2 = sqltt1.Split('$');
                        string[] sqltt3;
                        sqltt3 = sqltt2[0].Split('|');
                        sm = int.Parse(sqltt3[2]);
                    }
                }
                smd = new SqlCommand("select smallid from DataMasterAdditionalControl where bigid=" + sm + " and zt='y' order by sort", conn);
            }

            SqlDataReader sdr = smd.ExecuteReader();
            string strall = "";
            string db = "";
            while (sdr.Read())
            {
                strall += Convert.ToString(sdr.GetInt32(0)) + "$";
            }
            sdr.Close();
            string[] str = strall.Split('$');
            Panel p1;
            HyperLink hy1;
            Table tb;
            TableRow tr;
            TableCell tc;
            SqlCommand smdd;
            SqlDataReader sdrr;
            for (int i = 0; i < str.Length - 1; i++)
            {
                db = str[i] + "$";
                strall = strall.Replace(db, "");
                strall += db;
            }
            string[] dbb = strall.Split('$');
            string[] tt1;
            string[] tt2;
            string[] tt3;
            int gg1 = 0;
            string where1 = "";
            for (int j = 0; j < dbb.Length - 1; j++)
            {
                p1 = new Panel();
                p1.CssClass = "left_menu";
                tb = new Table();
                tb.BorderWidth = 0;
                tb.CellPadding = 0;
                tb.CellSpacing = 0;
                tr = new TableRow();
                tc = new TableCell();
                if (Session["WtoRightLX"].ToString() == "2")
                {
                    smdd = new SqlCommand("select smallname from DataMasterAdditionalControl where smallid=" + dbb[j] + " and zt='y'", conn);
                    hy1 = new HyperLink();
                    hy1.Text = Convert.ToString(smdd.ExecuteScalar());
                    hy1.NavigateUrl = "javascript:;";
                    hy1.Attributes.Add("onClick", "javascript:show_lm(this)");
                    hy1.ID = "lb" + (j + 1);
                    hy1.CssClass = "left_on";
                    tc.Controls.Add(hy1);
                    tr.Controls.Add(tc);
                    tb.Controls.Add(tr);
                    p1.Controls.Add(tb);
                    left.Controls.Add(p1);
                    p1 = new Panel();
                    p1.ID = "lm" + (j + 1);
                    p1.CssClass = "lm";
                    if (j != 0)
                    {
                        p1.Style.Add("display", "none");
                    }
                    smdd = new SqlCommand("select tagname,href from DataMasterAdditionalControl where zt='y' and smallid=" + dbb[j] + " order by sort", conn);
                    sdrr = smdd.ExecuteReader();
                    while (sdrr.Read())
                    {
                        hy1 = new HyperLink();
                        hy1.CssClass = "slb";
                        hy1.Text = sdrr.GetString(0);
                        hy1.NavigateUrl = sdrr.GetString(1);
                        hy1.Target = "main";
                        p1.Controls.Add(hy1);

                    }

                    sdrr.Close();

                    left.Controls.Add(p1);
                }
                else
                {
                    tt1 = sqltt1.Split('$');

                    for (int i = 0; i < tt1.Length - 1; i++)
                    {
                        tt2 = tt1[i].Split('|');
                        if (tt2[1].Trim() == dbb[j].Trim())
                        {
                            where1 = " and id=" + tt2[0];
                            smdd = new SqlCommand("select smallname from DataMasterAdditionalControl where smallid=" + dbb[j] + " and zt='y' " + where1, conn);
                            hy1 = new HyperLink();
                            hy1.Text = Convert.ToString(smdd.ExecuteScalar());
                            hy1.NavigateUrl = "javascript:;";
                            hy1.Attributes.Add("onClick", "javascript:show_lm(this)");
                            hy1.ID = "lb" + (j + 1);
                            hy1.CssClass = "left_on";
                            tc.Controls.Add(hy1);
                            tr.Controls.Add(tc);
                            tb.Controls.Add(tr);
                            p1.Controls.Add(tb);
                            left.Controls.Add(p1);
                            p1 = new Panel();
                            p1.ID = "lm" + (j + 1);
                            p1.CssClass = "lm";
                            if (j != 0)
                            {
                                p1.Style.Add("display", "none");
                            }

                            smdd = new SqlCommand("select tagname,href,id from DataMasterAdditionalControl where zt='y' and smallid=" + dbb[j] + "  order by sort", conn);
                            sdrr = smdd.ExecuteReader();
                            while (sdrr.Read())
                            {
                                for (int gg = 0; gg < tt1.Length - 1; gg++)
                                {
                                    tt3 = tt1[gg].Split('|');
                                    if (tt3[0].Trim() == sdrr["id"].ToString())
                                    {
                                        hy1 = new HyperLink();
                                        hy1.CssClass = "slb";
                                        hy1.Text = sdrr.GetString(0);
                                        hy1.NavigateUrl = sdrr.GetString(1);
                                        hy1.Target = "main";
                                        p1.Controls.Add(hy1);
                                    }
                                }
                            }
                            sdrr.Close();
                            left.Controls.Add(p1);
                            break;
                        }

                    }
                }

                //menuj = j;
            }
            conn.Close();
        }
        else
        {

            #region 版权信息菜单(当"type＝系统支持"时就显示此菜单)
            Panel p1;
            HyperLink hy1;
            Table tb;
            TableRow tr;
            TableCell tc;
            tb = new Table();
            tb.BorderWidth = 0;
            tb.CellPadding = 0;
            tb.CellSpacing = 0;
            tr = new TableRow();
            tc = new TableCell();            
            p1 = new Panel();
            p1.CssClass = "left_menu";

            #region 大菜单
            hy1 = new HyperLink();
            hy1.Text = "系统支持";
            hy1.NavigateUrl = "javascript:;";
            hy1.Attributes.Add("onClick", "javascript:show_lm(this)");
            hy1.ID = "lb1";
            hy1.CssClass = "left_on";
            tc.Controls.Add(hy1);
            tr.Controls.Add(tc);
            tb.Controls.Add(tr);
            p1.Controls.Add(tb);
            left.Controls.Add(p1);
            #endregion

            #region 小菜单

            #region 小菜单数据
            string[] title = new string[5];
            string[] url = new string[5];
            title[0] = "最新生意经";    url[0] = "http://www.31key.com/wincart/";
            title[1] = "万年历";        url[1] = "other/year.htm";
            title[2] = "我的提问";      url[2] = "http://www.31key.com/member/ask.aspx";
            title[3] = "系统动态"; url[3] = "http://www.31key.com/wincart/article.aspx?newsid=723";
            title[4] = "关于系统"; url[4] = "http://www.31key.com/wincart/Article.aspx?newsid=491";
            #endregion

            p1 = new Panel();
            p1.CssClass = "lm";

            for (int i = 0; i < title.Length; i++)
            {
                hy1 = new HyperLink();
                hy1.CssClass = "slb";
                hy1.Text = title[i];
                hy1.NavigateUrl = url[i];
                hy1.Target = "main";
                p1.Controls.Add(hy1);
            }
            #endregion

            left.Controls.Add(p1);
            #endregion
        }
    }

    private void Page_Unload(object sender, EventArgs e)
    {
        
    }
}
