📄 shoucang.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.SqlClient;
public partial class users_shoucang : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label5.Text = Session["user"].ToString() + "欢迎您" + "(如果您不是" + Session["user"].ToString() + "请退出登录)";
Label7.Text = "以下是你收藏的宝贝";
shoucang();
}
private void ShowMassage(string msg)
{
Response.Write("<script>alert('" + msg + "')</script>");
//Response.Write("<script>window.location.href="'+index.aspx+'"</script>");
}
void shoucang()
{
string str1 = Session["sto"].ToString();
if (str1=="")
{
ShowMassage("你还没有向收藏夹中添加任何商品!");
}
else
{
string str = Session["sto"].ToString();
string[] Array = System.Text.RegularExpressions.Regex.Split(str, ",", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
DataTable tab = new DataTable();
DataColumn col2 = new DataColumn("id", System.Type.GetType("System.Int32"));
DataColumn col3 = new DataColumn("petname", System.Type.GetType("System.String"));
DataColumn col4 = new DataColumn("petmoney", System.Type.GetType("System.String"));
tab.Columns.Add(col2);
tab.Columns.Add(col3);
tab.Columns.Add(col4);
foreach (string i in Array)
{
DataRow dr = tab.NewRow();
if (i != "")
{
int pro_id = Int32.Parse(i);
SqlConnection con = new SqlConnection("data source=localhost;uid=sa;pwd=;database=Ebusiness");
con.Open();
SqlCommand comm1 = new SqlCommand("select id,petname,petmoney from product_info where id=@id", con);
SqlParameter pid = new SqlParameter("@id", SqlDbType.Int);
pid.Value = pro_id.ToString();
comm1.Parameters.Add(pid);
SqlDataReader reader;
reader = comm1.ExecuteReader();
if (reader.Read())
{
dr["id"] = reader.GetInt32(0);
dr["petname"] = reader.GetString(1);
dr["petmoney"] = reader.GetSqlMoney(2).ToString();
reader.Close();
}
con.Close();
for (int j = 0; j < tab.Rows.Count; j++)
{
int product_id_fromsession = Int32.Parse(tab.Rows[j]["id"].ToString());
if (pro_id == product_id_fromsession)
{
//Response.Write("这是测试语句!看是否每次都会运行");
tab.Rows[j].Delete();
}
}
}
else
break;
tab.Rows.Add(dr);
}
Session["storage"] = tab;
GridView1.DataSource = (DataTable)Session["storage"];
GridView1.DataBind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -