コード例 #1
0
 public void UpdateContentInfo(IItemBundleInfo[] bundles)
 {
     // Update content info
     _contentCount.Clear();
     // Update item-count information
     foreach (var item in bundles)
     {
         if (!_contentCount.ContainsKey(item.GetInfoItemDescription()))
         {
             _contentCount[item.GetInfoItemDescription()] = item.GetInfoItemCount();
         }
         else
         {
             _contentCount[item.GetInfoItemDescription()] += item.GetInfoItemCount();
         }
     }
     // Update the visual controls
     foreach (var item in bundles)
     {
         // Check whether it is a new item
         if (!_blocksContent.ContainsKey(item.GetInfoItemDescription()))
         {
             // New item - init visual control
             TextBlock textBlock = new TextBlock()
             {
                 Padding = new Thickness(3), FontFamily = VisualizationConstants.ItemFont
             };
             if (item.GetInfoItemDescription() is IColoredLetterDescriptionInfo)
             {
                 IColoredLetterDescriptionInfo itemDescription = item.GetInfoItemDescription() as IColoredLetterDescriptionInfo;
                 textBlock.Background = VisualizationConstants.LetterColorBackgroundBrushes[itemDescription.GetInfoColor()];
                 textBlock.Foreground = VisualizationConstants.LetterColorComplete;
                 textBlock.Text       = itemDescription.GetInfoLetter() + "/" + _contentCount[itemDescription];
             }
             else
             {
                 if (item.GetInfoItemDescription() is ISimpleItemDescriptionInfo)
                 {
                     ISimpleItemDescriptionInfo itemDescription = item.GetInfoItemDescription() as ISimpleItemDescriptionInfo;
                     textBlock.Background = ColorManager.GenerateHueBrush(itemDescription.GetInfoHue());
                     textBlock.Foreground = VisualizationConstants.SimpleItemColorComplete;
                     textBlock.Text       =
                         (itemDescription.GetInfoID().ToString() + "(" + _contentCount[itemDescription] + ")").PadBoth(VisualizationConstants.SIMPLE_ITEM_BUNDLE_MIN_CHAR_COUNT);
                 }
                 else
                 {
                     textBlock.Text = item.GetInfoItemDescription().GetInfoDescription();
                 }
             }
             // Add the control
             _blocksContent[item.GetInfoItemDescription()] = textBlock;
             _contentHost.Items.Add(textBlock);
         }
         else
         {
             // Visual control already exists - grab and update it
             if (item.GetInfoItemDescription() is IColoredLetterDescriptionInfo)
             {
                 IColoredLetterDescriptionInfo itemDescription = item.GetInfoItemDescription() as IColoredLetterDescriptionInfo;
                 _blocksContent[item.GetInfoItemDescription()].Text = itemDescription.GetInfoLetter() + "/" + _contentCount[itemDescription];
             }
             else
             {
                 if (item.GetInfoItemDescription() is ISimpleItemDescriptionInfo)
                 {
                     ISimpleItemDescriptionInfo itemDescription = item.GetInfoItemDescription() as ISimpleItemDescriptionInfo;
                     _blocksContent[item.GetInfoItemDescription()].Text =
                         (itemDescription.GetInfoID().ToString() + "(" + _contentCount[itemDescription] + ")").PadBoth(VisualizationConstants.SIMPLE_ITEM_BUNDLE_MIN_CHAR_COUNT);
                 }
                 else
                 {
                     _blocksContent[item.GetInfoItemDescription()].Text = item.GetInfoItemDescription().GetInfoDescription();
                 }
             }
         }
     }
     // Remove controls showing items not present in the pod anymore
     foreach (var itemDescription in _blocksContent.Keys.Except(bundles.Select(b => b.GetInfoItemDescription())).ToArray())
     {
         _contentHost.Items.Remove(_blocksContent[itemDescription]);
         _blocksContent.Remove(itemDescription);
     }
 }
コード例 #2
0
 public void UpdateContentInfo()
 {
     // Update the visual controls
     foreach (var item in _pod.GetInfoInstance().GetInfoItemDescriptions())
     {
         // Check whether the item is contained in the pod
         if (_pod.GetInfoContent(item) > 0)
         {
             // Check whether it is a new item
             if (!_blocksContent.ContainsKey(item))
             {
                 // New item - init visual control
                 TextBlock textBlock = new TextBlock()
                 {
                     Padding = new Thickness(3), FontFamily = VisualizationConstants.ItemFont
                 };
                 if (item is IColoredLetterDescriptionInfo)
                 {
                     IColoredLetterDescriptionInfo itemDescription = item as IColoredLetterDescriptionInfo;
                     textBlock.Background = VisualizationConstants.LetterColorBackgroundBrushes[itemDescription.GetInfoColor()];
                     textBlock.Foreground = VisualizationConstants.LetterColorComplete;
                     textBlock.Text       = itemDescription.GetInfoLetter() + "/" + _pod.GetInfoContent(itemDescription);
                 }
                 else
                 {
                     if (item is ISimpleItemDescriptionInfo)
                     {
                         ISimpleItemDescriptionInfo itemDescription = item as ISimpleItemDescriptionInfo;
                         textBlock.Background = ColorManager.GenerateHueBrush(itemDescription.GetInfoHue());
                         textBlock.Foreground = VisualizationConstants.SimpleItemColorComplete;
                         textBlock.Text       =
                             (itemDescription.GetInfoID().ToString() + "(" + _pod.GetInfoContent(itemDescription) + ")").PadBoth(VisualizationConstants.SIMPLE_ITEM_BUNDLE_MIN_CHAR_COUNT);
                     }
                     else
                     {
                         textBlock.Text = item.GetInfoDescription();
                     }
                 }
                 // Add the control
                 _blocksContent[item] = textBlock;
                 _contentHost.Items.Add(textBlock);
             }
             else
             {
                 // Visual control already exists - grab and update it
                 if (item is IColoredLetterDescriptionInfo)
                 {
                     IColoredLetterDescriptionInfo itemDescription = item as IColoredLetterDescriptionInfo;
                     _blocksContent[item].Text = itemDescription.GetInfoLetter() + "/" + _pod.GetInfoContent(itemDescription);
                 }
                 else
                 {
                     if (item is ISimpleItemDescriptionInfo)
                     {
                         ISimpleItemDescriptionInfo itemDescription = item as ISimpleItemDescriptionInfo;
                         _blocksContent[item].Text =
                             (itemDescription.GetInfoID().ToString() + "(" + _pod.GetInfoContent(itemDescription) + ")").PadBoth(VisualizationConstants.SIMPLE_ITEM_BUNDLE_MIN_CHAR_COUNT);
                     }
                     else
                     {
                         _blocksContent[item].Text = item.GetInfoDescription();
                     }
                 }
             }
         }
     }
     // Remove controls showing items not present in the pod anymore
     foreach (var item in _pod.GetInfoInstance().GetInfoItemDescriptions())
     {
         if (_pod.GetInfoContent(item) <= 0 && _blocksContent.ContainsKey(item))
         {
             _contentHost.Items.Remove(_blocksContent[item]);
             _blocksContent.Remove(item);
         }
     }
 }
コード例 #3
0
        public void Update(IEnumerable <IOrderInfo> openOrders, IEnumerable <IOrderInfo> completedOrders)
        {
            // Add new controls for the orders
            foreach (var order in openOrders.Concat(completedOrders))
            {
                // Check whether a control for this order is already available
                if (!_orderStatusOpen.ContainsKey(order))
                {
                    // Create a container for this order
                    _orderControls[order] = new WrapPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    RootOpenOrders.Items.Add(_orderControls[order]);
                    // Create the controls for every element of the order
                    _itemControls[order] = new Dictionary <IItemDescriptionInfo, TextBlock>();
                    foreach (var position in order.GetInfoPositions())
                    {
                        TextBlock positionBlock = new TextBlock()
                        {
                            Padding = new Thickness(3), FontFamily = VisualizationConstants.ItemFont
                        };
                        if (position is IColoredLetterDescriptionInfo)
                        {
                            IColoredLetterDescriptionInfo itemDescription = position as IColoredLetterDescriptionInfo;
                            positionBlock.Background = VisualizationConstants.LetterColorBackgroundBrushes[itemDescription.GetInfoColor()];
                            positionBlock.Foreground = VisualizationConstants.LetterColorIncomplete;
                            positionBlock.Text       = itemDescription.GetInfoLetter() + "(0/" + order.GetInfoDemandCount(position) + ")";
                        }
                        else
                        {
                            if (position is ISimpleItemDescriptionInfo)
                            {
                                ISimpleItemDescriptionInfo itemDescription = position as ISimpleItemDescriptionInfo;
                                positionBlock.Background = ColorManager.GenerateHueBrush(itemDescription.GetInfoHue());
                                positionBlock.Foreground = VisualizationConstants.SimpleItemColorIncomplete;
                                positionBlock.Text       = (itemDescription.GetInfoID().ToString() + "(0/" + order.GetInfoDemandCount(position) + ")").PadLeft(VisualizationConstants.SIMPLE_ITEM_ORDER_MIN_CHAR_COUNT);
                            }
                            else
                            {
                                positionBlock.Text = position.GetInfoDescription() + "(0/" + order.GetInfoDemandCount(position) + ")";
                            }
                        }
                        _itemControls[order][position] = positionBlock;
                        _orderControls[order].Children.Add(positionBlock);
                    }
                    // Add the order to the list and mark it as open
                    _openOrders.Add(order);
                    _openOrderCount++;
                    _orderStatusOpen[order] = true;
                }
            }

            // Update served quantities of existing orders
            foreach (var order in _openOrders)
            {
                // Refresh order status
                if (order.GetInfoIsCompleted())
                {
                    _orderStatusOpen[order] = false;
                }

                // Update all positions
                foreach (var position in order.GetInfoPositions())
                {
                    if (position is IColoredLetterDescriptionInfo)
                    {
                        // Update the position's text (use the coloring too)
                        IColoredLetterDescriptionInfo itemDescription = position as IColoredLetterDescriptionInfo;
                        _itemControls[order][position].Text = itemDescription.GetInfoLetter() + "(" + order.GetInfoServedCount(position).ToString() + "/" + order.GetInfoDemandCount(position).ToString() + ")";
                    }
                    else
                    {
                        if (position is ISimpleItemDescriptionInfo)
                        {
                            // Update the position's text (use the coloring too)
                            ISimpleItemDescriptionInfo itemDescription = position as ISimpleItemDescriptionInfo;
                            _itemControls[order][position].Text =
                                (itemDescription.GetInfoID().ToString() + "(" + order.GetInfoServedCount(position).ToString() + "/" + order.GetInfoDemandCount(position).ToString() + ")")
                                .PadLeft(VisualizationConstants.SIMPLE_ITEM_ORDER_MIN_CHAR_COUNT);
                        }
                        else
                        {
                            // Update the position's text
                            _itemControls[order][position].Text = position.GetInfoDescription() + "(" + order.GetInfoServedCount(position).ToString() + "/" + order.GetInfoDemandCount(position).ToString() + ")";
                        }
                    }
                    // Set color according to completed position
                    _itemControls[order][position].Foreground =
                        order.GetInfoServedCount(position) == order.GetInfoDemandCount(position) ? // Check whether position is complete
                        VisualizationConstants.LetterColorComplete :                               // Completed the position
                        VisualizationConstants.LetterColorIncomplete;                              // Position is incomplete
                }
            }

            // Move newly completed orders from open to complete node
            foreach (var order in _openOrders.Where(o => !_orderStatusOpen[o]).ToList())
            {
                _openOrders.Remove(order);
                _completedOrders.Add(order);
                RootOpenOrders.Items.Remove(_orderControls[order]);
                RootCompletedOrders.Items.Insert(0, _orderControls[order]);
                _openOrderCount--;
                _completedOrderCount++;
            }

            // Remove completed orders if list gets too long
            if (_completedOrders.Count > _orderCount)
            {
                // Manage the list of the currently displayed orders
                List <IOrderInfo> removedOrders = _completedOrders.Take(_completedOrders.Count - _orderCount).ToList();
                _droppedOrders.AddRange(removedOrders);
                _completedOrders.RemoveRange(0, _completedOrders.Count - _orderCount);
                foreach (var removedOrder in removedOrders)
                {
                    RootCompletedOrders.Items.Remove(_orderControls[removedOrder]);
                }
                // Remove the controls
                foreach (var removedOrder in removedOrders)
                {
                    foreach (var position in removedOrder.GetInfoPositions())
                    {
                        _itemControls[removedOrder].Remove(position);
                    }
                    _itemControls.Remove(removedOrder);
                    _orderControls.Remove(removedOrder);
                }
            }

            // Update order count info
            RootOpenOrders.Header      = _headerOpenOrders + " (" + _openOrderCount + ")";
            RootCompletedOrders.Header = _headerCompletedOrders + " (" + Math.Min(_orderCount, _completedOrderCount) + "/" + _completedOrderCount + ")";
        }