Exemplo n.º 1
0
        private void UpdateSelectedItemListAndRecalculateCosts()
        {
            //UPDATE THE LIST OF SELECTED ITEMS TO INCLUDE THE NEWLY ADDED ITEM VIA THE INTERFACE.
            IUpdateSelectedItemsList = NewCaseWindowReference;
            IUpdateSelectedItemsList.UpdateSelectedItemsList(StackOfSelectedItems);

            //RECALCULATE THE COST OF ALL THE SELECTED ITEMS VIA THE INTERFACE.
            ICalculateTotalSelectedItemsCost = NewCaseWindowReference;
            ICalculateTotalSelectedItemsCost.CalculateCostOfAllSelectedItems();
        }
Exemplo n.º 2
0
        private void CommonAddSelectedItem(object sender, MouseButtonEventArgs e)
        {
            string clickedItemRefNumber = "";

            if (sender is InventoryItem)
            {
                clickedItemRefNumber = ((InventoryItem)sender).RefNumber.ToString();
            }
            else if (sender is Button)
            {
                clickedItemRefNumber = ((Button)sender).Tag.ToString();
            }

            if (NewCaseWindowReference.SelectedItems.Children.Count > 0)
            {
                var childrenCount = NewCaseWindowReference.SelectedItems.Children.Count;
                var children      = NewCaseWindowReference.SelectedItems.Children;

                bool matchFound = false;

                //CHECK IF SELECTEDITEM ALREADY EXISTS.
                for (int i = 0; i < childrenCount; i++)
                {
                    SelectedItem childItem = (SelectedItem)children[i];

                    if (childItem.DeleteSelectedItemButton.Tag.ToString() == clickedItemRefNumber)
                    {
                        matchedChildItem = childItem;
                        matchFound       = true;
                    }
                }

                //IF ITEM ALREADY EXISTS, UPDATE ACCORDINGLY.
                if (matchFound)
                {
                    int    currentItemCount = int.Parse(matchedChildItem.ItemCount.Content.ToString());
                    Double currentItemCost  = Double.Parse(matchedChildItem.SelectedItemCost.Content.ToString());
                    Double baseCost         = currentItemCost / currentItemCount;

                    //Convert itemCount string to int, add 1, then convert back to string and set as new itemCount content.
                    matchedChildItem.ItemCount.Content = (currentItemCount + 1).ToString();

                    //Convert itemCost string to Double, multiply baseCost by itemCount, convert back to string and set as SelectedItemCost.content.
                    matchedChildItem.SelectedItemCost.Content = (baseCost * (currentItemCount + 1)).ToString();

                    //UPDATE THE LIST OF SELECTED ITEMS TO INCLUDE THE NEWLY ADDED ITEM VIA THE INTERFACE.
                    IUpdateSelectedItemsList = NewCaseWindowReference;
                    IUpdateSelectedItemsList.UpdateSelectedItemsList(StackOfSelectedItems);

                    //RECALCULATE THE COST OF ALL THE SELECTED ITEMS VIA THE INTERFACE.
                    ICalculateTotalSelectedItemsCost = NewCaseWindowReference;
                    ICalculateTotalSelectedItemsCost.CalculateCostOfAllSelectedItems();
                }
                else
                {
                    AddItemToSelectedItemsList(sender);
                }
            }
            else
            {
                AddItemToSelectedItemsList(sender);
            }
        }