Exemple #1
0
        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;
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Admins             vcontroller = new Admins();
                Entities.KhachHang vusers      = new Entities.KhachHang();
                string             errMsg      = string.Empty;
                int result = vcontroller.Login_khachhang(true, txtUserName.Text, txtPassword.Text, ref errMsg);

                if (result > 0)
                {
                    vusers = vcontroller.getby_tk_khachhang(txtUserName.Text, ref errMsg);

                    if (vusers != null)
                    {
                        Session.Add("UserID", Convert.ToInt32(vusers.MaKH));
                        Session.Add("FullName", Convert.ToString(vusers.Hoten));
                        Response.Redirect("~/Admin/users.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)
            {
                AlertNotification.Visible = true;
                lblAlert.Text             = ex.Message;
            }
        }