Example #1
0
        public static bool IsLogged()
        {
            if ((int)HttpContext.Current.Session["IsLogin"] == 1)
            {
                return(true);
            }

            if (HttpContext.Current.Request.Cookies["accID"] != null)
            {
                int accID = Convert.ToInt32(HttpContext.Current.Request.Cookies["accID"].Value);
                HttpContext.Current.Session["IsLogin"] = 1;

                using (DBEcommerceEntities db = new DBEcommerceEntities())
                {
                    int role = db.Accounts.SingleOrDefault(acc => acc.AccountID == accID).Role.RoleID;
                    if (role == 1)
                    {
                        HttpContext.Current.Session["CurAd"] = "Admin";
                    }
                    else if (role == 2)
                    {
                        Employee employ = db.Employees.Where(emp => emp.AccountID == accID).FirstOrDefault();
                        HttpContext.Current.Session["CurEmp"] = employ;
                    }
                    else
                    {
                        Customer customer = db.Customers.Where(c => c.AccountID == accID).FirstOrDefault();
                        HttpContext.Current.Session["CurCus"] = customer;
                    }
                }
                return(true);
            }

            return(false);
        }
Example #2
0
 void loadProducts()
 {
     using (DBEcommerceEntities db = new DBEcommerceEntities())
     {
         lvProducts.DataSource = db.Products.OrderByDescending(pro => pro.NumViews).ToList();
         lvProducts.DataBind();
     }
 }
Example #3
0
 private void LoadDataShip(int shipID)
 {
     using (DBEcommerceEntities db = new DBEcommerceEntities())
     {
         List <Product> ds = db.Products.Where(p => p.SupplierID == shipID).ToList();
         this.lvProducts.DataSource = ds;
         this.lvProducts.DataBind();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack == false)
     {
         using (DBEcommerceEntities db = new DBEcommerceEntities())
         {
             List <Slider> ds = db.Sliders.ToList();
             this.lvSider.DataSource = ds;
             this.lvSider.DataBind();
             HtmlGenericControl a = (HtmlGenericControl)this.lvSider.Items[0].FindControl("divSlider");
             a.Attributes.Add("class", "item active");
         }
     }
 }
Example #5
0
 protected void cvEmailSu_ServerValidate(object source, ServerValidateEventArgs args)
 {
     using (DBEcommerceEntities db = new DBEcommerceEntities())
     {
         var checkExist = db.Accounts.Where(acc => acc.UserName == txtEmailSu.Text).FirstOrDefault();
         if (checkExist != null)
         {
             args.IsValid = false;
         }
         else
         {
             args.IsValid = true;
         }
     }
 }
Example #6
0
        protected void btnSignup_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Account account = new Account
                {
                    UserName = txtEmailSu.Text,
                    PassWord = StringUltils.MD5(txtPasswordSu.Text),
                    RoleID   = 3,
                    Enabled  = true
                };

                String gioiTinh = "";
                if (int.Parse(cbbSex.SelectedValue) == 1)
                {
                    gioiTinh = "Nam";
                }
                if (int.Parse(cbbSex.SelectedValue) == 2)
                {
                    gioiTinh = "Nữ";
                }

                Customer customer = new Customer
                {
                    FullName  = txtNameSu.Text,
                    AccountID = account.AccountID,
                    Email     = txtEmailSu.Text,
                    BirthDay  = DateTime.ParseExact(txtBirthDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    Address   = txtDiaChi.Text,
                    Sex       = gioiTinh,
                    Account   = account
                };

                using (DBEcommerceEntities db = new DBEcommerceEntities())
                {
                    db.Customers.Add(customer);
                    db.SaveChanges();
                }

                Response.Redirect("~/board.aspx?msg=1");
            }
        }
Example #7
0
 private void LoadData(int cate = 0)
 {
     if (cate == 0)
     {
         using (DBEcommerceEntities db = new DBEcommerceEntities())
         {
             List <Product> ds = db.Products.ToList();
             this.lvProducts.DataSource = ds;
             this.lvProducts.DataBind();
         }
     }
     else
     {
         using (DBEcommerceEntities db = new DBEcommerceEntities())
         {
             List <Product> ds = db.Products.Where(p => p.CategoryID == cate).ToList();
             this.lvProducts.DataSource = ds;
             this.lvProducts.DataBind();
         }
     }
 }
Example #8
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            using (DBEcommerceEntities db = new DBEcommerceEntities())
            {
                string pass          = StringUltils.MD5(txtPasswordLog.Text);
                var    checkAccExist = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text).FirstOrDefault();
                if (checkAccExist != null)
                {
                    var account = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text &&
                                                    acc.PassWord == pass).FirstOrDefault();
                    if (account != null)
                    {
                        var checkEnable = db.Accounts.Where(acc => acc.UserName == txtEmailLog.Text &&
                                                            acc.PassWord == pass &&
                                                            acc.Enabled == true).FirstOrDefault();
                        if (checkEnable != null)
                        {
                            int role = checkEnable.Role.RoleID;
                            if (role == 1) // admin
                            {
                                var employ = db.Employees.Where(emp => emp.AccountID == account.AccountID).FirstOrDefault();
                                Session["IsLogin"] = 1;
                                Session["CurAd"]   = "admin";
                                Session["CurEmp"]  = employ;
                                Response.Redirect("~/Admin/Report.aspx");
                            }
                            else if (role == 2) // nhân viên
                            {
                                var employ = db.Employees.Where(emp => emp.AccountID == account.AccountID).FirstOrDefault();
                                if (employ != null)
                                {
                                    Session["IsLogin"] = 1;
                                    Session["CurEmp"]  = employ;
                                    Response.Redirect("~/Admin/Report.aspx");
                                }
                            }
                            else // khách hàng
                            {
                                var customer = db.Customers.Where(cus => cus.AccountID == account.AccountID).FirstOrDefault();

                                if (customer != null) // là khách hàng
                                {
                                    Session["IsLogin"] = 1;
                                    Session["CurCus"]  = customer;
                                }
                            }
                            Session["Cart"] = new helpers.cCart();
                            if (cbKeep.Checked)
                            {
                                Response.Cookies["accID"].Value   = checkEnable.AccountID.ToString();
                                Response.Cookies["accID"].Expires = DateTime.Now.AddDays(7);
                            }

                            string retUrl = Request.QueryString["retUrl"];
                            if (string.IsNullOrEmpty(retUrl))
                            {
                                retUrl = "~/Default.aspx";
                            }
                            Response.Redirect(retUrl);
                        }
                        else
                        {
                            lblMessLog.Text = "Tài khoản đã bị khóa";
                        }
                    }
                    else
                    {
                        lblMessLog.Text = "Mật khẩu không đúng";
                    }
                }
                else
                {
                    lblMessLog.Text = "Tên tài khoản không tồn tại";
                }
            }
        }