protected void DeleteOrderItemLineButton_Command(object sender, CommandEventArgs e)
    {
        int currentEditIndex = OrderDetailsGridView.EditIndex;

        if (currentEditIndex >= 0 && ((CheckBox)OrderDetailsGridView.Rows[currentEditIndex].FindControl("SelectedCheckBox")).Checked == false)
        {
            UpdateRowIfInEditMode();
        }

        List <OrderItemLine> linesToDelete = new List <OrderItemLine>();

        foreach (GridViewRow row in OrderDetailsGridView.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox selectedCheckBox = (CheckBox)row.FindControl("SelectedCheckBox");
                if (selectedCheckBox != null && selectedCheckBox.Checked)
                {
                    OrderItemLine orderItemLine = OrderItemsLines[row.DataItemIndex];
                    linesToDelete.Add(orderItemLine);
                }
            }
        }
        if (linesToDelete.Count > 0)
        {
            _presenter.OnDeleteOrderItemLines(linesToDelete);
        }
        //SetLastRowToEditMode();
        OrderDetailsGridView.EditIndex = -1;
    }
Example #2
0
        public void ShouldUpdateItemTotalAndOrderTotalOnOrderItemLineChanged()
        {
            decimal?price = 1.99m;

            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            productService.AddProduct(new Product(2, "9876-54321", "Stencil Pad", 0.79m, null));

            //Total set to 0, so it can be updated by the presenter.
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", price, 10, 0m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            short         newQty      = 20;
            OrderItemLine lineUpdated = new OrderItemLine(1, line1.Sku, line1.Name, line1.Price, newQty, 0, false);

            lineUpdated.Id = line1.Id;

            presenter.OnChangedOrderItemLine(lineUpdated);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(newQty, view.OrderItemsLines[0].Quantity);
            Assert.AreEqual(price * newQty, view.OrderItemsLines[0].Total);
            Assert.AreEqual(line1.Total + line2.Total, view.OrderTotalPrice);
        }
Example #3
0
        public bool IsSkuValid(string sku, out string errorMessage)
        {
            if (string.IsNullOrEmpty(sku))
            {
                errorMessage = Resources.ErrorEmptySku;
                return(false);
            }
            OrderItemLine        line  = (View.EditingOrderItemLine ?? (new OrderItemLine()));
            List <OrderItemLine> lines = new List <OrderItemLine>(View.OrderItemsLines);
            bool skuAlreadyExists      = SkuAlreadyEntered(sku, lines, line);

            if (skuAlreadyExists)
            {
                errorMessage = Resources.ErrorRepeatedSku;
                return(false);
            }

            Product product = _productService.GetProductBySku(sku);

            if (product == null)
            {
                errorMessage = Resources.ErrorInvalidSku;
                return(false);
            }
            else
            {
                errorMessage = string.Empty;
                return(true);
            }
        }
        /// <summary>
        /// NAME: Jesse Tomash
        /// DATE: 4/26/2020
        ///
        /// Approver: Brandyn T. Coverdill
        ///
        /// Inserts a new Order-Item Line
        /// </summary>
        /// <remarks>
        /// UPDATED BY:
        /// UPDATE DATE:
        /// WHAT WAS CHANGED:
        /// <returns>1 if successful, 0 if not</returns>
        public bool InsertOrderItemLine(OrderItemLine newLine)
        {
            bool isInserted = false;

            var conn = DBConnection.GetConnection();

            var cmdText = @"sp_insert_order_item_line";
            var cmd     = new SqlCommand(cmdText, conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@OrderID", newLine.OrderID);
            cmd.Parameters.AddWithValue("@ItemID", newLine.ItemID);
            cmd.Parameters.AddWithValue("@Quantity", newLine.Quantity);

            try
            {
                conn.Open();
                isInserted = 1 == cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(isInserted);
        }
Example #5
0
        public void OnAddOrderItemLine()
        {
            IList <OrderItemLine> lines   = View.OrderItemsLines;
            OrderItemLine         newLine = new OrderItemLine();

            newLine.Quantity = 1;
            lines.Add(newLine);
            View.ShowOrderItemLines(lines);
        }
Example #6
0
        /// <summary>
        /// NAME: Jesse Tomash
        /// DATE: 4/26/2020
        ///
        /// Approver:
        /// Approver:
        ///
        /// Action on item click to add item to order and create order line
        /// </summary>
        /// /// <remarks>
        /// UPDATED BY: Brandyn T. Coverdill
        /// UPDATE DATE: 4/28/2020
        /// WHAT WAS CHANGED: When the user clicks add item for the order, it makes the quantity empty.
        /// </remarks>
        /// <returns></returns>
        private void btnAddOrderItem_Click(object sender, RoutedEventArgs e)
        {
            if (dgItems.SelectedItem == null)
            {
                "You must have an item selected.".ErrorMessage();
            }
            if (txtQty == null || txtQty.Text == "0")
            {
                "You must enter a quantity".ErrorMessage();
            }
            else
            {
                try
                {
                    Int32.Parse(txtQty.Text);
                    if (Int32.Parse(txtQty.Text) < 20)
                    {
                        try
                        {
                            _item          = (Item)dgItems.SelectedItem;
                            _orderItemLine = new OrderItemLine
                            {
                                OrderID  = _order.OrderID,
                                ItemID   = _item.ItemID,
                                Quantity = Int32.Parse(txtQty.Text)
                            };

                            _orderItemLineManager.AddOrderItemLine(_orderItemLine);

                            // After the item has been added to the OrderItem Datagrid, remove it from the item datagrid.
                            Item item = new Item();
                            item = _item;
                            item.ItemQuantity = Int32.Parse(txtQty.Text);
                            _orderItems.Add(item);
                            dgItems.Items.Refresh();
                            dgOrderItems.Items.Refresh();
                        }
                        catch
                        {
                            "Could not Add Item to Order".ErrorMessage();
                        }
                    }
                    else
                    {
                        "Cannot be greater than 20".ErrorMessage();
                    }
                }
                catch
                {
                    "Not a number".ErrorMessage();
                }
                txtQty.Text = "";
            }
        }
Example #7
0
        public void OnShowOrder(Order order)
        {
            OrderInfo            orderInfo = _ordersConverter.ConvertBusinessToPresentation(order);
            List <OrderItemLine> lines     = new List <OrderItemLine>();

            foreach (OrderDetail detail in order.Details)
            {
                OrderItemLine orderItemLine = _orderDetailsConverter.ConvertBusinessToPresentation(detail);
                lines.Add(orderItemLine);
            }
            View.ShowOrderInfo(orderInfo, lines);
        }
Example #8
0
        public void RepeatedSkuIsNotValid()
        {
            string        sku   = "1234-56789";
            OrderItemLine line1 = new OrderItemLine(1, sku, "#2 Pencil Pack", 1.99m, 10, 19.9m, false);

            view.OrderItemsLines.Add(line1);

            string errorMessage = string.Empty;

            Assert.IsFalse(presenter.IsSkuValid(sku, out errorMessage));
            Assert.IsFalse(string.IsNullOrEmpty(errorMessage));
        }
Example #9
0
        public void ShouldDeleteAndShowRemainingOrderItemLinesOnDelete()
        {
            List <OrderItemLine> lines         = new List <OrderItemLine>();
            OrderItemLine        orderItemLine = new OrderItemLine();

            view.OrderItemsLines.Add(orderItemLine);
            lines.Add(orderItemLine);

            presenter.OnDeleteOrderItemLines(lines);

            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(0, view.OrderItemsLines.Count);
        }
Example #10
0
        public override void OnViewInitialized()
        {
            ICollection <OrderDetail> details = _controller.CurrentOrder.Details;
            List <OrderItemLine>      lines   = new List <OrderItemLine>();

            foreach (OrderDetail detail in details)
            {
                OrderItemLine orderItemLine = _orderDetailsConverter.ConvertBusinessToPresentation(detail);
                UpdateOrderLineTotalPrice(orderItemLine);
                lines.Add(orderItemLine);
            }
            View.ShowOrderItemLines(lines);
        }
Example #11
0
        public void ShouldUpdateProductPriceOnChangeOrderItemLine()
        {
            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            decimal       fakePrice = 0.01m;
            OrderItemLine line1     = new OrderItemLine(1, "1234-56789", "Fake product name", fakePrice, 10, 0m, false);

            view.OrderItemsLines.Add(line1);

            presenter.OnChangedOrderItemLine(line1);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(1.99m, view.OrderItemsLines[0].Price);
            Assert.AreEqual("#2 Pencil Pack", view.OrderItemsLines[0].Name);
        }
Example #12
0
        public void ShouldNotUpdateOrderItemSkuOnNullProductSelected()
        {
            view.OrderItemsLines = new List <OrderItemLine>();
            productService.AddProduct(new Product(1, "1234-56789", "#2 Pencil Pack", 1.99m, null));
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.EditingOrderItemLine = line1;

            presenter.OnProductSelected(null);

            Assert.IsFalse(view.SetEditingProductCalled);
        }
Example #13
0
        /// <summary>
        /// NAME: Jesse Tomash
        /// DATE: 4/26/2020
        ///
        /// Approver: Brandyn T. Coverdill
        ///
        /// This is the method that handles logic between InsertOrderitemline() and the presentation
        /// </summary>
        /// <remarks>
        /// UPDATED BY:
        /// UPDATE DATE:
        /// WHAT WAS CHANGED:
        /// </remarks>
        /// <param name="newLine"></param>
        /// <returns></returns>
        public bool AddOrderItemLine(OrderItemLine newLine)
        {
            bool result;

            try
            {
                result = _orderItemLineAccessor.InsertOrderItemLine(newLine);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Example #14
0
        public void ShouldSubmitOrderItemsToControllerOnSave()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            presenter.OnSave();

            Assert.IsTrue(controller.SaveCurrentOrderAsDraftCalled);
            Assert.AreEqual(2, controller.CurrentOrder.Details.Count);
            Assert.AreEqual(1, controller.CurrentOrder.Details[0].ProductId);
            Assert.AreEqual(2, controller.CurrentOrder.Details[1].ProductId);
        }
Example #15
0
        public void NotUsedSkuIsValid()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);

            view.OrderItemsLines.Add(line1);

            Product product = new Product(1, "9876-54321", "#2 Pencil Pack", 1.99m, "#2 Pencil Pack");

            productService.AddProduct(product);

            string errorMessage = string.Empty;

            Assert.IsTrue(presenter.IsSkuValid("9876-54321", out errorMessage));
            Assert.IsTrue(string.IsNullOrEmpty(errorMessage));
        }
Example #16
0
        public void ShouldIgnoreInvalidOrderItemsWhenPassingToControllerOnSave()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", null, 10, 7.9m, false);            //Invalid, no UnitPrice
            OrderItemLine line3 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 0, 7.9m, false);             //Invalid, quantity is zero

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.OrderItemsLines.Add(line3);

            presenter.OnSave();

            Assert.AreEqual(1, controller.CurrentOrder.Details.Count);
            Assert.AreEqual(1, controller.CurrentOrder.Details[0].ProductId);
        }
Example #17
0
        public void ShouldMaintainSelectedValueWhenEditingOrderLine()
        {
            view.OrderItemsLines = new List <OrderItemLine>();
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            bool selectedValue = true;
            int  rowIndex      = 1;

            presenter.OnEditOrderItemLine(rowIndex, selectedValue);

            Assert.IsTrue(view.OrderItemsLinesRequested);
            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(selectedValue, view.OrderItemsLines[rowIndex].Selected);
        }
Example #18
0
        public void ShouldDeleteCorrectOrderLinesOnDelete()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.90m, false);
            OrderItemLine line2 = new OrderItemLine(2, "9876-54321", "Stencil Pad", .79m, 10, 7.9m, false);
            OrderItemLine line3 = new OrderItemLine(3, "4356-43239", "#6 Pencil Pack", 1.99m, 10, 19.90m, false);

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);
            view.OrderItemsLines.Add(line3);

            List <OrderItemLine> lines = new List <OrderItemLine>();

            lines.Add(line1);
            lines.Add(line3);

            presenter.OnDeleteOrderItemLines(lines);

            Assert.IsTrue(view.OrderItemsLinesShown);
            Assert.AreEqual(1, view.OrderItemsLines.Count);
            Assert.AreEqual(line2, view.OrderItemsLines[0]);
        }
Example #19
0
        public void AddingLineWithAlreadyExistingSkuWillSetItBackToEmpty()
        {
            OrderItemLine line1 = new OrderItemLine(1, "1234-56789", "#2 Pencil Pack", 1.99m, 10, 19.9m, false);
            OrderItemLine line2 = new OrderItemLine();

            view.OrderItemsLines.Add(line1);
            view.OrderItemsLines.Add(line2);

            OrderItemLine newLine2 = new OrderItemLine(1, "1234-56789", null, null, 2, null, false);

            newLine2.Id = line2.Id;
            presenter.OnChangedOrderItemLine(newLine2);

            Assert.AreEqual(2, view.OrderItemsLines.Count);
            OrderItemLine updatedLine = view.OrderItemsLines[1];

            Assert.AreEqual(line2.Id, updatedLine.Id);
            Assert.IsTrue(String.IsNullOrEmpty(updatedLine.Sku));
            Assert.IsTrue(String.IsNullOrEmpty(updatedLine.Name));
            Assert.IsNull(updatedLine.Price);
            Assert.IsFalse(updatedLine.ProductId > 0);
        }
Example #20
0
        public void OnChangedOrderItemLine(OrderItemLine orderItemLine)
        {
            List <OrderItemLine> lines = new List <OrderItemLine>(View.OrderItemsLines);

            OrderItemLine line = lines.Find(delegate(OrderItemLine order)
            {
                return(order.Equals(orderItemLine));
            });

            line.Sku = orderItemLine.Sku;
            if (line.Sku != null)
            {
                bool skuAlreadyEntered = SkuAlreadyEntered(orderItemLine.Sku, lines, line);

                if (skuAlreadyEntered)
                {
                    line.Sku   = null;
                    line.Name  = null;
                    line.Price = null;
                }
                else
                {
                    Product product = _productService.GetProductBySku(line.Sku);
                    if (product != null)
                    {
                        line.ProductId = product.ProductId;
                        line.Name      = product.ProductName;
                        line.Price     = product.UnitPrice;
                    }
                }
            }
            line.Quantity = orderItemLine.Quantity;
            UpdateOrderLineTotalPrice(line);

            View.ShowOrderItemLines(lines);
            UpdateTotalPrice();
        }
Example #21
0
 private static void UpdateOrderLineTotalPrice(OrderItemLine line)
 {
     line.Total = line.Price * line.Quantity;
 }
Example #22
0
        private static bool SkuAlreadyEntered(string sku, List <OrderItemLine> lines, OrderItemLine editingLine)
        {
            bool skuAlreadyExists = lines.Exists(delegate(OrderItemLine order)
            {
                return(!order.Equals(editingLine) && sku.Equals(order.Sku, StringComparison.InvariantCultureIgnoreCase));
            }
                                                 );

            return(skuAlreadyExists);
        }