69 lines
3.5 KiB
C#
69 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using CitySunlight.Product;
|
|
|
|
namespace CitySunlight
|
|
{
|
|
public partial class Main : System.Web.UI.Page
|
|
{
|
|
int pages = HttpUtils.getQueryString("pages").ToInt();
|
|
public String classid = HttpUtils.getQueryString("classid");
|
|
public String search = HttpUtils.getQueryString("search");
|
|
public String classoption;
|
|
const decimal peritems = 5;
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
classoption = ProductClassManager.getOptionString("classid", classid);
|
|
}
|
|
public String GetProductInfo()
|
|
{
|
|
String html = "";
|
|
DataTable items = ProductManager.SearchProduct("", search, classid, "", "", pages, peritems.ToString().ToInt());
|
|
if (items.Rows.Count == 0)
|
|
return "<tr><td style=\"color:red\" colspan=\"8\" align=\"center\">数据库中未找到产品</td></tr>";
|
|
else
|
|
html += HttpUtils.addThs("商品名称", "商品图片", "商品价格", "商品库存", "商品分类", "所属卖家");
|
|
html += "<tbody class=\"text-center\">";
|
|
foreach (DataRow item in items.Rows)
|
|
{
|
|
int id = int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.ID));
|
|
String name = ProductManager.GetProductInfo(item, ProductManager.Info.ItemName);
|
|
String url = ProductManager.GetProductInfo(item, ProductManager.Info.PicUrl);
|
|
String picurl = String.Format("<img src=\"../Picture/{0}\" alt=\"\" width=\"64\" height=\"64\"/>", url);
|
|
String price = ProductManager.GetProductInfo(item, ProductManager.Info.Price);
|
|
String amount = ProductManager.GetProductInfo(item, ProductManager.Info.Amount);
|
|
String user = ProductManager.GetProductInfo(item, ProductManager.Info.UserName);
|
|
String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.Class)));
|
|
|
|
html += HttpUtils.addTds(ProductManager.NameToUrl(id, name), picurl, price, amount, classname, user);
|
|
}
|
|
decimal allproduct = ProductManager.SearchProduct("", search, classid, "", "").Rows.Count;
|
|
decimal totalpages = Math.Ceiling(allproduct / peritems);
|
|
String allpage = "<ul class=\"pagination\">";
|
|
for (int i = 1; i <= totalpages; i++)
|
|
{
|
|
String page = String.Format("<li><a href=\"/Main.aspx?search={0}&classid={1}&pages={2}\">{3}</a></li>", search, classid, i, i);
|
|
allpage += page;
|
|
}
|
|
allpage += String.Format("<li><a href=\"#\">共{0}页</a><li>", totalpages);
|
|
allpage += "</ul>";
|
|
html += String.Format("<tr><td colspan=\"6\" align=\"right\">{0}</td></tr>", allpage);
|
|
html += "</tbody>";
|
|
return html;
|
|
}
|
|
|
|
protected void searchB_Click(object sender, EventArgs e)
|
|
{
|
|
String search = HttpUtils.getElementsbyName("search");
|
|
String classid = HttpUtils.getElementsbyName("classid");
|
|
String url = String.Format("/Main.aspx?search={0}&classid={1}&pages=1", search, classid == "0" ? "" : classid);
|
|
Response.Redirect(url);
|
|
}
|
|
|
|
}
|
|
} |