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

📄 product.cs

📁 网上购物系统源代码加毕业设计论文
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using eshop.DAL;

namespace eshop.BLL
{
	public class ProductDetails
	{
		public int productId;
		public string productName;
		public decimal productPrice;
		public string intro;
		public int categoryId;
		public int clickCount;
	}

	/// <summary>
	/// Product 的摘要说明。
	/// </summary>
	public class Product
	{
		public Product()
		{
		}

		/// <summary>
		/// 获取商品类型列表
		/// </summary>
		/// <returns>商品类型列表</returns>
		public static SqlDataReader GetCategoryList()
		{
			return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, 
				CommandType.StoredProcedure, "GetCategoryList");
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static SqlDataReader GetNewProductsList()
		{
			return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, 
				CommandType.StoredProcedure, "GetNewProductsList");
		}

		public static SqlDataReader GetPopularProduct()
		{
			return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, 
				CommandType.StoredProcedure, "GetPopularProduct");
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="categoryId"></param>
		/// <param name="pageSize"></param>
		/// <param name="pageIndex"></param>
		/// <returns></returns>
		public static SqlDataReader GetProductsByCategory(int categoryId, int pageSize, int pageIndex)
		{
			SqlParameter[] para = {
									  new SqlParameter("@CategoryId", categoryId),
									  new SqlParameter("@pageSize", pageSize),
									  new SqlParameter("@pageIndex", pageIndex)
								  };
			return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, 
				CommandType.StoredProcedure, "GetProductByCategory", para);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="categoryId"></param>
		/// <returns></returns>
		public static int GetProductCountByCategory(int categoryId)
		{
			SqlParameter[] para={
									new SqlParameter("@categoryId", categoryId)
								};
			return Convert.ToInt32(
				SQLHelper.ExecuteScalar(SQLHelper.CONN_STRING,
				CommandType.StoredProcedure, "GetProductCountByCategory", para)
				);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="keyword"></param>
		/// <param name="pageSize"></param>
		/// <param name="pageIndex"></param>
		/// <returns></returns>
		public static SqlDataReader SearchProducts (string keyword, int pageSize, int pageIndex)
		{
			SqlParameter[] para = {
									  new SqlParameter("@KeyWord", keyword),
									  new SqlParameter("@pageSize", pageSize),
									  new SqlParameter("@pageIndex", pageIndex)
								  };
			return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
				CommandType.StoredProcedure, "SearchProducts", para);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="keyword"></param>
		/// <returns></returns>
		public static int GetSearchResultCount(string keyword)
		{
			SqlParameter[] para={
									new SqlParameter("@keyword", keyword)
								};

			return Convert.ToInt32(
				SQLHelper.ExecuteScalar(SQLHelper.CONN_STRING, 
				CommandType.StoredProcedure, "GetSearchResultCount", para)
				);
		}

		public static ProductDetails GetProductInfo(int productId)
		{
			ProductDetails result = new ProductDetails();

			SqlParameter[] para={
									new SqlParameter("@productId", productId)
								};
			using(SqlDataReader dr = SQLHelper.ExecuteReader(
					  SQLHelper.CONN_STRING, CommandType.StoredProcedure, "GetProductInfo", para))
			{
				dr.Read();
				//给ProductDetails类的实例Result赋值
				result.productId = productId;
				result.productName = dr["productName"].ToString();
				result.productPrice = decimal.Parse(dr["productPrice"].ToString());
				result.intro = dr["Intro"].ToString();
				result.categoryId = int.Parse(dr["categoryId"].ToString());
				result.clickCount = int.Parse(dr["clickCount"].ToString());
					
				
			}
			return result;
		}

	}
}

⌨️ 快捷键说明

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