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

📄 category.cs

📁 wrox c#高级编程
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
 
namespace Wrox.WebModules.NewsManager.Business
{
	/// <summary>
	/// Summary description for Category.
	/// </summary>
	public sealed class Category : Wrox.WebModules.Business.BizObject
	{	
		private Configuration.ModuleSettings settings;	
		private int categoryID;
		private string name;
		private string imageUrl;
		private string description;
		
		// constructors
		public Category()
		{ 
			settings = Configuration.ModuleConfig.GetSettings();
			ResetProperties();
		}

		public Category(int existingCategoryID)
		{			
			settings = Configuration.ModuleConfig.GetSettings();
			categoryID = existingCategoryID;
			LoadFromID();						
		}

		public Category(Category existingCategory)
		{									
			settings = Configuration.ModuleConfig.GetSettings();
			categoryID = existingCategory.ID;
			LoadFromID();
		}
		
		// retrieve the values for the properties
		private void LoadFromID()
		{
			Data.Categories categories = new Data.Categories(settings.ConnectionString);
			Data.CategoryDetails details = categories.GetDetails(categoryID);

			categoryID = details.CategoryID;
			name = details.Name;
			imageUrl = details.ImageUrl;
			description = details.Description;
		}

		public int LoadFromID(int existingCategoryID)
		{
			categoryID = existingCategoryID;
			LoadFromID();
			return categoryID;
		}

		// reset the properties
		private void ResetProperties()
		{
			categoryID = -1;
			name = "";
			imageUrl = "";
			description = "";
		}

		// create a new record
		public int Create(string categoryName, string categoryDescription, string categoryImageUrl)
		{		
			Data.Categories categories = new Data.Categories(settings.ConnectionString);
			categoryID = categories.Add(categoryName, categoryDescription, categoryImageUrl);
			LoadFromID();
			return categoryID;
		}

		// update the record represented by this object
		public bool Update()
		{
			Data.Categories categories = new Data.Categories(settings.ConnectionString);
			return categories.Update(categoryID, name, description, imageUrl);
		}

		// delete the record represented by this object
		public bool Delete()
		{
			Data.Categories categories = new Data.Categories(settings.ConnectionString);
			bool ret = categories.Delete(categoryID);
			ResetProperties();
			return ret;
		}

		// return the categories
		public static DataSet GetCategories()
		{
			Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings();
			Data.Categories categories = new Data.Categories(settings.ConnectionString);
			return categories.GetCategories();
		}
		
		// return the child news
		public DataSet GetNews()
		{
			return GetNews(false);
		}

		public DataSet GetNews(bool currentApprovedOnly)
		{
			Data.News news = new Data.News(settings.ConnectionString);
			return news.GetNews(categoryID, currentApprovedOnly, settings.AbstractLength);
		}

		// return the child headlines
		public DataSet GetHeadlines()
		{
			Data.News news = new Data.News(settings.ConnectionString);
			DataSet headlines = news.GetHeadlines(categoryID);
			// add the NewsUrl column that is a link to the page that shows the entire news body
			headlines.Tables[0].Columns.Add("NewsUrl", 
				System.Type.GetType("System.String"), 
				"'" + settings.NewsUrl + "?NewsID=' + newsID");
			return headlines;
		}

		// add a new child news
		public News AddNews(string newsTitle, string newsBody, DateTime newsReleaseDate, 
			DateTime newsExpireDate, bool newsApproved, int newsUserID)
		{
			Business.News news = new Business.News();
			news.Create(categoryID, newsTitle, newsBody, newsReleaseDate, 
				newsExpireDate, newsApproved, newsUserID);
			return news;
		}


		// PROPERTIES DEFINED BELOW

		public int ID
		{
			get { return categoryID; }
		}

		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		public string Description
		{
			get { return description; }
			set { description = value; }
		}

		public string ImageUrl
		{
			get { return imageUrl; }
			set { imageUrl = value; }
		}

	}
}

⌨️ 快捷键说明

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