⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabs.ascx.cs

📁 三层架构的.net源码三层架构的.net源码
💻 CS
字号:
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyStarterKit.Portal.Web
{
	/// <summary>
	///	Tabs 的摘要说明。
	/// </summary>
	public class Tabs : PortalModuleControl
	{
		protected System.Web.UI.WebControls.LinkButton addBtn;
		protected System.Web.UI.WebControls.ListBox tabList;
		protected System.Web.UI.WebControls.ImageButton upBtn;
		protected System.Web.UI.WebControls.ImageButton downBtn;
		protected System.Web.UI.WebControls.ImageButton editBtn;
		protected System.Web.UI.WebControls.ImageButton deleteBtn;

		//标签的ArrayList
		protected ArrayList portalTabs;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Verify that the current user has access to access this page
			// 用户角色为Admins的才能访问该管理模块,负责重定向到EditAccessDenied.aspx
			if (PortalSecurity.IsInRoles("Admins") == false) 
			{
				Response.Redirect("~/Admin/EditAccessDenied.aspx");
			}

			// Obtain PortalSettings from Current Context
			// 获取门户站点设置的信息类
			PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
        
			portalTabs = new ArrayList();
			foreach (TabStripDetails tab in portalSettings.DesktopTabs) 
			{
        
				TabItem t = new TabItem();
				t.TabName = tab.TabName;
				t.TabId = tab.TabId;
				t.TabOrder = tab.TabOrder;
				portalTabs.Add(t);
			}
        
			// Give the admin tab a big sort order number, to ensure it's always at the end
			// 让管理标签总是最后一个
			TabItem adminTab = (TabItem) portalTabs[portalTabs.Count-1];
			adminTab.TabOrder=99999;
        
			// 页面初次载入时,绑定tabList
			if (!Page.IsPostBack) 
			{
				tabList.DataBind();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.addBtn.Click += new System.EventHandler(this.addBtn_Click);
			this.upBtn.Click += new System.Web.UI.ImageClickEventHandler(this.upBtn_Click);
			this.downBtn.Click += new System.Web.UI.ImageClickEventHandler(this.downBtn_Click);
			this.editBtn.Click += new System.Web.UI.ImageClickEventHandler(this.editBtn_Click);
			this.deleteBtn.Click += new System.Web.UI.ImageClickEventHandler(this.deleteBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		//添加新标签
		private void addBtn_Click(object sender, System.EventArgs e)
		{
			// 获取门户站点设置的信息类
			PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];

			//构造一个新的标签类,赋初值并添加到portalTabs变量中
			TabItem t = new TabItem();
			t.TabName = "新标签";
			t.TabId = -1;
			t.TabOrder = 999;
			portalTabs.Add(t);

			// 将新签信息添加到配置文件数据集中,并取回添加行的Id
			Configuration config = new Configuration();
			t.TabId = config.AddTab(portalSettings.PortalId, t.TabName, t.TabOrder);
        
			// reload the _portalSettings from the database
			// 重新构造站点信息对象
			HttpContext.Current.Items["PortalSettings"] = new PortalSettings(portalSettings.PortalId, t.TabId);

			// Reset the order numbers for the tabs within the list  
			OrderTabs();
        
			// Redirect to edit page
			// 重定向到编辑标签页
			Response.Redirect("~/Admin/TabLayout.aspx?tabid=" + t.TabId);
		}

		//上移下移操作
		private void UpDown(String cmd) 
		{
			if (tabList.SelectedIndex != -1) 
			{
				int delta;
            
				// Determine the delta to apply in the order number for the module
				// within the list.  +3 moves down one item; -3 moves up one item

				//因为标签排序号是1,3,5,7,9方式排列的,将一个标签的上移或下移一位,就把标签序号加减3,正好为一偶数就在前后一位的前面或后面。(如:将第7位上移,那么新的顺序是1,3,4,5,9)
            
				if (cmd == "down") 
				{
            
					delta = 3;
				}
				else 
				{
            
					delta = -3;
				}

				TabItem t;
				t = (TabItem) portalTabs[tabList.SelectedIndex];
				t.TabOrder += delta; 
            
				// Reset the order numbers for the tabs within the portal  
				OrderTabs();
            
				//重定向到当前请求的原始Url
				Response.Redirect(Request.RawUrl);        
			}
		}

		//上移标签位置
		private void upBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			String cmd = ((ImageButton)sender).CommandName;
			UpDown(cmd);
		}

		//下移标签位置
		private void downBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			String cmd = ((ImageButton)sender).CommandName;
			UpDown(cmd);
		}

		//编辑选中标签
		private void editBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			// Redirect to edit page of currently selected tab
			if (tabList.SelectedIndex != -1) 
			{

				// Redirect to module settings page
				TabItem t = (TabItem) portalTabs[tabList.SelectedIndex];
            
				Response.Redirect("~/Admin/TabLayout.aspx?tabid=" + t.TabId);
			}
		}

		//删除选中标签
		private void deleteBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (tabList.SelectedIndex != -1) 
			{

				// must delete from database too
				TabItem t = (TabItem) portalTabs[tabList.SelectedIndex];
				Configuration config = new Configuration();
				config.DeleteTab(t.TabId);
                        
				// remove item from list
				portalTabs.RemoveAt(tabList.SelectedIndex);

				// reorder list
				OrderTabs();
            
				//重定向到当前请求的原始Url
				Response.Redirect(Request.RawUrl);        
			}		
		}

		/// <summary>
		/// 将portalTabs中的标签排序
		/// </summary>
		private void OrderTabs () 
		{
    
			int i = 1;
        
			// 使用指定的比较器对部分 System.Collections.ArrayList 中的元素进行排序。
			// portalTabs中的对象是TabItem,TabItem对象继承了IComparable接口,实现了以TabOrder的CompareTo
			portalTabs.Sort();
        
			// renumber the order and save to database
			// 将排序后的信息存入XML
			foreach (TabItem t in portalTabs) 
			{
        
				// number the items 1, 3, 5, etc. to provide an empty order number when moving items up and down in the list.
				// 将标签的排序号按1, 3, 5,递增的顺序排列
				t.TabOrder = i;
				i += 2;
            
				// 将新的排序号写入用户配置文件
				Configuration config = new Configuration();
				config.UpdateTabOrder(t.TabId, t.TabOrder);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -