예제 #1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     Button1.Attributes.Add("AutoPostback", "true");
     con             = new SqlConnection(constr);
     cmd             = new SqlCommand();
     cmd.Connection  = con;
     cmd.CommandText = "SELECT * FROM NGUOISUDUNG WHERE TenDangNhap= '" + TextBox1.Text + "'and MatKhau='" + TextBox2.Text + "'";
     sda             = new SqlDataAdapter(cmd);
     sda.Fill(ds, "NGUOISUDUNG");
     if (ds.Tables[0].Rows.Count > 0)
     {
         Session["user"] = TextBox1.Text;
     }
     else
     {
         Label1.Text   = "Đăng nhập không thành công";
         TextBox1.Text = "";
         TextBox2.Text = "";
     }
     if (Request.QueryString["MaSP"] == null) //Đăng nhập từ giỏ hàng
     {
         Response.Redirect("/GioHang.aspx");
     }
     else //Thêm sản phẩm vào giỏ hàng mà chưa đăng nhập
     {
         int       maSP   = int.Parse(Request.QueryString["MaSP"]);
         GioHangDB db     = new GioHangDB();
         bool      resutl = db.InsertGioHang(Session["user"].ToString(), maSP);
         Response.Redirect("/GioHang.aspx");
     }
 }
예제 #2
0
        protected void BtnThemGioHang_Click(object sender, ImageClickEventArgs e)
        {
            int maSP = int.Parse(((ImageButton)sender).CommandArgument);

            if (Session["user"] == null)
            {
                Response.Redirect("/DangNhap_GioHang?MaSP=" + maSP); // Yêu cầu đăng nhập trước khi thêm sản phẩm vào giỏ hàng
            }
            else
            {
                string    tenDangNhap = Session["user"].ToString();
                GioHangDB db          = new GioHangDB();
                bool      resutl      = db.InsertGioHang(tenDangNhap, maSP);
                Response.Write("<script language='javascript'>alert('Đã thêm sản phẩm vào giỏ hàng!')</script>");
            }
        }