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

📄 categoryitem.cs

📁 一个采用VS2008+Sql2000开发的任务管理系统
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace BronzeMonkey.GeneralTaskList
{
	/// <summary>
	/// Summary description for CategoryItem.
	/// </summary>
	public class CategoryItem
	{
		public readonly int CategoryID = 0;
		public string Description = String.Empty;
		public string IconUrl = String.Empty;

		public CategoryItem()
		{
		}

		public CategoryItem(int CategoryID, string Description, string IconUrl)
		{
			this.CategoryID = CategoryID;
			this.Description = Description;
			this.IconUrl = IconUrl;
		}

		public void Update(string ConnectionString)
		{
			
			SqlCommand Command = new SqlCommand("TaskList_UpdateCategory", new SqlConnection(ConnectionString));
			Command.CommandType = CommandType.StoredProcedure;

			Command.Parameters.Add("@CategoryID", SqlDbType.BigInt).Value = this.CategoryID;
			Command.Parameters.Add("@Description", SqlDbType.VarChar, 25).Value = this.Description;
			Command.Parameters.Add("@IconUrl", SqlDbType.VarChar, 500).Value = this.IconUrl;

			Command.Connection.Open();
			Command.ExecuteNonQuery();
			Command.Connection.Close();

			Command.Dispose();
		}

		public static CategoryItem GetCategoryItem(int CategoryID, string ConnectionString)
		{
			CategoryItem ThisItem = new CategoryItem();

			SqlCommand Command = new SqlCommand("TaskList_GetCategoryByID", new SqlConnection(ConnectionString));
			Command.CommandType = CommandType.StoredProcedure;

			Command.Parameters.Add("@CategoryID", SqlDbType.BigInt).Value = CategoryID;

			Command.Connection.Open();
			SqlDataReader dr = Command.ExecuteReader(CommandBehavior.CloseConnection);
			if( dr.Read() )
			{
				ThisItem = new CategoryItem(
					Convert.ToInt32(dr["CategoryID"]),
					Convert.ToString(dr["Description"]),
					Convert.ToString(dr["IconUrl"])
				);
			}
			else
			{
				throw new Exception("Could not find a Category matching ID " + CategoryID.ToString());
			}
			
			dr.Close();
			Command.Dispose();

			return ThisItem;
		}

		public static int AddCategoryItem(string Description, string IconUrl, string ConnectionString)
		{
			SqlCommand Command = new SqlCommand("TaskList_AddCategory", new SqlConnection(ConnectionString));
			Command.CommandType = CommandType.StoredProcedure;

			Command.Parameters.Add("@Description", SqlDbType.VarChar, 25).Value = Description;
			Command.Parameters.Add("@IconUrl", SqlDbType.VarChar, 500).Value = IconUrl;
			SqlParameter RetVal = Command.Parameters.Add("@ReturnValue", SqlDbType.Int);
			RetVal.Direction = ParameterDirection.ReturnValue;

			Command.Connection.Open();
			Command.ExecuteNonQuery();
			Command.Connection.Close();

			Command.Dispose();

			return Convert.ToInt32(RetVal.Value);
		}

		public static void DeleteCategoryItem(int CategoryID, string ConnectionString)
		{
			SqlCommand Command = new SqlCommand("TaskList_DeleteCategory", new SqlConnection(ConnectionString));
			Command.CommandType = CommandType.StoredProcedure;

			Command.Parameters.Add("@CategoryID", SqlDbType.BigInt).Value = CategoryID;

			Command.Connection.Open();
			Command.ExecuteNonQuery();
			Command.Connection.Close();

			Command.Dispose();
		}
	}
}

⌨️ 快捷键说明

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