📄 kindspage.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class User_kindsPage : System.Web.UI.Page
{
UserInfo ui = new UserInfo();
changePage cp = new changePage();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
title.Text = Request.QueryString["name"];
}
countPage();
//ui.DGBind(Request.QueryString["name"], DataList1);
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "detail")
{
Session["address"] = "";
//Session["address"] = "~/User/kindsPage.aspx";
Session["address"] = "kindsPage.aspx?name=" + Request.QueryString["name"].ToString() + "&page=" + Request.QueryString["page"];
Response.Redirect("~/User/GoodsDetail.aspx?GoodsID=" + Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString()));
}
else if (e.CommandName == "buy")
{
addShopCart(e, DataList1);
}
}
public void addShopCart(DataListCommandEventArgs e, DataList dlName)
{
if (Session["UID"] != null)
{
SaveGoodsClass sgc = getSaveGoodsClass(e, dlName);
string userID = Session["UID"].ToString();
ui.addShopCart(sgc.GoodsID, sgc.MemberPrice, userID);
ui.MessageBox(Page, "添加成功");
}
}
public SaveGoodsClass getSaveGoodsClass(DataListCommandEventArgs e, DataList dlName)
{
SaveGoodsClass goods = new SaveGoodsClass();
goods.MemberPrice = Convert.ToDouble(e.CommandArgument.ToString());
goods.GoodsID = dlName.DataKeys[e.Item.ItemIndex].ToString();
return goods;
}
public void countPage()
{
DBConn dbconn = new DBConn();
OleDbConnection conn = dbconn.GetConnection();
int classID= ui.classId(Request.QueryString["name"]);
string sql = "SELECT * from tb_GoodsInfo where ClassID=" +classID;
cp.TotalPicture= ui.countLine(sql); //总个数
cp.PageNow = Convert.ToInt32(Request.QueryString["page"]);
int start = (cp.PageNow - 1) * cp.PictureNum;
OleDbDataAdapter ad = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();
//显示的开始,结束.
if (cp.TotalPicture < cp.PictureNum)
{
ui.DGBind(Request.QueryString["name"], DataList1, start, cp.TotalPicture);
}
else
{
ui.DGBind(Request.QueryString["name"], DataList1, start, cp.PictureNum);
// cp.LeavePicture = cp.TotalPicture - cp.PictureNum;
if (cp.TotalPicture % cp.PictureNum == 0)
{
cp.PageNum = cp.TotalPicture / cp.PictureNum;
}
else if (cp.TotalPicture % cp.PictureNum > 0)
{
cp.PageNum = (cp.TotalPicture / cp.PictureNum) + 1;
}
}
for (int i = 1; i <= cp.PageNum; ++i)
{
lblPage.Text += "[<a href='kindsPage.aspx?name=" + Request.QueryString["name"].ToString() + "&page="+i.ToString()+"'>" + i.ToString() + "</a>]";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -