⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoucang.aspx.cs

📁 前台首页:users/index.aspx 后台首页:login.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 + -