protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["quyen"] != null) { if (Session["quyen"].ToString() == "1") { Response.Redirect("~/AdminFood.aspx"); } else if (Session["quyen"].ToString() == "2") { Response.Redirect("~/AdminKH.aspx"); } else { Response.Redirect("~/AdminAD.aspx"); } } } if (Session["TenDN"] == null) { Response.Redirect("~/Dangnhap.aspx"); } if (Session["GioHang"] == null) { Response.Redirect("~/Giohang.aspx"); } if (Session["TenDN"] != null) { string s = "SELECT MAKH,HOTENKH,DIACHIKH,DIENTHOAIKH,EMAIL FROM KHACHHANG WHERE TENDN='" + Session["TenDN"].ToString() + "'"; DataTable dt = X.GetData(s); if (dt.Rows.Count > 0) { MAKH = int.Parse(dt.Rows[0][0].ToString()); lbHoTen.Text = dt.Rows[0][1].ToString(); lbDiaChi.Text = dt.Rows[0][2].ToString(); lbDienThoai.Text = dt.Rows[0][3].ToString(); lbEmail.Text = dt.Rows[0][4].ToString(); } } if (Session["Giohang"] != null) { DataTable dt = new DataTable(); dt = (DataTable)Session["GioHang"]; System.Decimal TongThanhTien = 0; foreach (DataRow r in dt.Rows) { r["ThanhTien"] = Convert.ToInt32(r["SoLuong"]) * Convert.ToDecimal(r["DonGia"]); TongThanhTien += Convert.ToDecimal(r["ThanhTien"]); lbTongTien.Text = TongThanhTien.ToString(); } gvGioHang.DataSource = dt; gvGioHang.DataBind(); } if (!IsPostBack) { cldNgayGiao.SelectedDate = DateTime.Today; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt; if (Session["TenDN"] != null) { if (Session["quyen"] == null) { Response.Redirect("~/Default.aspx"); } string tendn = Session["TenDN"].ToString(); dt = x.GetData("SELECT QUYENADMIN FROM ADMIN WHERE TENDNADMIN='" + tendn + "'"); string quyen = dt.Rows[0][0].ToString(); if (quyen == "2") { Response.Redirect("~/AdminKH.aspx"); } } else { Response.Redirect("~/AdminLogin.aspx"); } dt = x.GetData("SELECT* FROM SANPHAM"); gvGioHang.DataSource = dt; gvGioHang.DataBind(); } }
protected void btDangNhap_Click(object sender, EventArgs e) { try { DataTable dt = x.GetData("SELECT* FROM ADMIN WHERE TENDNADMIN='" + txtTenDN.Text + "' AND MATKHAUADMIN='" + txtMatKhau.Text + "'"); if (dt.Rows.Count > 0) { Session["TenDN"] = txtTenDN.Text; Session["quyen"] = dt.Rows[0][9].ToString(); if (Session["quyen"].ToString() == "1") { Response.Redirect("~/AdminFood.aspx"); } else if (Session["quyen"].ToString() == "2") { Response.Redirect("~/AdminKH.aspx"); } else { Response.Redirect("~/AdminAD.aspx"); } } else { lbThongBaoLoi.Text = "Tên đăng nhập hoặc mật khẩu không hợp lệ!"; } } catch { lbThongBaoLoi.Text = "Thất bại!"; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["quyen"] != null) { if (Session["quyen"].ToString() == "1") { Response.Redirect("~/AdminFood.aspx"); } else if (Session["quyen"].ToString() == "2") { Response.Redirect("~/AdminKH.aspx"); } else { Response.Redirect("~/AdminAD.aspx"); } } if (Request.QueryString["msp"] != null) { int MaSP = int.Parse(Request.QueryString["msp"]); DataTable dt = new DataTable(); dt = x.GetData("SELECT* FROM SANPHAM WHERE MASP=" + MaSP); DataList1.DataSource = dt; DataList1.DataBind(); } } }
private void ChuDeSach() { DataTable dt = x.GetData("select* from LOAI"); if (dt.Rows.Count > 0) { gvChuDeSach.DataSource = dt; gvChuDeSach.DataBind(); } }
protected void btDangky_Click(object sender, EventArgs e) { try { string str1 = @"SELECT 1 FROM KHACHHANG WHERE TENDN=N'" + txtTenDN.Text + "'"; if (x.GetData(str1).Rows.Count > 0) { lbThongBaoLoi.Text = "Tên đăng nhập đã tồn tại"; txtTenDN.Focus(); } else { SqlConnection con = new SqlConnection(x.strCon); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = @"INSERT INTO KHACHHANG(HOTENKH,DIACHIKH,DIENTHOAIKH,EMAIL,TENDN,MATKHAU,NGAYSINH,GIOITINH) VALUES(@HOTEN,@DIACHI,@DIENTHOAI,@EMAIL,@TENDN,@MATKHAU,@NGAYSINH,@GIOITINH)"; cmd.Parameters.Add("@HOTEN", SqlDbType.NVarChar, 50); cmd.Parameters["@HOTEN"].Value = txtHoTen.Text; cmd.Parameters.Add("@DIACHI", SqlDbType.NVarChar, 50); cmd.Parameters["@DIACHI"].Value = txtDiachi.Text; cmd.Parameters.Add("@DIENTHOAI", SqlDbType.VarChar, 10); cmd.Parameters["@DIENTHOAI"].Value = txtDienThoai.Text; cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar, 50); cmd.Parameters["@EMAIL"].Value = txtEmail.Text; cmd.Parameters.Add("@TENDN", SqlDbType.VarChar, 15); cmd.Parameters["@TENDN"].Value = txtTenDN.Text; cmd.Parameters.Add("@MATKHAU", SqlDbType.VarChar, 15); cmd.Parameters["@MATKHAU"].Value = txtMatKhau.Text; cmd.Parameters.Add("@NGAYSINH", SqlDbType.SmallDateTime); cmd.Parameters["@NGAYSINH"].Value = DateTime.Parse(ddlThangSinh.Text + "/" + ddlNgaySinh.Text + "/" + txtNamSinh.Text); cmd.Parameters.Add("@GIOITINH", SqlDbType.Int); cmd.Parameters["@GIOITINH"].Value = Convert.ToInt16(rblGioiTinh.SelectedIndex == 0); cmd.ExecuteNonQuery(); con.Close(); Response.Redirect("~/Dangnhap.aspx"); } } catch { lbThongBaoLoi.Text = "Thất bại!"; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["quyen"] != null) { if (Session["quyen"].ToString() == "1") { Response.Redirect("~/AdminFood.aspx"); } else if (Session["quyen"].ToString() == "2") { Response.Redirect("~/AdminKH.aspx"); } else { Response.Redirect("~/AdminAD.aspx"); } } if (Request.QueryString["msp"] != null) { int MaSP = int.Parse(Request.QueryString["msp"]); DataTable dt = x.GetData("SELECT TENSP,DONGIA FROM SANPHAM WHERE MASP=" + MaSP); String TenSP = dt.Rows[0][0].ToString(); float DonGia = float.Parse(dt.Rows[0][1].ToString()); int SoLuong = 1; ThemVaoGioHang(MaSP, TenSP, DonGia, SoLuong); } if (Session["GioHang"] != null) { DataTable dt = new DataTable(); dt = (DataTable)Session["GioHang"]; System.Decimal TongThanhTien = 0; foreach (DataRow r in dt.Rows) { r["ThanhTien"] = Convert.ToInt32(r["SoLuong"]) * Convert.ToDecimal(r["DonGia"]); TongThanhTien += Convert.ToDecimal(r["ThanhTien"]); lbTongThanhTien.Text = TongThanhTien.ToString(); } gvGioHang.DataSource = dt; gvGioHang.DataBind(); } } }
protected void btDangNhap_Click(object sender, EventArgs e) { try { DataTable dt = x.GetData("SELECT* FROM KHACHHANG WHERE TENDN='" + txtTenDN.Text + "' AND MATKHAU='" + txtMatKhau.Text + "'"); if (dt.Rows.Count > 0) { Session["TenDN"] = txtTenDN.Text; Response.Redirect("~/Giohang.aspx"); } else { lbThongBaoLoi.Text = "Tên đăng nhập hoặc mật khẩu không hợp lệ!"; } } catch { lbThongBaoLoi.Text = "Thất bại!"; } }
protected void btDongY_Click(object sender, EventArgs e) { try { DataTable dt = x.GetData("SELECT TENDNADMIN FROM ADMIN WHERE TENDNADMIN='" + txtTenDN.Text + "' AND MATKHAUADMIN='" + txtMatKhauCu.Text + "'"); if (dt.Rows.Count > 0) { x.Excute("UPDATE ADMIN SET MATKHAUADMIN='" + txtMatKhauMoi.Text + "'WHERE TENDNADMIN='" + txtTenDN.Text + "'"); lbThongBaoLoi.Text = "Đổi mật khẩu thành công"; } else { lbThongBaoLoi.Text = "Tên đăng nhập hoặc mật khẩu cũ không hợp lệ!"; } } catch { lbThongBaoLoi.Text = "Thất bại!"; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string MALOAI = Request.QueryString["MALOAI"]; DataTable dt = new DataTable(); if (MALOAI == null) { dt = x.GetData("select* from SANPHAM WHERE MALOAI=1"); if (dt.Rows.Count > 0) { DataList.DataSource = dt; DataList.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=1"); title.DataSource = dt; title.DataBind(); } dt.Clear(); dt = x.GetData("select* from SANPHAM WHERE MALOAI=2"); if (dt.Rows.Count > 0) { DataList1.DataSource = dt; DataList1.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=2"); title1.DataSource = dt; title1.DataBind(); } dt.Clear(); dt = x.GetData("select* from SANPHAM WHERE MALOAI=3"); if (dt.Rows.Count > 0) { DataList2.DataSource = dt; DataList2.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=3"); title2.DataSource = dt; title2.DataBind(); } dt.Clear(); dt = x.GetData("select* from SANPHAM WHERE MALOAI=4"); if (dt.Rows.Count > 0) { DataList3.DataSource = dt; DataList3.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=4"); title3.DataSource = dt; title3.DataBind(); } dt.Clear(); dt = x.GetData("select* from SANPHAM WHERE MALOAI=5"); if (dt.Rows.Count > 0) { DataList4.DataSource = dt; DataList4.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=5"); title4.DataSource = dt; title4.DataBind(); } dt.Clear(); dt = x.GetData("select* from SANPHAM WHERE MALOAI=6"); if (dt.Rows.Count > 0) { DataList5.DataSource = dt; DataList5.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=6"); title5.DataSource = dt; title5.DataBind(); } } else { dt = x.GetData("select* from SANPHAM WHERE MALOAI=" + MALOAI); if (dt.Rows.Count > 0) { DataList.DataSource = dt; DataList.DataBind(); dt.Clear(); dt = x.GetData("SELECT TEN FROM LOAI WHERE MALOAI=" + MALOAI); title.DataSource = dt; title.DataBind(); } } /* * if (dt.Rows.Count > 0) * { * DataList.DataSource = dt; * DataList.DataBind(); * }*/ } }