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

📄 helpers.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.Drawing;

namespace daReport
{
	/// <summary>
	/// A class of static helper functions
	/// </summary>
	public class Helpers
	{
		/// <summary>
		/// Parses an XmlNode for information and returns a System.Drawing.Font object
		/// </summary>
		/// <param name="FontNode">XmlNode to parse for information</param>
		/// <returns>System.Drawing.Font</returns>
		public static System.Drawing.Font ResolveFont(System.Xml.XmlNode FontNode)
		{
			try
			{
				System.Drawing.Font ReturnFont;
				string fntName = FontNode.Attributes["family"]==null ? "Arial" : FontNode.Attributes["family"].Value;
				int fntSize = FontNode.Attributes["size"]==null ? 10 : Convert.ToInt32( FontNode.Attributes["size"].Value );
				string fntStyle = FontNode.Attributes["style"]==null ? "Regular" : FontNode.Attributes["style"].Value;

				switch (fntStyle)
				{
					case "Bold Italic":
						ReturnFont = new Font(fntName,fntSize,FontStyle.Bold | FontStyle.Italic);
						break;

					case "Bold":
						ReturnFont = new Font(fntName,fntSize,FontStyle.Bold);
						break;

					case "Italic":
						ReturnFont = new Font(fntName,fntSize,FontStyle.Italic);
						break;

					default :
						ReturnFont = new Font(fntName,fntSize,FontStyle.Regular);
						break;
				}

				return ReturnFont;
										
			}
			catch (Exception)
			{
				return new System.Drawing.Font("Arial",8,FontStyle.Regular);
			}
		}


		/// <summary>
		/// Converts characters in Text which are valid XML entities to safe strings
		/// </summary>
		/// <param name="Text">text to be parsed</param>
		/// <returns>XML-safe text</returns>
		public static string TextSafeForXML(string Text)
		{
			Text = Text.Replace("&","&amp;"); //&amp; -> &
			Text = Text.Replace("'","&apos;"); //&apos; -> '
			Text = Text.Replace("\"","&quot;"); //&quot; -> "
			Text = Text.Replace("<","&lt;"); //&lt; -> <
			Text = Text.Replace(">","&gt;"); //&gt; -> >
			return Text;
		}


		/// <summary>
		/// Replaces XML-safe strings back to Text which are valid XML entities
		/// </summary>
		/// <param name="XMLText">text to be parsed</param>
		/// <returns>Standard text</returns>
		public static string SafeXMLToText(string XMLText)
		{
			XMLText = XMLText.Replace("&amp;", "&");	//& -> &amp;
			XMLText = XMLText.Replace("&apos;", "'");	//' -> &apos;
			XMLText = XMLText.Replace("&quot;", "\"");	//" -> &quot;
			XMLText = XMLText.Replace("&lt;", "<");	//< -> &lt;
			XMLText = XMLText.Replace("&gt;", ">");	//> -> &gt;
			return XMLText;
		}
	}
}

⌨️ 快捷键说明

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