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

📄 myschedule.cs

📁 一个很精巧的个人日程管理程序
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace smartSchedule.ScheduleMethod
{
	/// <summary>
	/// MySchedule 的摘要说明。
	/// </summary>
	public class MySchedule
	{
		public MySchedule()
		{
			InitSchedule();
		}

		public MySchedule(ref MySchedule srcSchedule)
		{
			InitSchedule();
			TaskId = srcSchedule.GetTaskId();
			Title = srcSchedule.GetTitle();
			Detail = srcSchedule.GetDetail();
			BeginTime = srcSchedule.GetBeginTime();
			NotifyTime = srcSchedule.GetNotifyTime();
			NeedNotify = srcSchedule.GetFinished();
			Type = srcSchedule.GetScheduleType();
			Priority = srcSchedule.GetPriority();
			if(!IsValidSchedule())
				InitSchedule();
		}

		//初始化日程信息
		private void InitSchedule()
		{
			TaskId	= 0;
			Title	= "";
			Detail	= "";
			BeginTime = DateTime.Now;
			NotifyTime = DateTime.Now;
			NeedNotify = 0;
			Finished = 0;
			Type = 0;
			Priority = 0;
		}

		//清除日程信息
		public void ClearSchedule()
		{
			InitSchedule();
		}

		//获取指定Id的日程信息
		public bool GetScheduleById(ref SqlConnection myConn, int ScheduleId)
		{
			SqlCommand cmd = new SqlCommand("GetScheduleById", myConn);
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.Parameters.Add(ScheduleId);
			SqlDataReader ScheduleReader = cmd.ExecuteReader();

			int tmpTaskId = 0;
			string tmpTitle = "";
			string tmpDetail = "";
			DateTime tmpBeginTime = DateTime.Now;
			DateTime tmpNotifyTime = DateTime.Now;
			int tmpNeedNotify = 0;
			int tmpFinished = 0;
			int tmpType = 0;
			int tmpPriority = 0;

			try
			{
				if(ScheduleReader.Read())
				{
					tmpTaskId = Int32.Parse(ScheduleReader["TASK_ID"].ToString().Trim());
					tmpTitle = ScheduleReader["Title"].ToString().Trim();
					tmpDetail = ScheduleReader["Detail"].ToString().Trim();
					tmpBeginTime = DateTime.Parse(ScheduleReader["BeginTime"].ToString());
					tmpNotifyTime = DateTime.Parse(ScheduleReader["NotifyTime"].ToString());
					tmpNeedNotify = Int32.Parse(ScheduleReader["NeedNotify"].ToString().Trim());
					tmpFinished = Int32.Parse(ScheduleReader["Finished"].ToString().Trim());
					tmpType = Int32.Parse(ScheduleReader["Type"].ToString().Trim());
					tmpPriority = Int32.Parse(ScheduleReader["Priority"].ToString().Trim());
				}
			}
			catch
			{
				ScheduleReader.Close();
				return false;
			}

			TaskId = tmpTaskId;
			Title  = tmpTitle;
			Detail = tmpDetail;
			BeginTime = tmpBeginTime;
			NotifyTime = tmpNotifyTime;
			NeedNotify = tmpNeedNotify;
			Finished = tmpFinished;
			Type = tmpType;
			Priority = tmpPriority;

			return IsValidSchedule();
		}

		//获取指定日期的日程
		public bool GetScheduleByGivenDay(ref SqlConnection myConn, ref DataSet ds, ref DateTime GivenDay)
		{
			SqlDataAdapter da = new SqlDataAdapter("GetScheduleByGivenDay", myConn);
			da.SelectCommand.CommandType = CommandType.StoredProcedure;
			da.SelectCommand.Parameters.Add("@GivenDay", GivenDay);
			try
			{
				da.Fill(ds, "ScheduleList");
			}
			catch
			{
				return false;
			}
			return true;
		}

        //获取所有日程列表
		public bool GetAllSchedule(ref SqlConnection myConn, ref DataSet ds)
		{
			SqlDataAdapter da = new SqlDataAdapter("GetAllSchedule", myConn);
			da.SelectCommand.CommandType = CommandType.StoredProcedure;
			try
			{
				da.Fill(ds, "ScheduleList");
			}
			catch
			{
				return false;
			}
			return true;
		}

		//获取未完成日程列表
		public bool GetUnfinishedSchedule(ref SqlConnection myConn, ref DataSet ds)
		{
			SqlDataAdapter da = new SqlDataAdapter("getUnfinishedSchedule", myConn);
			da.SelectCommand.CommandType = CommandType.StoredProcedure;
			try
			{
				da.Fill(ds, "ScheduleList");
			}
			catch
			{
				return false;
			}
			return true;
		}

		//设置日程参数
		public void SetSchedule(int nTaskId, string sTitle, string sDetail, DateTime dBeginTime, DateTime dNotifyTime, int nNeedNotify, int nType, int nPriority)
		{
			TaskId		= nTaskId;
			Title		= sTitle;
			Detail		= sDetail;
			BeginTime  = dBeginTime;
			NotifyTime = dNotifyTime;
			NeedNotify = nNeedNotify;
			Type		= nType;
			Priority	= nPriority;

			CheckTitle();
			CheckDetail();
		}

		public bool InsertSchedule(ref SqlConnection myConn)
		{
			if(!IsValidSchedule())
				return false;

			SqlCommand cmd_InsertNewSchedule = new SqlCommand("InsertNewSchedule",myConn);
			cmd_InsertNewSchedule.CommandType = CommandType.StoredProcedure;
			cmd_InsertNewSchedule.Parameters.Add("@Title", Title);
			cmd_InsertNewSchedule.Parameters.Add("@Detail", Detail);
			cmd_InsertNewSchedule.Parameters.Add("@BeginTime", BeginTime);
			cmd_InsertNewSchedule.Parameters.Add("@Type", Type);
			cmd_InsertNewSchedule.Parameters.Add("@Priority", Priority);
			cmd_InsertNewSchedule.Parameters.Add("@NeedNotify", NeedNotify);
			cmd_InsertNewSchedule.Parameters.Add("@NotifyTime", NotifyTime);
			try
			{
				cmd_InsertNewSchedule.ExecuteNonQuery();
			}
			catch
			{
				return false;
			}

			return true;
		}

		//------------------------------------------------------------
		//数据成员约束函数
		public void CheckTitle()
		{
			Title.Trim();

			if(Title.Length >= MaxTitleLength)
			{
				Title = Title.Substring(0, MaxTitleLength);
			}
		}

		public void	CheckDetail()
		{
			Detail.Trim();

			if(Detail.Length >= MaxDetailLength)
			{
				Detail = Detail.Substring(0, MaxDetailLength);
			}
		}

		//检查日程是否有效
		public bool IsValidSchedule()
		{
			CheckTitle();
			CheckDetail();

			if( (Title == "") || (Detail == "") || (Type == 0) || (Priority == 0) )
				return false;
			return true;
		} 

		//-----------------------------------------------------------
		//数据成员访问函数
		public int GetTaskId()
		{
			return TaskId;
		}

		public string GetTitle()
		{
			return Title;
		}

		public string GetDetail()
		{
			return Detail;
		}

		public DateTime GetBeginTime()
		{
			return BeginTime;
		}

		public DateTime GetNotifyTime()
		{
			return NotifyTime;
		}

		public int GetNeedNotify()
		{
			return NeedNotify;
		}

		public int GetFinished()
		{
			return Finished;
		}

		public int GetScheduleType()
		{
			return Type;
		}

		public int GetPriority()
		{
			return Priority;
		}

		//-------------------------------------------------------------
		//数据成员
		private const int   MaxTitleLength = 256;
		private const int   MaxDetailLength = 8000;

		//日程属性
		private int			TaskId;
		private string		Title;
		private string		Detail;
		private DateTime    BeginTime;
		private DateTime	NotifyTime;
		private int			NeedNotify;
		private int			Finished;
		private int			Type;
		private int			Priority;
	}
}

⌨️ 快捷键说明

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