Exemplo n.º 1
0
        protected void btnUpDate_Click(object sender, EventArgs e)
        {
            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                int count = ctx.Users.Where(u => u.f_Username == txtUsername.Text).Count();

                if (count == 0)
                {
                }
                else
                {
                    User cUs = CurrentContext.GetCurUser();
                    cUs.f_Name  = txtName.Text;
                    cUs.f_Email = txtEmail.Text;
                    cUs.f_DOB   = (DateTime.ParseExact(txtDate.Text, "dd/M/yyyy", null));

                    ctx.Entry(cUs).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    if (ClientScript.IsStartupScriptRegistered("updateinfo") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "updateinfo",
                                                           "alert('Cập nhật thành công!');",
                                                           true
                                                           );
                    }
                }
            }
        }
        protected void btnLapHoaDon_Click(object sender, EventArgs e)
        {
            if (CurrentContext.GetCart().Items.Count == 0)
            {
                if (ClientScript.IsStartupScriptRegistered("thongbao") == false)
                {
                    ClientScript.RegisterStartupScript(this.GetType(),
                                                       "thongbao",
                                                       "alert('Giỏ hàng rỗng!');",
                                                       true
                                                       );
                }
                return;
            }

            Order ord = new Order
            {
                OrderDate = System.DateTime.Now,
                UserID    = CurrentContext.GetCurUser().f_ID,
                Total     = (long)Convert.ToDecimal(lblTotal.Text.Substring(0, lblTotal.Text.Length - 1))
            };

            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                foreach (CartItems item in CurrentContext.GetCart().Items)
                {
                    Product pro = ctx.Products.Where(p => p.ProID == item.ProID).FirstOrDefault();
                    if (pro != null)
                    {
                        Orderdetail d = new Orderdetail
                        {
                            ProID    = item.ProID,
                            Quantity = item.Quantity,
                            Price    = pro.Price,
                            Amount   = item.Quantity * pro.Price
                        };

                        ord.Orderdetails.Add(d);

                        UpdateQuantityAndSale(ctx, pro, item);
                    }
                }
                ctx.Orders.Add(ord);
                ctx.SaveChanges();
            }

            CurrentContext.GetCart().Items.Clear();
            ((template_sale_cars)this.Master).UpdateCartLink();
            lvwCart.DataSource = CurrentContext.GetCart().Items;
            lvwCart.DataBind();

            if (ClientScript.IsStartupScriptRegistered("thongbaotc") == false)
            {
                ClientScript.RegisterStartupScript(this.GetType(),
                                                   "thongbaotc",
                                                   "alert('Đặt hàng thành công!');",
                                                   true
                                                   );
            }
        }
 private void UpdateView(SaleCarsEntities ctx, Product pro)
 {
     //update view
     pro.Views++;
     ctx.Entry(pro).State = System.Data.Entity.EntityState.Modified;
     ctx.SaveChanges();
 }
        private void UpdateQuantityAndSale(SaleCarsEntities ctx, Product pro, CartItems item)
        {
            //update quantity
            pro.Quantity -= item.Quantity;
            //update sale
            pro.Sales += item.Quantity;

            ctx.Entry(pro).State = System.Data.Entity.EntityState.Modified;
            ctx.SaveChanges();
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            User u = new User
            {
                f_Username   = txtUserName.Text,
                f_Password   = StringUtils.MD5(txtRegPass.Text),
                f_Email      = txtEmail.Text,
                f_Name       = txtName.Text,
                f_DOB        = (DateTime.ParseExact(txtDate.Text, "dd/M/yyyy", null)),
                f_Permission = 0
            };

            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                ctx.Users.Add(u);
                ctx.SaveChanges();
            }

            Response.Redirect("~/login.aspx?msg=1");
        }
Exemplo n.º 6
0
        protected void btnChangePass_Click(object sender, EventArgs e)
        {
            string oldPass = StringUtils.MD5(txtOldPass.Text);

            using (SaleCarsEntities ctx = new SaleCarsEntities())
            {
                int count = ctx.Users.Where(u => u.f_Username == txtUsername.Text && u.f_Password == oldPass).Count();

                if (count == 0)
                {
                    if (ClientScript.IsStartupScriptRegistered("swal") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "swal",
                                                           "alert('Mật khẩu không đúng!');",
                                                           true
                                                           );
                    }
                }
                else
                {
                    User cUs = CurrentContext.GetCurUser();
                    cUs.f_Password = StringUtils.MD5(txtNewPass.Text);

                    ctx.Entry(cUs).State = System.Data.Entity.EntityState.Modified;
                    ctx.SaveChanges();

                    if (ClientScript.IsStartupScriptRegistered("updatepass") == false)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(),
                                                           "updatepass",
                                                           "alert('Đổi mật khẩu thành công!');",
                                                           true
                                                           );
                    }
                }
            }
        }