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.Text;

public partial class index :PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this.Page.IsPostBack)
        {
            BindPage();
            Session.Timeout = 600;//一个小时
        }
    }

    #region 绑定页面
    /// <summary>
    /// 绑定页面
    /// </summary>
    public void BindPage()
    {
        DataSet ds = SqlHelper.GetDataSet("SELECT WorkId,LoginName,PersonnelName,MainModuleIdString,SubModuleIdString FROM dbo.tabP_Personnel WHERE Pid=" + PersonalId + "", "constring");
        if(ds.Tables[0].Rows.Count>0)
        {
            #region 绑定最上方的账号、职位名、部门名
            spanUserName.InnerHtml = ConvertHelper.GetString(ds.Tables[0].Rows[0]["LoginName"]);//账号
            DataSet dsWork = SqlHelper.GetDataSet("SELECT WorkName,DepartmentId FROM dbo.tabP_Work WHERE WorkId="+ConvertHelper.GetInteger(ds.Tables[0].Rows[0]["WorkId"])+"", "constring");
            if(dsWork.Tables[0].Rows.Count>0)
            {
                spanWork.InnerHtml=ConvertHelper.GetString(dsWork.Tables[0].Rows[0]["WorkName"]);//职位名
                DataSet dsDepartment = SqlHelper.GetDataSet("SELECT DepartmentName FROM dbo.tabP_Department WHERE DepartmentId=" + ConvertHelper.GetInteger(dsWork.Tables[0].Rows[0]["DepartmentId"]) + "", "constring");
                if(dsDepartment.Tables[0].Rows.Count>0)
                {
                    spanDepartment.InnerHtml = ConvertHelper.GetString(dsDepartment.Tables[0].Rows[0]["DepartmentName"]);//部门名
                }
            }
            #endregion
            #region 加载菜单
            //如果模块和子模块都不为空时执行加载菜单
            if (!(string.IsNullOrEmpty(ConvertHelper.GetString(ds.Tables[0].Rows[0]["MainModuleIdString"])) || string.IsNullOrEmpty(ConvertHelper.GetString(ds.Tables[0].Rows[0]["SubModuleIdString"]))))
            {
                string[] mainModuleId = ConvertHelper.GetString(ds.Tables[0].Rows[0]["MainModuleIdString"]).Split(',');//数据库中存的模块id数组
                string[] subModuleId = ConvertHelper.GetString(ds.Tables[0].Rows[0]["SubModuleIdString"]).Split(',');//数据库中存的子模块id数组
                StringBuilder stbMenu = new StringBuilder();//菜单
                for (int i = 0; i < mainModuleId.Length; i++)
                {
                    DataSet dsMainModuleName = SqlHelper.GetDataSet("SELECT ModuleName FROM tabF_Module WHERE ModuleId=" + mainModuleId[i] + "", "constring");
                    if (dsMainModuleName.Tables[0].Rows.Count > 0)
                    {
                        stbMenu.Append("<ul class=\"tabpage2\">");
                        stbMenu.Append("<li id=\"left_tab" + ConvertHelper.GetString(i + 1) + "\" title=\"操作菜单\" onclick=\"" + "javascript" + ":border_left('left_tab" + ConvertHelper.GetString(i + 1) + "','left_menu_cnt" + ConvertHelper.GetString(i + 1) + "');\">");
                        stbMenu.Append("<span>" + ConvertHelper.GetString(dsMainModuleName.Tables[0].Rows[0]["ModuleName"]) + "</span>");
                        stbMenu.Append("</li>");
                        stbMenu.Append("</ul>");
                        stbMenu.Append("<div id=\"left_menu_cnt" + ConvertHelper.GetString(i + 1) + "\" class=\"left_menu_cnt\">");
                        stbMenu.Append("<ul id=\"dleft_tab" + ConvertHelper.GetString(i + 1) + "\">");
                        for (int k = 0; k < subModuleId.Length; k++)//子模块
                        {
                            DataSet dsSubModule = SqlHelper.GetDataSet("SELECT ModuleId,FunctionName,FunctionAddress FROM dbo.tabF_Function WHERE FunctionId=" + subModuleId[k] + " AND ModuleId=" + mainModuleId[i] + " AND State=1", "constring");
                            if (dsSubModule.Tables[0].Rows.Count > 0)//子模块
                            {
                                stbMenu.Append("<li>");
                                stbMenu.Append("<a title=\"" + ConvertHelper.GetString(dsSubModule.Tables[0].Rows[0]["FunctionName"]) + "\" href=\"" + ConvertHelper.GetString(dsSubModule.Tables[0].Rows[0]["FunctionAddress"]) + "\" target=\"content3\" onclick=\"show_title('" + ConvertHelper.GetString(dsSubModule.Tables[0].Rows[0]["FunctionName"]) + "')\">");
                                stbMenu.Append("<span>" + ConvertHelper.GetString(dsSubModule.Tables[0].Rows[0]["FunctionName"]) + "</span>");
                                stbMenu.Append("</a>");
                                stbMenu.Append("</li>");
                            }
                        }
                        stbMenu.Append("</ul>");
                        stbMenu.Append("</div>");
                        stbMenu.Append("<div class=\"clear\">");
                        stbMenu.Append("</div>");
                    }
                }
                menu.InnerHtml = ConvertHelper.GetString(stbMenu);
            }
            else
            {
                StringBuilder stbMenu = new StringBuilder();//菜单
                stbMenu.Append("<ul class=\"tabpage2\">");
                stbMenu.Append("<li id=\"left_tab1\" title=\"操作菜单\" onclick=\"javascript"+":border_left('left_tab1','left_menu_cnt1');\">");
                stbMenu.Append("<span>公告</span></li>");
                stbMenu.Append("</ul>");
                stbMenu.Append("<div id=\"left_menu_cnt1\" class=\"left_menu_cnt\">");
                stbMenu.Append("<ul id=\"dleft_tab1\">");
                stbMenu.Append("<li id=\"liNewsFirstPage\"  ><a title=\"公告栏\" href=\"../News/FirstPage.aspx\" target=\"content3\" onclick=\"show_title('公告栏')\">");
                stbMenu.Append("<span>公告栏</span></a></li>");
                stbMenu.Append("</ul>");
                stbMenu.Append("</div>");
                stbMenu.Append("<div class=\"clear\">");
                stbMenu.Append("</div>");
                menu.InnerHtml = ConvertHelper.GetString(stbMenu);
            }
            #endregion
        }
    }
    #endregion
    protected void lbtnExit_Click(object sender, EventArgs e)//退出按钮
    {
        Response.Redirect("~/Exit/Exit.aspx");
    }
}
