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

📄 commonfunc.cs

📁 一个网页的系统例子
💻 CS
字号:
using System;
using System.Configuration;
using System.Collections;
using System.Text;

namespace Common
{
	/// <summary>
	/// CommonFunc 的摘要说明。
	/// </summary>
	public class CommonFunc
	{
		public CommonFunc()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		/// <summary>
		/// 取得数据库连接字符串
		/// </summary>
		/// <returns></returns>
		public static string getConnectionString()
		{
			return ConfigurationSettings.AppSettings["SYS-CONN"];
		}

		/// <summary>
		/// 取得消息页面显示的图片路径
		/// </summary>
		/// <param name="type"></param>
		public static string getMessagePic(string type)
		{
			if (type=="1")
			{
				return ConfigurationSettings.AppSettings["ErrorPicPath"]; 
			}
			else if (type=="2")
			{
				return ConfigurationSettings.AppSettings["SuccessPicPath"];
			}
			else
			{
				return "";
			}
		}

		#region 返回页面显示用的数值
		public static string ConvertNumericToPageStyle(Object objValue) 
		{
			return ConvertNumericToPageStyle(objValue,false);
		}
		
		/// <summary>
		/// 返回页面显示用的数值
		/// </summary>
		/// <param name="objValue">对象(Int,Decimal,Float)</param>
		/// <param name="isAllowNegative">是否允许负数</param>
		/// <returns></returns>
		public static string ConvertNumericToPageStyle(Object objValue, bool isAllowNegative) 
		{
			if ( !isAllowNegative && decimal.Parse(objValue.ToString()) < 0)
			{
				return "";
			}

			string myValue = objValue.ToString();
			
			//Integer
			if (myValue.IndexOf(".") < 0)
			{
				return myValue;
			}
			
			//Decimal
			bool isloop = false;
			do 
			{
				//check the last bit
				string temp = myValue.Substring(myValue.Length-1,1);
				if (temp == "0") 
				{
					myValue = myValue.Substring(0,myValue.Length-1);
				}
				else if (myValue.Substring(myValue.Length-1,1) == ".")
				{
					myValue = myValue.Substring(0,myValue.Length-1);
					isloop = true;
				}
				else
				{
					isloop = true;
				}
			} while (! isloop);

			return myValue;
		}
		#endregion

		#region 返回页面显示用的日期(yyyy年MM月dd日)
		public static string ConvertDateToPageStyle(string strdate)
		{
			try
			{
				DateTime date = DateTime.Parse(strdate);
				string year = date.Year.ToString();
				string month = date.Month.ToString();
				string day = date.Day.ToString();

				if (month.Length < 2)
				{
					month = "0" + month;
				}
				if (day.Length < 2)
				{
					day = "0" + day;
				}
				
				string retDate = year + "年" + month + "月" + day + "日";

				return retDate;
			}
			catch
			{
				return "";
			}
		}
	
		#endregion

		#region 返回页面显示用货币格式
		/// <summary>
		/// 返回页面显示用货币格式
		/// </summary>
		/// <param name="objValue">对象(Int,Decimal,Float)</param>
		/// <param name="flag">货币标记</param>
		/// <returns></returns>
		public static string ConvertMoneyToPageStyle(Object objValue,String flag)
		{
			string strReturn = "";
			bool isNegative = false;
			
			//转换到页面显示用的数值(允许负数)
			string strValue = ConvertNumericToPageStyle(objValue,true);

			//判断有无小数
			int index = strValue.IndexOf(".");
			if (index >= 0)
			{
				//保留小数部分
				strReturn = strValue.Substring(index,strValue.Length - index);
				//取得整数部分
				strValue = strValue.Substring(0,index);
			}

			//判断是否负数
			if (strValue.Substring(0,1) == "-")
			{
				isNegative = true;
				strValue = strValue.Substring(1,strValue.Length -1);
			}
			
			//从后往前每三位增加一个分隔符
			bool isLoop = false;
			do
			{
				if (strValue.Length > 3)
				{
					strReturn = "," + strValue.Substring(strValue.Length -3) + strReturn;
					strValue = strValue.Substring(0,strValue.Length -3);
				} 
				else
				{
					strReturn = strValue + strReturn;
					isLoop = true;
				}
			} while (! isLoop);

			//负号
			if (isNegative) 
			{
				strReturn = "-" + strReturn;
			}

			//货币标记
			strReturn = flag + strReturn;

			return strReturn;
		}

		public static string ConvertMoneyToPageStyle(Object objValue)
		{
			return ConvertMoneyToPageStyle(objValue,"¥");
		}
		#endregion 

		


	}
}

⌨️ 快捷键说明

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