wtptooltips.cs

来自「C#编写的在线用户统计、在线编辑器、验证码图片」· CS 代码 · 共 175 行

CS
175
字号
/*
 * WtpToolTips.cs @Microsoft Visual Studio 2008 <.NET Framework 2.0 (or Higher)>
 * AfritXia
 * 2008/3/17
 *
 * Copyright(c) http://www.AfritXia.NET/
 *
 */

using System;
using System.Collections.Generic;
using System.Xml;
using System.Web;

namespace Net.AfritXia.Web.UI
{
	/// <summary>
	/// 工具提示信息类
	/// </summary>
	internal class WtpToolTips
	{
		// ToolTips 静态对象
		private static WtpToolTips g_instance = null;

		// 工具提示字典 中文
		private Dictionary<string, string> m_toolTipDict_ch = new Dictionary<string, string>();
		// 工具提示字典 英文
        private Dictionary<string, string> m_toolTipDict_en = new Dictionary<string, string>();

		#region 类构造器
		/// <summary>
		/// 类默认构造器
		/// </summary>
		private WtpToolTips()
		{
		}
		#endregion

		/// <summary>
		/// 获取工具提示对象实例,该属性是线程安全的
		/// </summary>
		public static WtpToolTips Instance
		{
			get
			{
				if (g_instance != null)
					return g_instance;

				lock (typeof(WtpToolTips))
				{
					if (g_instance == null)
					{
						WtpToolTips theInstance = new WtpToolTips();

						// 读取 XML 资源内容
						theInstance.LoadXmlResource("ch");
						theInstance.LoadXmlResource("en");

						g_instance = theInstance;
					}
				}

				return g_instance;
			}
		}

		/// <summary>
		/// 读取 XML 资源内容到工具提示字典对象
		/// </summary>
		/// <param name="language"></param>
		private void LoadXmlResource(string language)
		{
			XmlDocument xmlDoc = new XmlDocument();
			// 工具提示字典
			Dictionary<string, string> toolTipDict;

			if (language == "ch")
			{
				// 获取中文工具提示
				xmlDoc.LoadXml(MyRes.WtpToolTips_ch);
				// 指向中文字典
				toolTipDict = this.m_toolTipDict_ch;
			}
			else
			{
				// 获取英文工具提示
				xmlDoc.LoadXml(MyRes.WtpToolTips_en);
				// 指向英文字典
				toolTipDict = this.m_toolTipDict_en;
			}

			// <toolBar></toolBar>
			XmlNode root = xmlDoc.DocumentElement;

			foreach (XmlNode node in root.ChildNodes)
			{
                // <commandName></commandName>
				XmlNode cmdIDNode = node.SelectSingleNode("commandName");
				// <tipText></tipText>
				XmlNode tipTextNode = node.SelectSingleNode("tipText");

				if (cmdIDNode == null)
					continue;

				// 添加工具提示文本到字典
				toolTipDict.Add(cmdIDNode.InnerXml, tipTextNode.InnerXml);
			}
		}

		/// <summary>
		/// 获取工具提示字符串
		/// </summary>
        /// <param name="commandName">命令名称</param>
		/// <returns>工具提示字符串</returns>
		public string GetString(string commandName)
		{
			if (commandName == null)
				return null;

			// 获取工具提示字典
			Dictionary<string, string> toolTipDict = this.GetToolTipDictionary();

			if (!toolTipDict.ContainsKey(commandName))
				return null;

			return toolTipDict[commandName];
		}

		/// <summary>
		/// 获取命令关键字枚举
		/// </summary>
		/// <returns></returns>
		public IEnumerator<string> GetCommandIDEnumerator()
		{
			// 获取工具提示字典
			Dictionary<string, string> toolTipDict = this.GetToolTipDictionary();

			return toolTipDict.Keys.GetEnumerator();
		}

		/// <summary>
		/// 获取工具提示文本枚举
		/// </summary>
		/// <returns></returns>
		public IEnumerator<string> GetTipTextEnumerator()
		{
			// 获取工具提示字典
			Dictionary<string, string> toolTipDict = this.GetToolTipDictionary();

			return toolTipDict.Values.GetEnumerator();
		}

		/// <summary>
		/// 获取工具提示字典
		/// </summary>
		/// <returns></returns>
		private Dictionary<string, string> GetToolTipDictionary()
		{
			Dictionary<string, string> toolTipDict;

			if (HttpContext.Current.Request.UserLanguages[0] == "zh-cn")
			{
				// 指向中文字典
				toolTipDict = this.m_toolTipDict_ch;
			}
			else
			{
				// 指向英文字典
				toolTipDict = this.m_toolTipDict_en;
			}

			return toolTipDict;
		}
	}
}

⌨️ 快捷键说明

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