?? product.cs
字號(hào):
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 的摘要說(shuō)明。
/// </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類的實(shí)例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;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -