protected void btndangnhap_Click(object sender, EventArgs e) { try { EndUser vcontroller_enduser = new EndUser(); Admins vcontroller_admin = new Admins(); Entities.KhachHang vkhachhang = new Entities.KhachHang(); string errMsg = string.Empty; int result = vcontroller_admin.Login_khachhang(false, txtusername.Text, txtmakhau.Text, ref errMsg); if (result > 0) { vkhachhang = vcontroller_admin.getby_tk_khachhang(txtusername.Text, ref errMsg); if (vkhachhang != null) { Session.Add("KhachhangID", Convert.ToInt32(vkhachhang.MaKH)); Session.Add("FullName_KH", Convert.ToString(vkhachhang.Hoten)); Response.Redirect("~/Default.aspx"); } } else { if (result == -1) { throw new Exception("Sai tên tài khoản hoặc mật khẩu!"); } else { throw new Exception("Hệ thống gặp sự cố trong quá trình xác thực tài khoản!"); } } } catch (Exception ex) { throw ex; } }
public void ThemHD(int _mahd, string _tenkhachhang, string _diachi, string _sodienthoai, string _email) { EndUser.Open(); string now = DateTime.Now.ToString("MM/dd/yyyy"); string qry = "insert into hoadon values('" + _mahd + "','" + _tenkhachhang + "','" + _diachi + "','" + _sodienthoai + "','" + _email + "','" + now + "','" + now + "','False')"; SqlCommand cmd = new SqlCommand(qry, EndUser.cnn); cmd.ExecuteNonQuery(); cmd.Dispose(); EndUser.Close(); }
public DataTable getall_sp_chude(int _chude) { EndUser.Open(); string qry = "SELECT top 20 SanPham.[MaSP], [TenSP], [GiaMua], [GiaBan], [LoaiSP], [ThongTin], [ChuDe], [GioiTinh], [hot], [HinhAnh], [NgayNhapHang],[SoLuong],[Size] FROM [SanPham] inner join SanPham_Size on SanPham.MaSP = SanPham_Size.MaSP inner join Size on SanPham_Size.MaSize = Size.MaSize WHERE ChuDe =" + _chude; SqlCommand cmd = new SqlCommand(qry, EndUser.cnn); SqlDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); cmd.Dispose(); reader.Dispose(); EndUser.Close(); return(dt); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { giohang(); if (Request.QueryString["url"] != null) { string ulr = Request.QueryString["url"]; EndUser vcontrol = new EndUser(); switch (ulr) { case "nam": dtlSanPham.DataSource = vcontrol.getall_sp_gioitinh(1); dtlSanPham.DataBind(); break; case "nam0": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(0, 1); dtlSanPham.DataBind(); break; case "nam1": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(1, 1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nam1"; break; case "nam2": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(2, 1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nam2"; break; case "nam3": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(3, 1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nam3"; break; case "nam4": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(4, 1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nam4"; break; case "nu": dtlSanPham.DataSource = vcontrol.getall_sp_gioitinh(0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu0"; break; case "nu0": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(0, 0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu0"; break; case "nu1": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(1, 0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu1"; break; case "nu2": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(2, 0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu2"; break; case "nu3": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(3, 0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu3"; break; case "nu4": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(5, 0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "nu4"; break; case "phukien1": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(6, 1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "pknam"; break; case "phukien0": dtlSanPham.DataSource = vcontrol.getall_sp_loaisp_gioitinh(6, 0); dtlSanPham.DataBind(); break; case "saleoff": dtlSanPham.DataSource = vcontrol.getall_sp_chude(2); dtlSanPham.DataBind(); //Session["LoaiSP"] = "saleoff"; break; case "new": dtlSanPham.DataSource = vcontrol.getall_sp_chude(1); dtlSanPham.DataBind(); //Session["LoaiSP"] = "new"; break; case "hot": dtlSanPham.DataSource = vcontrol.getall_sp_chude(0); dtlSanPham.DataBind(); //Session["LoaiSP"] = "hot"; break; case "tk": //string TenSP = Request.QueryString["value"]; //dtlSanPham.DataSource = bus.TimKiemSanPham(TenSP); //dtlSanPham.DataBind(); break; default: break; } } } }
protected void btndathang_Click(object sender, EventArgs e) { try { EndUser vcontrol = new EndUser(); int mahd = Convert.ToInt32(DateTime.Now.Millisecond.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()); vcontrol.ThemHD(mahd, txttenkhachhang.Text, txtdiachi.Text, txtsdt.Text, txtemail.Text); DataTable cart = Session["cart"] as DataTable; ; foreach (DataRow row in cart.Rows) { //vcontrol.ThemCTHD(mahd, row["ID"].ToString(), row["Size"].ToString(), Convert.ToInt32(row["Quantity"]), Convert.ToDouble(row["Price"])); } Session["cart"] = null; Response.Redirect("Default.aspx"); } catch (Exception ex) { throw ex; } }