private List <TradingPartner> LoadTradingPartners(List <Orders> orders)
        {
            var tradingPartnerIds = orders
                                    .SelectMany(x => x.Order)
                                    .Select(y => y.Header.OrderHeader.TradingPartnerId)
                                    .Distinct();
            var allOrders       = orders.SelectMany(x => x.Order);
            var tradingPartners = new List <TradingPartner>();

            foreach (var id in tradingPartnerIds)
            {
                var tpOrders       = allOrders.Where(x => x.Header.OrderHeader.TradingPartnerId == id);
                var tradingPartner = new TradingPartner()
                {
                    TradingPartnerId = id,
                    ViewOrders       = tpOrders.Select(XmlOrderToViewOrder).ToList()
                };
                tradingPartners.Add(tradingPartner);
            }
            foreach (var tp in tradingPartners)
            {
                tp.TotalAmount    = tp.ViewOrders.SelectMany(x => x.LineItems).Sum(y => y.OrderQty * y.PurchasePrice);
                tp.TotalLineItems = tp.ViewOrders.SelectMany(x => x.LineItems).Count();
            }
            return(tradingPartners);
        }
Esempio n. 2
0
    LoadSessionTradingPrtNrVM TransformToVM(LoadSession inputA, TradingPartner inputB)
    {
        LoadSessionTradingPrtNrVM newOBJ = new LoadSessioNTradingPrtNrVM();

        newOBJ.LoadSessionId = ipnutA.LoadSessionID;
        newOBJ.Import        = inputA.Import
                               //Here is the property from your Transform object
                               newOBJ.Description = inputB.Description
                               //...  Continue to transform one object into the other...
                               //You could add as many members from as many different objects as you want into
                               //Your view model following that pattern.
    }
Esempio n. 3
0
        public TradeWindow(Vector2 v2Center, int width, VariableBundle leftTrader, VariableBundle rightTrader, TradingPartner partner, int unlocks, string leftTraderString, string rightTraderString)
            : base(v2Center, IntoTheNewWorld.Instance)
        {
            this.bounds = new Rectangle(this.bounds.X, this.bounds.Y, width, this.bounds.Height);

            this.leftTrader = leftTrader;
            this.rightTrader = rightTrader;
            _partner = partner;
            _unlocks = unlocks;
            _leftTraderString = leftTraderString;
            _rightTraderString = rightTraderString;

            _dictValueByTradeItem = getAcceptedTradeItems();

            List<string> leftTradeItems = this.leftTrader.variables.Where(variable => (this.leftTrader.getValue<int>(variable) > 0) && _dictValueByTradeItem.ContainsKey(variable)).ToList();
            List<string> rightTradeItems = this.rightTrader.variables.Where(variable => (this.rightTrader.getValue<int>(variable) > 0) && _dictValueByTradeItem.ContainsKey(variable)).ToList();

            // The list of items that can be traded is the union of the two traders' pile of items to trade.
            //_tradeItems = this.leftTrader.variables.Union(this.rightTrader.variables).Distinct().ToList();
            _tradeItems = leftTradeItems.Union(rightTradeItems).Distinct().ToList();

            _dictIndexByTradeItem = new Dictionary<string, int>();
            for (int i = 0; i < _tradeItems.Count; i++)
                _dictIndexByTradeItem.Add(_tradeItems[i], i);

            _offsets = new List<int>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _offsets.Add(0));

            _values = new List<int>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _values.Add(1));
            for (int i = 0; i < _tradeItems.Count; i++)
                _values[i] = _dictValueByTradeItem[_tradeItems[i]];

            //_sums = new List<int>(_tradeItems.Count);
            //foreach (string tradeItem in _tradeItems)
            //{
            //    int sum = 0;
            //    int val;
            //    if (leftTrader.getValue(tradeItem, out val))
            //        sum += val;
            //    if (rightTrader.getValue(tradeItem, out val))
            //        sum += val;
            //    _sums.Add(sum);
            //}

            //_tradeItemHotspots = new List<Rectangle>(_tradeItems.Count);
            //_tradeItems.ForEach(ti => _tradeItemHotspots.Add(new Rectangle(0, 0, 0, 0)));

            Graphic gArrowLtRTail = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_tail"];
            Graphic gArrowLtRBody = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_body"];
            Graphic gArrowLtRHead = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_head"];
            _arrowLtR = new Arrow(gArrowLtRTail, gArrowLtRBody, gArrowLtRHead);

            Graphic gArrowRtLTail = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_tail"];
            Graphic gArrowRtLBody = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_body"];
            Graphic gArrowRtLHead = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_head"];
            _arrowRtL = new Arrow(gArrowRtLTail, gArrowRtLBody, gArrowRtLHead);

            _lockedLeft = new List<LockedState>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _lockedLeft.Add(LockedState.None));
            _lockedRight = new List<LockedState>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _lockedRight.Add(LockedState.None));
            _desired = new List<bool>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _desired.Add(false));
            _undesired = new List<bool>(_tradeItems.Count);
            _tradeItems.ForEach(ti => _undesired.Add(false));

            if (isAIPartner())
                initializeAIState();

            initializeButtons();
            initializeHotspots();

            _textHeight = (int)_font.MeasureString("1").Y;

            int height = _itemsTop + _tradeItems.Count * (gArrowLtRBody.defaultBounds.Height + _itemsYBuffer + _textHeight) + _itemsBottom + _buttonOK.bounds.Height + this.buttonBottomBuffer;
            this.bounds = new Rectangle(this.bounds.X, this.bounds.Y, this.bounds.Width, height);
        }