Example #1
0
        protected void lvOrderItems_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item is ListViewDataItem)
            {
                int quantity          = 0;
                ListViewDataItem item = (ListViewDataItem)e.Item;
                IGrouping <long?, Product_Order> query = (IGrouping <long?, Product_Order>)item.DataItem;
                Product_Order prodOrder = query
                                          .Where(b => b != null)
                                          .ToList().FirstOrDefault();
                foreach (Product_Order ProdItem in order.Product_Order)
                {
                    if (prodOrder.Product_ID == ProdItem.Product_ID)
                    {
                        quantity++;
                    }
                }

                Product prod        = dde.Products.Find(prodOrder.Product_ID);
                Label   lblProdName = e.Item.FindControl("lblProdName") as Label;
                lblProdName.Text = prod.Product_Name;
                Label lblPrice = e.Item.FindControl("lblPrice") as Label;
                lblPrice.Text = String.Format("{0:C}", prod.Price);
                Label lblQuantity = e.Item.FindControl("lblQuantity") as Label;
                lblQuantity.Text = quantity.ToString();
                Label lblProductID = (Label)e.Item.FindControl("lblProductID");
                lblProductID.Text = prod.Product_ID.ToString();
            }
        }
Example #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            var findproduct = FactoryObject.Products.Where(x => x.BarkodNo == tbxBarkodNo.Text).FirstOrDefault();

            if (findproduct != null)
            {
                if (!gbProductInfo.Visible)
                {
                    gbProductInfo.Show();
                }
                lblBarcode.Text     = findproduct.BarkodNo;
                lblPrice.Text       = findproduct.UnitPrice.ToString();
                lblProductName.Text = findproduct.ProductName;

                var findProductCategory = FactoryObject.ProductsCategories.Where(x => x.ProductID == findproduct.ProductId).Select(x => x.CategoryID).ToList();
                if (findProductCategory.Count != 0)
                {
                    lbCategory.DataSource    = CategoryHelper.ReturnLastUpdatedCategorybyCategoryID(findProductCategory);
                    lbCategory.DisplayMember = "CategoryName";
                }
                products_order = new Product_Order {
                    Barcod = findproduct.BarkodNo, Price = findproduct.UnitPrice, ProductID = findproduct.ProductId, ProductName = findproduct.ProductName
                };
            }
            else
            {
                gbProductInfo.Hide();
                MessageBox.Show("Ürün Bulunamadı.");
            }
            BarcodeFocus();
        }
Example #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (products_order != null)
            {
                var isExist = products_order_list.Where(x => x.ProductID == products_order.ProductID).FirstOrDefault();
                if (isExist == null)
                {
                    products_order.Piece      = decimal.Parse(txbPiece.Text);
                    products_order.TotalPrice = decimal.Parse(lblPrice.Text) * products_order.Piece;
                    products_order_list.Add(products_order);
                }
                else
                {
                    isExist.Piece     += decimal.Parse(txbPiece.Text);
                    isExist.TotalPrice = isExist.Price * isExist.Piece;
                }

                products_order = null;
                Clear();
                BarcodeFocus();
                RefreshListView();
                SetTotalPrice();
            }
            else
            {
                MessageBox.Show("Ürün Bulunamadı");
            }
            gbProductInfo.Hide();
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,OrderId,Quantity")] Product_Order product_Order)
        {
            if (id != product_Order.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product_Order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Product_OrderExists(product_Order.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "Id", "ClientName", product_Order.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", product_Order.ProductId);
            return(View(product_Order));
        }
Example #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product_Order product_Order = db.Product_Order.Find(id);

            db.Product_Order.Remove(product_Order);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #6
0
 public OrderFrm()
 {
     InitializeComponent();
     products_order_list = new List <Product_Order>();
     products_order      = new Product_Order();
     gbProductInfo.Hide();
     SetProperty();
 }
Example #7
0
        public void Delete(int id)
        {
            Product_Order oroduct_Order = db.ProductOrders.Find(id);

            if (oroduct_Order != null)
            {
                db.ProductOrders.Remove(oroduct_Order);
            }
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("Id,AdressDeliveryStreetName,AdressDeliveryPostalCode,AdressDeliveryCountry,AdressDeliveryCity,AdressDeliveryOption_1,AdressDeliveryOption_2,AdressFacturationStreetName,AdressFacturationPostalCode,AdressFacturationCountry,AdressFacturationCity,AdressFacturationOption_1,AdressFacturationOption_2,ClientId")] Order order)
        {
            order.Client = await _userManager.FindByIdAsync(order.ClientId);

            order.Date = DateTime.Now;
            if (ModelState.IsValid)
            {
                var ListProductSession          = HttpContext.Session.GetString("ListCards");
                List <ProductCart> productCarts = JsonConvert.DeserializeObject <List <ProductCart> >(ListProductSession);
                //initialisation de variable de calcul
                double totalWeight   = 0;
                double shippingPrice = 0;
                double totalPrice    = 0;
                //enregistrement de l'order dans la base de donnée !
                _context.Add(order);
                await _context.SaveChangesAsync();

                //Order a maintenant un id !

                //conversion du Productcard sans id en Product-orders
                //et introduction dans la base de donnée de chacun relier avec orderId
                foreach (var item in productCarts)
                {
                    //calcul
                    totalWeight = totalWeight + item.Product.Weight * item.Quantity;
                    totalPrice  = totalPrice + item.Product.Price * item.Quantity;
                    //creation d'un object Product_Order & populate
                    Product_Order product_Order = new Product_Order();
                    product_Order.OrderId   = order.Id;
                    product_Order.ProductId = item.Product.Id;
                    //product_Order.Product = await _productRepository.GetProduct(product_Order.ProductId);
                    product_Order.Quantity = item.Quantity;
                    _context.Add <Product_Order>(product_Order);
                    await _context.SaveChangesAsync();
                }
                //finalisation des calcule
                shippingPrice = totalWeight * 1.2;
                totalPrice    = totalPrice + shippingPrice;

                //Modification de Order dans la base de donnée !

                order.State        = "payement accepted";
                order.Total        = totalPrice;
                order.Weight       = totalWeight;
                order.DeliveryCost = shippingPrice;

                _context.Update(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Clients, "Id", "Id", order.ClientId);
            return(View(order));
        }
Example #9
0
 public ActionResult Edit([Bind(Include = "productOrder_id,product_id,order_id")] Product_Order product_Order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.order_id   = new SelectList(db.Order, "order_id", "orderName", product_Order.order_id);
     ViewBag.product_id = new SelectList(db.Product, "product_id", "productName", product_Order.product_id);
     return(View(product_Order));
 }
Example #10
0
        public async Task <IActionResult> Create([Bind("ProductId,OrderId,Quantity")] Product_Order product_Order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product_Order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "Id", "ClientName", product_Order.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", product_Order.ProductId);
            return(View(product_Order));
        }
Example #11
0
        // GET: Product_Order/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product_Order product_Order = db.Product_Order.Find(id);

            if (product_Order == null)
            {
                return(HttpNotFound());
            }
            return(View(product_Order));
        }
Example #12
0
        public ActionResult Create(string Address, string PostalCode, string PaymentMethod)
        {
            try
            {
                var cartProducts = (List <ProductsQuantity>)Session["cart"];

                //Calculates the total price of the cart
                double Price = 0;
                foreach (var po in cartProducts)
                {
                    Price = Price + po.Product.Price * po.Quantity;
                }

                //Creates the object order
                Orders order = new Orders
                {
                    Address       = Address,
                    OrderDate     = DateTime.Now,
                    PaymentMethod = PaymentMethod,
                    PostalCode    = PostalCode,
                    Status        = "Processing",
                    Details       = "Unused",
                    Price         = Price,
                    UserId        = User.Identity.GetUserId()
                };

                //Adds the created order to the Orders table
                var addedOrder = db.Orders.Add(order);

                //Creates the data in the table Product_Order, result of the N-M relation between products and order
                foreach (var po in cartProducts)
                {
                    Product_Order prd_ord = new Product_Order {
                        Orders = addedOrder, ProductFK = po.Product.ProductID, Quantity = po.Quantity
                    };
                    db.Product_Order.Add(prd_ord);
                }
                db.SaveChanges();

                //Resets the values of the cart so that the cart is empty again
                Session["cart"]      = null;
                Session["cartCount"] = 0;

                return(Redirect("~/Home/Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
 public PurchaseOrder(Product_Order obj)
 {
     InitializeComponent();
     if (obj == null)
     {
         btnUpdate.Enabled = false;
         txtPoID.Text = "Auto Generate";
     }
     else
     {
         btnNew.Enabled = false;
         btnSave.Enabled = false;
         productOrderBindingSource.DataSource = obj;
     }
 }
Example #14
0
        // GET: Product_Order/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product_Order product_Order = db.Product_Order.Find(id);

            if (product_Order == null)
            {
                return(HttpNotFound());
            }
            ViewBag.order_id   = new SelectList(db.Order, "order_id", "orderName", product_Order.order_id);
            ViewBag.product_id = new SelectList(db.Product, "product_id", "productName", product_Order.product_id);
            return(View(product_Order));
        }
Example #15
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product_Order = await _context.Product_Order
                            .Include(p => p.order)
                            .Include(p => p.product).FirstOrDefaultAsync(m => m.Order_id_order == id);

            if (Product_Order == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #16
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product_Order = await _context.Product_Order.FindAsync(id);

            if (Product_Order != null)
            {
                _context.Product_Order.Remove(Product_Order);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ms.AddPR(int.Parse(txtPEId.Text), int.Parse(txtQuantity.Text));
            purchaseReturnBindingSource.DataSource = cmd.Purchase_Return.ToList();

            Product_Order p = new Product_Order();

            using (cmd)
            {
                p                  = cmd.Product_Order.Where(x => x.PONo.ToString().Equals(txtPONo.Text)).FirstOrDefault();
                p.Quabtity         = p.Quabtity - (int.Parse(txtQuantity.Text));
                cmd.Entry(p).State = EntityState.Modified;
                cmd.SaveChanges();
            }
            MessageBox.Show("Succesfully Return");
            txtQuantity.Clear();
            load();
        }
Example #18
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product_Order = await _context.Product_Order
                            .Include(p => p.order)
                            .Include(p => p.product).FirstOrDefaultAsync(m => m.Order_id_order == id);

            if (Product_Order == null)
            {
                return(NotFound());
            }
            ViewData["Order_id_order"]     = new SelectList(_context.Order, "id_order", "id_order");
            ViewData["Product_id_product"] = new SelectList(_context.Product, "id_product", "name");
            return(Page());
        }
Example #19
0
        public static void InsertTransaction(Product_Order product_Order, SqlTransaction transaction, SqlConnection connection)
        {
            OperationsLogs.WriteLogsDebug("DetalleVentaDal", "Insertar", string.Format("{0} Info: {1}",
                                                                                       DateTime.Now.ToString(), "Empezando a ejecutar el metodo acceso a datos para crear un DetalleVenta"));

            SqlCommand command = null;

            //Consulta para insertar DetalleVentas
            string queryString = @"INSERT INTO DetalleVenta(idProducto, idPedido, cantidad, precioUnitario) 
                                    VALUES(@idProducto, @idPedido, @cantidad, @precioUnitario)";

            try
            {
                command = OperationsSql.CreateBasicCommandWithTransaction(queryString, transaction, connection);

                command.Parameters.AddWithValue("@idProducto", product_Order.IdProducto);
                command.Parameters.AddWithValue("@idPedido", product_Order.IdPedido);
                command.Parameters.AddWithValue("@cantidad", product_Order.Cantidad);
                command.Parameters.AddWithValue("@precioUnitario", product_Order.PrecioUnitario);

                OperationsSql.ExecuteBasicCommandWithTransaction(command);
            }
            catch (SqlException ex)
            {
                OperationsLogs.WriteLogsRelease("DetalleVentaDal", "Insertar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message));
                throw ex;
            }
            catch (Exception ex)
            {
                OperationsLogs.WriteLogsRelease("DetalleVentaDal", "Insertar", string.Format("{0} Error: {1}", DateTime.Now.ToString(), DateTime.Now.ToString(), ex.Message));
                throw ex;
            }

            OperationsLogs.WriteLogsDebug("DetalleVentaDal", "Insertar", string.Format("{0} Info: {1}",
                                                                                       DateTime.Now.ToString(), DateTime.Now.ToString(),
                                                                                       "Termino de ejecutar  el metodo acceso a datos para insertar DetalleVenta"));
        }
Example #20
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            bool valid = false;

            if (ddlProducts.SelectedItem.Value != "0")
            {
                long    prodID = long.Parse(ddlProducts.SelectedItem.Value);
                Product prod   = dde.Products.Find(prodID);
                bool    Invent = true;
                foreach (Product_Inventory inv in prod.Product_Inventory)
                {
                    Inventory i = dde.Inventories.Find(inv.Item_ID);
                    if (i.Quantity == 0)
                    {
                        Invent = false;
                    }
                }
                if (Invent)
                {
                    if (!cbGuest.Checked)
                    {
                        Customer cust = new Customer();
                        if (txtCustomer.Text.ToString().Trim() != "")
                        {
                            long id = long.Parse(txtCustomer.Text.ToString().Trim());
                            cust = dde.Customers.Find(id);
                            if (cust == null)
                            {
                                cust = dde.Customers.Where(t => t.Phone == id.ToString()).FirstOrDefault();
                                if (cust == null)
                                {
                                    cust = dde.Customers.Where(t => t.Reward_CardID == id.ToString()).FirstOrDefault();
                                }
                            }
                            order.Customer_ID = id;
                            if (tbQuantity.Text != "")
                            {
                                lblError.Text = "";
                                int quantity = int.Parse(tbQuantity.Text);
                                if (quantity > 0)
                                {
                                    bool dinein   = cbDineIn.Checked;
                                    bool carryout = cbCarryOut.Checked;
                                    int  count    = quantity;
                                    while (count != 0)
                                    {
                                        Product_Order pOrder = new Product_Order();
                                        pOrder.Product_ID = prod.Product_ID;
                                        order.Product_Order.Add(pOrder);
                                        count--;
                                    }
                                    order.Price            += prod.Price * quantity;
                                    lblSubTotal.Text        = String.Format("{0:C}", order.Price);
                                    lblTotal.Text           = String.Format("{0:C}", order.Price + (order.Price * 0.0675M));
                                    lvOrderItems.DataSource = order.Product_Order.GroupBy(t => t.Product_ID).ToList();
                                    lvOrderItems.DataBind();
                                    valid = true;
                                }
                                else
                                {
                                    lblError.Text = "Quantity must be greater than 0.";
                                }
                            }
                            else
                            {
                                lblError.Text = "Please select a quantity before trying to add to order.";
                            }
                        }
                        else
                        {
                            lblError.Text = "You must enter a customer or select guest.";
                        }
                    }
                    else
                    {
                        if (tbQuantity.Text != "")
                        {
                            lblError.Text = "";
                            int quantity = int.Parse(tbQuantity.Text);
                            if (quantity > 0)
                            {
                                bool dinein   = cbDineIn.Checked;
                                bool carryout = cbCarryOut.Checked;
                                int  count    = quantity;
                                while (count != 0)
                                {
                                    Product_Order pOrder = new Product_Order();
                                    pOrder.Product_ID = prod.Product_ID;
                                    order.Product_Order.Add(pOrder);
                                    count--;
                                }
                                order.Price            += prod.Price * quantity;
                                lblSubTotal.Text        = String.Format("{0:C}", order.Price);
                                lblTotal.Text           = String.Format("{0:C}", order.Price + (order.Price * 0.0675M));
                                lvOrderItems.DataSource = order.Product_Order.GroupBy(t => t.Product_ID).ToList();
                                lvOrderItems.DataBind();
                                valid = true;
                            }
                            else
                            {
                                lblError.Text = "Quantity must be greater than 0.";
                            }
                        }
                        else
                        {
                            lblError.Text = "Please select a quantity before trying to add to order.";
                        }
                    }
                }
            }
            else
            {
                lblError.Text = "Please select a product before trying to add to order.";
            }
            if (valid)
            {
                submitSide.Visible = true;
            }
        }
Example #21
0
        protected void btnSubmitOrder_Click(object sender, EventArgs e)
        {
            if (ModifyOrder)
            {
                order = dde.Orders.Find(order.Order_ID);
            }
            bool valid = false;

            if (ddlPromos.SelectedItem.Value != "0")
            {
                long      PromoID = long.Parse(ddlPromos.SelectedItem.Value);
                Promotion promo   = dde.Promotions.Find(PromoID);
                if (promo != null)
                {
                    if (promo.Discount_Type == "Percent Off")
                    {
                        if (promo.Discount != null)
                        {
                            order.Ord_Date = DateTime.Now;
                            order.Price    = ((order.Price + (order.Price * ((Decimal)promo.Discount / 100))) + (order.Price * 0.0675M));
                            if (!ModifyOrder)
                            {
                                dde.Orders.Add(order);
                            }
                            dde.SaveChanges();
                            valid = true;
                        }
                    }
                    else if (promo.Discount_Type == "Cash Off")
                    {
                        if (promo.Discount != null)
                        {
                            order.Ord_Date = DateTime.Now;
                            order.Price    = ((order.Price + (Decimal)promo.Discount) + (order.Price * 0.0675M));
                            if (!ModifyOrder)
                            {
                                dde.Orders.Add(order);
                            }
                            dde.SaveChanges();
                            valid = true;
                        }
                    }
                    else
                    {
                        Product_Order cheapestProd = order.Product_Order.Where(t => t.Product.Price > 0).OrderBy(t => t.Product.Price).FirstOrDefault();
                        if (cheapestProd != null)
                        {
                            order.Ord_Date = DateTime.Now;
                            order.Price    = ((order.Price - cheapestProd.Product.Price) + (order.Price * 0.0675M));
                            if (!ModifyOrder)
                            {
                                dde.Orders.Add(order);
                            }
                            dde.SaveChanges();
                            valid = true;
                        }
                    }
                }
            }
            else
            {
                order.Ord_Date = DateTime.Now;
                order.Price    = (order.Price + (order.Price * 0.0675M));
                if (!ModifyOrder)
                {
                    dde.Orders.Add(order);
                }
                dde.SaveChanges();
                valid = true;
            }
            if (valid)
            {
                if (!ModifyOrder)
                {
                    foreach (Product_Order prodOrder in order.Product_Order)
                    {
                        Product prods = dde.Products.Find(prodOrder.Product_ID);
                        foreach (Product_Inventory prodInv in prods.Product_Inventory)
                        {
                            Inventory inv = dde.Inventories.Find(prodInv.Item_ID);
                            inv.Quantity -= 1;
                            dde.SaveChanges();
                        }
                    }
                }
                else
                {
                    foreach (Product_Order prodOrder in deletedProducts)
                    {
                        Product prods = dde.Products.Find(prodOrder.Product_ID);
                        foreach (Product_Inventory prodInv in prods.Product_Inventory)
                        {
                            Inventory inv = dde.Inventories.Where(t => t.Item_ID == prodInv.Item_ID).Single();
                            inv.Quantity += 1;
                            dde.SaveChanges();
                        }
                    }
                }
                submitSide.Visible = false;
                ddlProducts.ClearSelection();
                ddlPromos.ClearSelection();
                lvOrderItems.DataSource = null;
                lvOrderItems.DataBind();
                tbQuantity.Text  = "";
                txtCustomer.Text = "";
                lblCustomer.Text = "";
                order            = new Order();
                ModifyOrder      = false;
                valid            = true;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "OpenModal('SuccessModal')", true);
            }
        }
Example #22
0
 public void Update(Product_Order oroduct_Order)
 {
     db.Entry(oroduct_Order).State = EntityState.Modified;
 }
Example #23
0
 public void Create(Product_Order oroduct_Order)
 {
     db.ProductOrders.Add(oroduct_Order);
 }