110,534
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 获取产品
/// </summary>
/// <param name="manufacturerID">厂商ID,为null时不做查询条件。</param>
/// <param name="categoryID">类别ID,为null时不做查询条件。</param>
/// <param name="typeID">类型ID,为null时不做查询条件。</param>
/// <param name="name">产品名称,模糊匹配。</param>
/// <param name="description">描述,模糊匹配。</param>
/// <param name="pageSize">页大小</param>
/// <param name="pageIndex">页索引</param>
/// <returns></returns>
public DataTable GetProduct(int? manufacturerID, int? categoryID, int? typeID, string name, string description, int pageSize, int pageIndex)
{
......
}
public class QueryProduct
{
private int? manufacturerID;
/// <summary>
/// 厂商ID,为null时不做查询条件。
/// </summary>
public int? ManufacturerID
{
get { return manufacturerID; }
set { manufacturerID = value; }
}
private int? categoryID;
/// <summary>
/// 类别ID,为null时不做查询条件。
/// </summary>
public int? CategoryID
{
get { return categoryID; }
set { categoryID = value; }
}
private int? typeID;
/// <summary>
/// 类型ID,为null时不做查询条件。
/// </summary>
public int? TypeID
{
get { return typeID; }
set { typeID = value; }
}
private string name;
/// <summary>
/// 产品名称,模糊匹配。
/// </summary>
public string Name
{
get { return name; }
set { name = value; }
}
private string description;
/// <summary>
/// 描述,模糊匹配。
/// </summary>
public string Description
{
get { return description; }
set { description = value; }
}
private int pageSize;
/// <summary>
/// 页大小
/// </summary>
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
private int pageIndex;
/// <summary>
/// 页索引
/// </summary>
public int PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
}
/// <summary>
/// 获取产品
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public DataTable GetProduct(QueryProduct query)
{
......
}
Query(1,2,3);
Query( new Condition() { Id = 1, Category = 2, Price = 3 } );
Query( new Conditon().Id(1).Category(2).Price(3) );
public DataTable GetProductsByPage(QueryCondition condition, int pageSize, int pageIndex)
{
......
}
GetProductsByPage(new QueryCondition() { Name = "abc", Discription = "blabla" }, 10, 0);
GetProduct(null, null, null, "abc", "blabla", 10, 0);
new Query() { Id = 123 }.Get();
new Query() { Name = "abc" }.GetByPage(10, 0);
new Query().IdIs( 123 ).Get();
new Query().NameLike( "abc" ).GetByPage(10, 0);
new Query().PriceLargeThan( 10 ).GetByPage(10, 0);