Exemplo n.º 1
0
        private ArrayList createOrderDetailRecord(int orderId)
        {
            ordersDetail odl = new ordersDetail();

            using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities())
            {
                WebDL.shoppingCart sc = new shoppingCart();
                var data = from car in bke.shoppingCarts where car.userID == userId select car;
                List <WebDL.shoppingCart> scl = data.ToList();

                for (int i = 0; i < scl.Count; i++)
                {
                    odl.ordersID  = orderId;
                    odl.productID = scl[i].productID;
                    odl.quantity  = scl[i].quantity;
                    odl.ordersDetailDescription = "";
                    bke.ordersDetails.Add(odl);
                    bke.SaveChanges();

                    // var odId = (from r in bke.ordersDetails select r).Last();
                    //int lastID = bke.ordersDetails.AsEnumerable().Last().ordersDetailID;
                    //odIDList[i] = odl.ordersDetailID;
                    odIDList.Add(odl.ordersDetailID);
                }
            }

            return(odIDList);
        }
Exemplo n.º 2
0
 protected void btnCreate_Click(object sender, EventArgs e)
 {
     using (Team2_BookDBEntities cntx = new Team2_BookDBEntities())
     {
         var createProduct = new product();
         createProduct.categoryID             = Convert.ToInt32(dropListCategoryType.SelectedValue);
         createProduct.productName            = txtBookName.Text;
         createProduct.productCode            = txtCodeNo.Text;
         createProduct.productQty             = Convert.ToInt32(txtQty.Text);
         createProduct.productPrice           = Convert.ToDouble(txtPrice.Text);
         createProduct.productDiscount        = Convert.ToDouble(txtDiscount.Text);
         createProduct.productDiscountedPrice = Convert.ToDouble(txtDisPrice.Text);
         createProduct.productDescription     = txtDesc.Text;
         //createProduct.productID = 5;
         if (fileUImage.HasFile)
         {
             string filename = Path.GetFileName(fileUImage.PostedFile.FileName);
             fileUImage.SaveAs(Server.MapPath("~/Images") + filename);
             createProduct.productImage = filename;
         }
         lblSuccessful.Text = "Success";
         cntx.products.Add(createProduct);
         cntx.SaveChanges();
     }
 }
Exemplo n.º 3
0
 private void removeShoppingCart()
 {
     using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities())
     {
         var sc = from f in bke.shoppingCarts where f.userID == userId select f;
         if (sc != null)
         {
             bke.shoppingCarts.RemoveRange(sc);
             bke.SaveChanges();
         }
     }
 }
Exemplo n.º 4
0
        private int  createOrderRecord()
        {
            order order = new order();

            using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities())
            {
                order.userID            = userId;
                order.ordersDate        = DateTime.Now.Date;
                order.ordersDescription = "";
                bke.orders.Add(order);
                bke.SaveChanges();
            }
            orderID = order.ordersID;
            return(orderID);
        }
Exemplo n.º 5
0
        private void createDeliveryRecord()
        {
            using (WebDL.Team2_BookDBEntities bke = new Team2_BookDBEntities())
            {
                delivery deli = new delivery();
                deli.userID              = userId;
                deli.ordersID            = orderID;
                deli.deliveryDate        = Convert.ToDateTime(txtDeliveryDate.Text);
                deli.deliveryStatus      = "pending";
                deli.deliveryAddress     = lbDeliveryAddress.Text;
                deli.deliveryDescription = txtDeliveryDescrip.Text;
                bke.deliveries.Add(deli);

                bke.SaveChanges();
            }
        }
Exemplo n.º 6
0
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row        = GridView1.Rows[e.RowIndex];
            int         deliveryId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
            string      status     = (row.FindControl("txtDeliveryStatus") as TextBox).Text;

            using (Team2_BookDBEntities entities = new Team2_BookDBEntities())
            {
                delivery delivery = (from d in entities.deliveries
                                     where d.deliveryID == deliveryId
                                     select d).FirstOrDefault();
                delivery.deliveryStatus = status;
                entities.SaveChanges();
            }

            GridView1.EditIndex = -1;
            this.BindGrid();
        }
Exemplo n.º 7
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var db = new Team2_BookDBEntities())
     {
         try
         {
             var myItem = (from c in db.shoppingCarts where c.user.userName == updateCartID && c.product.productID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.quantity = quantity;
                 db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 8
0
        public void AddToCart(string name)
        {
            ShoppingCartActions  Action = new ShoppingCartActions();
            Team2_BookDBEntities DB     = new Team2_BookDBEntities();
            // Retrieve the product from the database.
            string ShoppingCartId = Action.GetCatrId();
            var    user           = from u in DB.users where u.userName == ShoppingCartId select u;

            WebDL.user userdata = user.FirstOrDefault();
            var        book     = from b in DB.products where b.productName == name select b;

            WebDL.product bookdata = book.FirstOrDefault();
            var           cartItem = DB.shoppingCarts.FirstOrDefault(
                c => c.user.userName == ShoppingCartId &&
                c.product.productName == name);
            var product = DB.products.FirstOrDefault(p => p.productName == name);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists.
                cartItem = new shoppingCart
                {
                    productID = bookdata.productID,
                    quantity  = Convert.ToInt32(tbQuantity.Text),
                    userID    = userdata.userID,
                    shoppingCartExpiredDate = DateTime.Now.AddDays(7),
                    user    = DB.users.SingleOrDefault(u => u.userID == userdata.userID),
                    product = DB.products.SingleOrDefault(p => p.productName == name)
                };

                DB.shoppingCarts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity.
                cartItem.quantity += Convert.ToInt32(tbQuantity.Text);
            }
            product.productQty -= Convert.ToInt32(tbQuantity.Text);

            DB.SaveChanges();
        }
Exemplo n.º 9
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var db = new Team2_BookDBEntities())
     {
         try
         {
             var myItem = (from c in db.shoppingCarts where c.user.userName == removeCartID && c.product.productID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 // Remove Item.
                 db.shoppingCarts.Remove(myItem);
                 db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 10
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            using (Team2_BookDBEntities cntx = new Team2_BookDBEntities())
            {
                string  productcode = txtBookCode.Text;
                var     data        = from f in cntx.products where f.productCode == productcode select f;
                product p           = data.First();

                p.productName = txtBookName.Text;
                p.productCode = txtBookCode.Text;
                //dropListCategoryType.SelectedValue = p.categoryID.ToString();
                p.categoryID             = Convert.ToInt32(txtCategory.Text);
                p.productDescription     = txtDescription.Text;
                p.productQty             = Convert.ToInt32(txtQuantity.Text);
                p.productPrice           = Convert.ToInt32(txtPrice.Text);
                p.productDiscount        = Convert.ToInt32(txtDiscount.Text);
                p.productDiscountedPrice = Convert.ToInt32(txtDiscountedPrice.Text);
                cntx.SaveChanges();
                lblSuccess.Text = "Update successfully.";
                ClearFields();
            }
        }
Exemplo n.º 11
0
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            using (Team2_BookDBEntities cntx = new Team2_BookDBEntities())
            {
                string loginUserName = Session["userName"].ToString();
                var    editUser      = cntx.users.Where(a => a.userName.Equals(loginUserName)).FirstOrDefault();
                //var editUser = new user();
                if (editUser != null)
                {
                    editUser.userName        = txtUserName.Text;
                    editUser.roleID          = 1;
                    editUser.userPassword    = txtPassword.Text;
                    editUser.userEmail       = txtEmail.Text;
                    editUser.userPhone       = Convert.ToInt32(txtPhoneNo.Text);
                    editUser.userAddress     = txtAddress.Text;
                    editUser.userDescription = txtDesc.Text;

                    cntx.SaveChanges();
                    Response.Redirect("/AdminHome.aspx");
                }
                Response.Redirect("/AdminHome.aspx");
            }
        }