Exemplo n.º 1
0
        public static OrdersList LoadOrders(List<AssetAccessParams> accessParams, List<int> itemIDs,
            List<long> stationIDs, int state, string type)
        {
            OrdersList retVal = new OrdersList();
            EMMADataSet.OrdersDataTable table = LoadOrdersData(accessParams, itemIDs, stationIDs, state, type);

            foreach (EMMADataSet.OrdersRow row in table)
            {
                Order order = new Order(row, accessParams);
                retVal.Add(order);
            }
            return retVal;
        }
        private void UpdateOrders()
        {
            try
            {
                // Retrieve data
                _buyOrders = Orders.LoadOrders(_assetParams, _itemIDs, new List<long>(), (int)OrderState.Active, "buy");
                _sellOrders = Orders.LoadOrders(_assetParams, _itemIDs, new List<long>(), (int)OrderState.Active, "sell");

                // Now add placeholder rows for item/owner combos that do not exist in the retrieved data.
                if (_orderPlaceholderType != OrderPlaceholderType.None)
                {
                    foreach (object itemObj in chkItems.CheckedItems)
                    {
                        int maxOwner = _orderPlaceholderType == OrderPlaceholderType.PerItem ? 1 : chkOwners.CheckedItems.Count;

                        for(int currentOwnerIndex = 0; currentOwnerIndex < maxOwner; currentOwnerIndex++)
                        {
                            object ownerObj = chkOwners.CheckedItems[currentOwnerIndex];
                            CharCorpOption owner = (CharCorpOption)ownerObj;
                            long ownerID = owner.Data.ID;
                            int itemID = ((ItemInfo)itemObj).ID;

                            _buyOrders.ItemFilter = "ItemID = " + itemID;
                            if (_orderPlaceholderType == OrderPlaceholderType.PerItemPerEntity)
                            {
                                _buyOrders.ItemFilter = _buyOrders.ItemFilter + " AND OwnerID = " + ownerID;
                            }
                            if (_buyOrders.FiltredItems.Count == 0)
                            {
                                _buyOrders.Add(new Order(ownerID, itemID, true, _assetParams));
                            }

                            _sellOrders.ItemFilter = "ItemID = " + itemID;
                            if (_orderPlaceholderType == OrderPlaceholderType.PerItemPerEntity)
                            {
                                _sellOrders.ItemFilter = _sellOrders.ItemFilter + " AND OwnerID = " + ownerID;
                            }
                            if (_sellOrders.FiltredItems.Count == 0)
                            {
                                _sellOrders.Add(new Order(ownerID, itemID, false, _assetParams));
                            }
                        }
                    }
                    _buyOrders.ItemFilter = "";
                    _sellOrders.ItemFilter = "";
                }
                foreach (object itemObj in chkItems.CheckedItems)
                {
                    int itemID = ((ItemInfo)itemObj).ID;

                    _sellOrders.ItemFilter = "ItemID = " + itemID;
                    if (_sellOrders.FiltredItems.Count > 0)
                    {
                        // Check if there is a buy order for the same item as in this sell order
                        _buyOrders.ItemFilter = "ItemID = " + itemID;
                        foreach (Order o in _sellOrders.FiltredItems)
                        {
                            SortableCollection buyOrders = _buyOrders.FiltredItems;
                            if (buyOrders.Count > 0)
                            {
                                o.BuyOrderExistsForThisItem = (buyOrders[0] as Order).Station != "NO ORDER";
                            }
                        }
                    }
                }
                _buyOrders.ItemFilter = "";
                _sellOrders.ItemFilter = "";

                _ordersDataVisible = true;
                _ordersGettingData = false;
                RefreshOrders();
                RefreshGUI();
            }
            catch (ThreadAbortException)
            {
                // User has aborted, just drop out.
            }
            catch (Exception ex)
            {
                new EMMAException(ExceptionSeverity.Error, "Error when updating orders data in item detail", ex);
            }
        }