示例#1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["CurCus"] != null)
     {
         Customer c = (Customer)Session["CurCus"];
         Order    O = new Order();
         O.CustomerID = c.CustomerID;
         O.DateBuy    = DateTime.Now;
         O.EmployeeID = null;
         O.Status     = 2;
         O.Payments   = "Thanh toan ngay";
         helpers.cCart cart = CurrentContext.getCart();
         foreach (helpers.cCartItem item in cart.Items)
         {
             Product     p   = db.Products.SingleOrDefault(q => q.ProductID == item.ProID);
             OrderDetail del = new OrderDetail();
             del.ProductID  = p.ProductID;
             del.Quantity   = item.Quantity;
             del.UnitPrice  = p.UnitPrice;
             del.TotalMoney = Convert.ToDouble(del.Quantity * del.UnitPrice);
             O.OrderDetails.Add(del);
         }
         O.TotalMoney = O.OrderDetails.Sum(m => m.TotalMoney);
         db.Orders.Add(O);
         db.SaveChanges();
         cart.Items.Clear();
         Response.Redirect("~/Default.aspx");
     }
     else
     {
         Response.Redirect("~/404.aspx");
     }
 }
示例#2
0
 protected void Session_Start(object sender, EventArgs e)
 {
     Session["IsLogin"] = 0;
     Session["CurCus"]  = null;
     Session["CurEmp"]  = null;
     Session["CurAd"]   = null;
     Session["Cart"]    = new helpers.cCart();
 }
示例#3
0
 protected void btnThanhToan_Click(object sender, EventArgs e)
 {
     if (rdoNgay.Checked)
     {
         double amountVND = Convert.ToDouble(Session["Total"]);
         string itemInfo  = "Cart Item";
         string name      = "hb";
         string phone     = "01688469370";
         string email     = "*****@*****.**";
         string currency  = "USD";
         PayWithPayPal(amountVND.ToString(), itemInfo, name, phone, email, currency);
     }
     else
     {
         if (Session["CurCus"] != null)
         {
             Customer c = (Customer)Session["CurCus"];
             Order    O = new Order();
             O.CustomerID = c.CustomerID;
             O.DateBuy    = DateTime.Now;
             O.EmployeeID = null;
             O.Status     = 1;
             O.Payments   = "Thanh toan ngay";
             helpers.cCart cart = CurrentContext.getCart();
             foreach (helpers.cCartItem item in cart.Items)
             {
                 Product     p   = db.Products.SingleOrDefault(q => q.ProductID == item.ProID);
                 OrderDetail del = new OrderDetail();
                 del.ProductID  = p.ProductID;
                 del.Quantity   = item.Quantity;
                 del.UnitPrice  = p.UnitPrice;
                 del.TotalMoney = Convert.ToDouble(del.Quantity * del.UnitPrice);
                 O.OrderDetails.Add(del);
             }
             O.TotalMoney = O.OrderDetails.Sum(m => m.TotalMoney);
             db.Orders.Add(O);
             db.SaveChanges();
             cart.Items.Clear();
             Response.Redirect("~/Default.aspx?sucess=1");
         }
     }
 }
示例#4
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";
                }
            }
        }