Basf_EProject/EProject/FineUIPro.Web/index.aspx.cs

369 lines
11 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Configuration;
namespace FineUIPro.Web
{
public partial class index : PageBase
{
#region EnableFStatePersistence
/// <summary>
/// 首页没有回发操作所以无需在服务器端保存FState
/// </summary>
protected override bool SaveFStateToServer
{
get
{
return false;
}
}
#endregion
#region Page_Init
private string _menuType = "tree";
private string _searchText = "";
// 主选项卡标签页
private string _mainTabs = "multi";
// 示例数
private int _examplesCount = 0;
#region Page_Init
protected void Page_Init(object sender, EventArgs e)
{
////////////////////////////////////////////////////////////////
string themeStr = Request.QueryString["theme"];
string menuStr = Request.QueryString["menu"];
string https = ConfigurationManager.AppSettings["Https"];
if (!String.IsNullOrEmpty(themeStr) || !String.IsNullOrEmpty(menuStr))
{
if (!String.IsNullOrEmpty(themeStr))
{
if (themeStr == "bootstrap1")
{
themeStr = "bootstrap_pure";
}
HttpCookie cookie = new HttpCookie("Theme", themeStr);
cookie.Expires = DateTime.Now.AddYears(1);
if (https == "true")
{
cookie.Secure = true;
}
Response.Cookies.Add(cookie);
}
if (!String.IsNullOrEmpty(menuStr))
{
HttpCookie cookie = new HttpCookie("MenuStyle", menuStr);
cookie.Expires = DateTime.Now.AddYears(1);
if (https == "true")
{
cookie.Secure = true;
}
Response.Cookies.Add(cookie);
}
PageContext.Redirect("~/default.aspx");
return;
}
////////////////////////////////////////////////////////////////
// 从Cookie中读取 - 左侧菜单类型
HttpCookie menuCookie = Request.Cookies["MenuStyle"];
if (menuCookie != null)
{
_menuType = menuCookie.Value;
}
// 新版首页不再支持手风琴+树控件的情况,这样会增加复杂度
if (_menuType == "accordion")
{
_menuType = "tree";
}
// 从Cookie中读取 - 搜索文本
HttpCookie searchText = Request.Cookies["SearchText"];
if (searchText != null)
{
_searchText = HttpUtility.UrlDecode(searchText.Value);
}
// 从Cookie中读取 - 是否单标签页
HttpCookie mainTabs = Request.Cookies["MainTabs"];
if (mainTabs != null)
{
_mainTabs = mainTabs.Value;
}
InitTreeMenu();
}
#endregion
#region InitAccordionMenu
private Accordion InitAccordionMenu()
{
Accordion accordionMenu = new Accordion();
accordionMenu.ID = "accordionMenu";
accordionMenu.EnableFill = false;
accordionMenu.ShowBorder = false;
accordionMenu.ShowHeader = false;
leftPanel.Items.Add(accordionMenu);
var dt = GetNewMenu("0");
foreach (var dr in dt)
{
AccordionPane accordionPane = new AccordionPane();
accordionPane.Title = dr.MenuName;
//accordionPane.Layout = Layout.Fit;
accordionPane.ShowBorder = false;
accordionPane.BodyPadding = "2px 0 0 0";
accordionMenu.Items.Add(accordionPane);
Tree innerTree = new Tree();
innerTree.ShowBorder = false;
innerTree.ShowHeader = false;
innerTree.EnableIcons = true;
innerTree.AutoScroll = true;
innerTree.EnableSingleClickExpand = true;
accordionPane.Items.Add(innerTree);
BoundTree(innerTree.Nodes, dr.MenuId);
}
return accordionMenu;
}
#endregion
/// <summary>
/// 加载树
/// </summary>
/// <param name="nodes"></param>
/// <param name="menuId"></param>
private void BoundTree(TreeNodeCollection nodes, string menuId)
{
var dt = GetNewMenu(menuId);
if (menuId == "0")
{
if (dt.Count() > 0)
{
TreeNode tn = null;
foreach (var dr in dt)
{
tn = new TreeNode();
//tn.Text = dr.MenuName;
tn.Text = dr.MenuEnName;
tn.NodeID = dr.MenuId;
if (this.GetLanguage == "en-US")
{
tn.Text = dr.MenuEnName;
}
if (dr.SuperMenu != "0" && !string.IsNullOrEmpty(dr.Url))
{
tn.NavigateUrl = "~/" + dr.Url;
}
nodes.Add(tn);
BoundTree(tn.Nodes, dr.MenuId);
}
}
}
else
{
if (dt.Count() > 0)
{
TreeNode tn = null;
foreach (var dr in dt)
{
tn = new TreeNode();
//tn.Text = dr.MenuName;
tn.Text = dr.MenuEnName;
tn.NodeID = dr.MenuId;
if (this.GetLanguage == "en-US")
{
tn.Text = dr.MenuEnName;
}
if (dr.SuperMenu != "0" && !string.IsNullOrEmpty(dr.Url))
{
if (dr.Url.Contains("default.aspx"))
{
//tn.NavigateUrl = ResolveUrl("~/" + dr.Url);
}
else
{
tn.NavigateUrl = "~/" + dr.Url;
}
}
nodes.Add(tn);
BoundTree(tn.Nodes, dr.MenuId);
}
}
}
}
#region InitTreeMenu
private Tree InitTreeMenu()
{
var dt = GetNewMenu("0");
BoundTree(treeMenu.Nodes, "0");
return treeMenu;
}
/// <summary>
/// 得到菜单方法
/// </summary>
/// <param name="parentId"></param>
/// <returns></returns>
private List<Model.Sys_Menu> GetNewMenu(string parentId)
{
List<Model.Sys_Menu> menu = new List<Model.Sys_Menu>();
var menuList = BLL.CommonService.GetMenuByRoleRower(this.CurrUser.UserId);
if (menuList.Count() > 0)
{
menu = menuList.Where(x => x.SuperMenu == parentId).ToList();
}
return menu;
}
#endregion
#region
/// <summary>
/// 用户ID
/// </summary>
/// <param name="userId"></param>
//private void GetUserLoginSystem(string userId)
//{
// var user = BLL.Sys_UserService.GetUsersByUserId(userId);
//this.btnGDAZ.Visible = false;
//this.btnYLRQ.Visible = false;
//if (user != null && user.AllowLoginSystem!=null)
//{
// string[] systems = user.AllowLoginSystem.Split('|');
// foreach (string sys in systems)
// {
//if (sys == BLL.Const.System_2)
//{
// btnGDAZ.Visible = true;
//}
//if (sys == BLL.Const.System_4)
//{
// btnYLRQ.Visible = true;
//}
// }
// }
//}
#endregion
#endregion
#region Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitMenuStyleButton();
InitMenuDisplayModeButton();
InitMenuRegionButton();
hfExamplesCount.Text = _examplesCount.ToString();
// 为CSS样式文件添加版本号防止版本更新时客户端缓存
linkIndexCSS.Href = "~/res/css/index.css?v" + GlobalConfig.ProductVersion;
linkMobileViewCss.Href = "~/res/css/mobileview.css?v" + GlobalConfig.ProductVersion;
litScriptIndex.Text = String.Format("<script src=\"{0}\"></script>", ResolveClientUrl("~/res/js/index.js?v" + GlobalConfig.ProductVersion));
// 单标签页
//if (_mainTabs == "single")
//{
//mainTabStrip.ShowTabHeader = false;
//}
btnUser.Text = this.CurrUser.UserName;
}
}
private void InitMenuStyleButton()
{
string menuStyle = "tree";
HttpCookie menuStyleCookie = Request.Cookies["MenuStyle"];
if (menuStyleCookie != null)
{
menuStyle = menuStyleCookie.Value;
}
SetSelectedMenuItem(MenuStyle, menuStyle);
}
private void InitMenuDisplayModeButton()
{
string displayMode = "normal";
HttpCookie displayModeCookie = Request.Cookies["DisplayMode"];
if (displayModeCookie != null)
{
displayMode = displayModeCookie.Value;
}
SetSelectedMenuItem(MenuDisplayMode, displayMode);
}
private void InitMenuRegionButton()
{
string mainTabs = "multi";
HttpCookie mainTabsCookie = Request.Cookies["MainTabs"];
if (mainTabsCookie != null)
{
mainTabs = mainTabsCookie.Value;
}
SetSelectedMenuItem(MenuMainTabs, mainTabs);
}
private void SetSelectedMenuItem(MenuButton menuButton, string selectedDataTag)
{
foreach (MenuItem item in menuButton.Menu.Items)
{
MenuCheckBox checkBox = (item as MenuCheckBox);
if (checkBox != null)
{
checkBox.Checked = checkBox.AttributeDataTag == selectedDataTag;
}
}
}
#endregion
}
}