protected void btndangki_Click(object sender, EventArgs e)
        {
            Entity.KhachHang objkh = new Entity.KhachHang();
            if (txtpassword.Text != "")
            {
                objkh.MatKhau = txtpassword.Text.Trim();
            }
            else
            {
                objkh.MatKhau = MatKhau;
                //Response.Write("<script>alert('Bạn phải bắt buộc phải nhập mật khẩu!')</script>");
                //return;
            }
            objkh.TenKH = txthovaten.Text.Trim();
            if (rdobtnNam.Checked == true)
            {
                objkh.GioiTinh = "true";
            }
            else
            {
                objkh.GioiTinh = "false";
            }
            objkh.NgaySinh = txtngaysinh.Text;

            objkh.SDT    = txtdienthoai.Text.Trim();
            objkh.Tinh   = ddlthanhpho.SelectedItem.ToString();
            objkh.Quan   = ddlquan.SelectedItem.ToString();
            objkh.DiaChi = txtdiachi.Text.Trim();
            List <Entity.KhachHang> lst = new List <Entity.KhachHang>();

            if (Session["link_fb"] != null)
            {
                objkh.Email = txtemail.Text;
                lst         = KhachHangService.KhachHang_GetByTop("", " link_fb='" + Session["link_fb"] + "' ", "");
                objkh.Id    = lst[0].Id;
                KhachHangService.KhachHang_Update(objkh);
                Response.Write("<script>alert('Cật nhật thành công')</script>");
            }
            else
            {
                objkh.Email = txtemail.Text.Trim();
                lst         = KhachHangService.KhachHang_GetByTop("", " TaiKhoan='" + Session["TenDangNhap"] + "'", "");
                objkh.Id    = lst[0].Id;
                KhachHangService.KhachHang_Update(objkh);
                Response.Write("<script>alert('Cật nhật thành công')</script>");
            }
        }
        protected void btndathang_Click(object sender, EventArgs e)
        {
            List <Entity.KhachHang> lstKh = new List <Entity.KhachHang>();

            Entity.DatHang        dh    = new Entity.DatHang();
            List <Entity.DatHang> lstdh = new List <Entity.DatHang>();

            Entity.ChiTietDatHang lstctdh = new Entity.ChiTietDatHang();
            string Id_SP;

            if (txtdiachi.Text == "" || txtdienthoai.Text == "" || txtemail.Text == "" || txthovaten.Text == "" || ddlquan.SelectedIndex == 0 || ddlthanhpho.SelectedIndex == 0)
            {
                Response.Write("<script>alert('Bạn phải nhập đầy đủ thông tin!!1')</script>");
                return;
            }
            else if (Session["Link_Fb"] == null)
            {
                if (Session["TenDangNhap"] == null)
                {
                    Entity.KhachHang obj = new Entity.KhachHang();

                    obj.TenKH    = txthovaten.Text;
                    obj.TaiKhoan = "";
                    obj.MatKhau  = "";
                    obj.NgaySinh = "";
                    obj.GioiTinh = "True";

                    obj.Email   = txtemail.Text;
                    obj.SDT     = txtdienthoai.Text;
                    obj.DiaChi  = txtdiachi.Text;
                    obj.Tinh    = ddlthanhpho.SelectedItem.ToString();
                    obj.Quan    = ddlquan.SelectedItem.ToString();
                    obj.Link_Fb = "false";
                    KhachHangService.KhachHang_Insert(obj);
                    lstKh           = KhachHangService.KhachHang_GetByTop("", " id=(SELECT MAX(id) from tbl_KhachHang) ", "");
                    dh.Id_KhachHang = lstKh[0].Id;
                    dh.NgaylapHD    = DateTime.Now.ToString();
                    dh.IdPay        = ddlhinhthucthanhtoan.SelectedValue.ToString();
                    DatHangService.DatHang_Insert(dh);
                    lstdh             = DatHangService.DatHang_GetByTop("", " id=(SELECT MAX(id) from tbl_DatHang)", "");
                    lstctdh.Id_hoadon = lstdh[0].Id;
                    for (int i = 0; i < tbGioHang.Rows.Count; i++)
                    {
                        string tenSP = tbGioHang.Rows[i]["TenSP"].ToString();
                        Id_SP              = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id;
                        lstctdh.Id_hang    = Id_SP;
                        lstctdh.Size       = tbGioHang.Rows[i]["Size"].ToString();
                        lstctdh.SoLuongMua = tbGioHang.Rows[i]["SoLuong"].ToString();
                        lstctdh.ThanhTien  = tbGioHang.Rows[i]["TongGia"].ToString();
                        lstctdh.Gia        = tbGioHang.Rows[i]["Gia"].ToString();
                        ChiTietDatHangService.ChiTietDatHang_Insert(lstctdh);
                    }
                }
                else
                {
                    string TenDangNhap = Session["TenDangNhap"].ToString();

                    lstKh = KhachHangService.KhachHang_GetByTop("", " TaiKhoan='" + TenDangNhap + "'", "");
                    Entity.KhachHang kh = new Entity.KhachHang();
                    kh.Id     = lstKh[0].Id;
                    kh.TenKH  = txthovaten.Text;
                    kh.Email  = txtemail.Text;
                    kh.DiaChi = txtdiachi.Text;
                    kh.SDT    = txtdienthoai.Text;
                    kh.Tinh   = ddlthanhpho.SelectedItem.ToString();
                    kh.Quan   = ddlquan.SelectedItem.ToString();
                    KhachHangService.KhachHang_UpdateDatHang(kh);

                    dh.NgaylapHD    = DateTime.Now.ToString();
                    dh.IdPay        = ddlhinhthucthanhtoan.SelectedValue.ToString();
                    dh.Id_KhachHang = kh.Id;
                    DatHangService.DatHang_Insert(dh);

                    lstdh = DatHangService.DatHang_GetByTop("", " id=(SELECT MAX(id) from tbl_DatHang where id_KhachHang=" + kh.Id + ")", "");


                    lstctdh.Id_hoadon = lstdh[0].Id;
                    for (int i = 0; i < tbGioHang.Rows.Count; i++)
                    {
                        string tenSP = tbGioHang.Rows[i]["TenSP"].ToString();
                        Id_SP              = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id;
                        lstctdh.Id_hang    = Id_SP;
                        lstctdh.Size       = tbGioHang.Rows[i]["Size"].ToString();
                        lstctdh.SoLuongMua = tbGioHang.Rows[i]["SoLuong"].ToString();
                        lstctdh.ThanhTien  = tbGioHang.Rows[i]["TongGia"].ToString();
                        lstctdh.Gia        = tbGioHang.Rows[i]["Gia"].ToString();
                        ChiTietDatHangService.ChiTietDatHang_Insert(lstctdh);
                    }
                }
            }
            else
            {
                string Link_Fb = Session["Link_Fb"].ToString();

                lstKh = KhachHangService.KhachHang_GetByTop("", " Link_Fb='" + Link_Fb + "' ", "");
                Entity.KhachHang kh = new Entity.KhachHang();
                kh.Id     = lstKh[0].Id;
                kh.TenKH  = txthovaten.Text;
                kh.Email  = txtemail.Text;
                kh.DiaChi = txtdiachi.Text;
                kh.SDT    = txtdienthoai.Text;
                kh.Tinh   = ddlthanhpho.SelectedItem.ToString();
                kh.Quan   = ddlquan.SelectedItem.ToString();
                KhachHangService.KhachHang_UpdateDatHang(kh);

                dh.NgaylapHD    = DateTime.Now.ToString();
                dh.IdPay        = ddlhinhthucthanhtoan.SelectedValue.ToString();
                dh.Id_KhachHang = kh.Id;
                DatHangService.DatHang_Insert(dh);

                lstdh = DatHangService.DatHang_GetByTop("", " id=(SELECT MAX(id) from tbl_DatHang where id_KhachHang=" + kh.Id + ")", "");


                lstctdh.Id_hoadon = lstdh[0].Id;
                for (int i = 0; i < tbGioHang.Rows.Count; i++)
                {
                    string tenSP = tbGioHang.Rows[i]["TenSP"].ToString();
                    Id_SP              = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id;
                    lstctdh.Id_hang    = Id_SP;
                    lstctdh.Size       = tbGioHang.Rows[i]["Size"].ToString();
                    lstctdh.SoLuongMua = tbGioHang.Rows[i]["SoLuong"].ToString();
                    lstctdh.ThanhTien  = tbGioHang.Rows[i]["TongGia"].ToString();
                    lstctdh.Gia        = tbGioHang.Rows[i]["Gia"].ToString();
                    ChiTietDatHangService.ChiTietDatHang_Insert(lstctdh);
                }
            }
            Response.Write("<script>alert('Đặt hàng thành công!!')</script>");
            Session["GioHang"] = null;
            lblsl                 = (Label)Master.FindControl("lblslgiohang");
            lblsl.Text            = "0";
            lbltongtien.Text      = "0 VNĐ";
            tbGioHang             = null;
            grvsanpham.DataSource = tbGioHang;
            grvsanpham.DataBind();
        }