using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CommonFunction.常用功能及函数集
{
	/// <summary>
	/// DateTiemOper 的摘要说明。
	/// </summary>
	public class DateTiemOper : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtWeek;
		protected System.Web.UI.WebControls.TextBox txtYearDay;
		protected System.Web.UI.WebControls.Button btnGetYear;
		protected System.Web.UI.WebControls.Button btnGetMonthDay;
		protected System.Web.UI.WebControls.TextBox txtMonthDays;
		protected System.Web.UI.WebControls.Button btnWeek;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnWeek.Click += new System.EventHandler(this.btnWeek_Click);
			this.btnGetYear.Click += new System.EventHandler(this.btnGetYear_Click);
			this.btnGetMonthDay.Click += new System.EventHandler(this.btnGetMonthDay_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnWeek_Click(object sender, System.EventArgs e)
		{
			string dt ,week="";

			dt = DateTime.Now.DayOfWeek.ToString();
			switch  (dt)
			{
				case "Monday":
					week= "星期一";
					break;
				case "Tuesday" :
					week= "星期二";
					break;
				case "Wednesday":
					week= "星期三";
					break;
				case "Thursday" :
					week= "星期四";
					break;
				case "Friday" :
					week= "星期五";
					break;
				case "Saturday":
					week= "星期六";
					break;
				case "Sunday":
					week = "星期日";
					break;

			}
			txtWeek.Text =  week;
		}

		private void btnGetYear_Click(object sender, System.EventArgs e)
		{
			//判断是否是闰年
			if(DateTime.IsLeapYear(Convert.ToInt32(txtYearDay.Text)))
			{
				//如果是闰年
				txtYearDay.Text = "366天";
			}
			else
			{
				//如果不是闰年
				txtYearDay.Text = "365天";
			}
		}

		private void btnGetMonthDay_Click(object sender, System.EventArgs e)
		{
			int year,month,days=0;
			year = DateTime.Now.Year ;
			month = DateTime.Now.Month ;

			//得到当前月的天数信息。
			switch (month)
			{
				case 1:
					days = 31;
					break;
				case 2:
					if (DateTime.IsLeapYear(year)) 
					{
						//闰年二月为 29 天
						days = 29;
					}
					else
					{
						//闰年二月为 28 天
						days = 28;
					}

					break;
				case 3:
					days = 31;
					break;
				case 4:
					days = 30;
					break;
				case 5:
					days = 31;
					break;
				case 6:
					days = 30;
					break;
				case 7:
					days = 31;
					break;
				case 8:
					days = 31;
					break;
				case 9:
					days = 30;
					break;
				case 10:
					days = 31;
					break;
				case 11:
					days = 30;
					break;
				case 12:
					days = 31;
					break;
			}	   

			txtMonthDays.Text = days.ToString();
		}
	}
}
