Product.cs
资源名称:SHOPASP.rar [点击查看]
上传用户:xiecaij
上传日期:2015-02-08
资源大小:2016k
文件大小:4k
源码类别:
百货/超市行业
开发平台:
ASP/ASPX
- 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;
- }
- }
- }