//===========================================================================
// Smarclient FPMS Demo Project a sample project for SmartClient technology.
// Smarclient FPMS Demo is designed and implemented bases Microsoft Application Block tech.
// Author: SFPMS Team, Date 2004-11
// Vision 1.0
// Revison History
//=============================================================================

using System;
using System.Globalization; 

namespace JSW.FPMS.Tool
{
	/// <summary>
	/// 巡检系统日期专用处理类
	/// </summary>
	public class clsRiQiChuLi
	{
		#region 常量区域              
		public const String    RiQiCuoWu					= "1/1/1";	//错误日期，表示格式化日期字符串出了问题		

		public const String    RiQiJiSuanNian				= "Nian";	//根据年计算
		public const String    RiQiJiSuanYue				= "Yue";	//根据月计算
		public const String    RiQiJiSuanRi					= "Ri";		//根据日计算
		public const String    RiQiJiSuanShi				= "Shi";	//根据小时计算
		public const String    RiQiJiSuanFen				= "Fen";	//根据分钟计算
		public const String    RiQiJiSuanMiao				= "Miao";	//根据秒计算
		#endregion

		#region 公开方法区域	
				
		/// <summary>
		/// 按照指定的日期格式处理日期数据
		/// </summary>
		/// <param name="RiQi">日期数据</param>
		/// <param name="GeShi">日期格式<example>:yyyy-MM-dd:</example></param>	
		/// <returns>按照指定格式得到的日期数据</returns>
		public static String RiQiGeShi(String RiQi, String GeShi)
		{
			try 
			{
		
				DateTime Date = DateTime.Parse(RiQi);
				String RiQiJieGuo = Date.ToString(GeShi,DateTimeFormatInfo.InvariantInfo);
				//根据指定的日期格式生成日期
				return RiQiJieGuo;
			}
			catch(Exception genException )
			{		
				String CuoWuZFC=genException.Message; 
				return RiQiCuoWu;//发生了错误
			}
		}

		/// <summary>
		/// 按照指定的日期格式得到当前日期
		/// </summary>				
		/// <returns>当前日期数据</returns>
		public static String DangQianRiQi()
		{
			return DateTime.Now.ToString();
		}

		/// <summary>
		/// 按照指定的日期格式得到当前日期
		/// </summary>		
		/// <param name="GeShi">日期格式<example>:yyyy-MM-dd:</example></param>	
		/// <returns>按照指定格式得到的当前日期数据</returns>
		public static String DangQianRiQi(String GeShi)
		{
			return RiQiGeShi(DateTime.Now.ToString(),GeShi);
		}

		/// <summary>
		/// 指定的日期计算
		/// </summary>
		/// <param name="RiQi">日期</param>
		/// <param name="JiSuLeiXing">日期计算类型<example>RiQiChuLi.RiQiJiSuanNian</example></param>	
		/// <param name="JiSuanZhi">具体的日期计算变化值</param>
		/// <returns>按照指定计算值得到的日期数据</returns>
		public static String RiQiJiSuaZengJia(String RiQi,String JiSuLeiXing,int JiSuanZhi)
		{
			try 
			{
				DateTime date = DateTime.Parse(RiQi); 
				switch (JiSuLeiXing) 
				{
					case RiQiJiSuanNian :
						date = date.AddYears( JiSuanZhi);
						break;
					case RiQiJiSuanYue	:
						date = date.AddMonths( JiSuanZhi);
						break;
					case RiQiJiSuanRi	:
						date = date.AddDays( JiSuanZhi);
						break;
					case RiQiJiSuanShi	:
						date = date.AddHours( JiSuanZhi);
						break;
					case RiQiJiSuanFen	:
						date = date.AddMinutes(JiSuanZhi); 
						break;
					case RiQiJiSuanMiao	:
						date = date.AddSeconds( JiSuanZhi);
						break;
				}
				return date.ToString(); 
			}
			catch (Exception genException)
			{
				String CuoWuZFC=genException.Message; 
				return RiQiCuoWu;//发生了错误;
			}
		}

		#endregion
	}
}
