예제 #1
0
        /// <summary>
        /// Gets the required data from the database
        /// </summary>
        public void GetDataFromDatabase()
        {
            EveDataSet.invTypesDataTable assetItems = Items.GetItemsThatAreAssets(_assetAccessParams);
            int maxProgress = assetItems.Count;
            UpdateStatus(0, maxProgress, "Getting Report Data...", "", false);
            //StreamWriter log = File.CreateText("C:\\AssetsReport.txt");
            //try
            //{
                // Cycle through all items that are assets and add thier data to the report
                for (int j = 0; j < assetItems.Count; j++)
                {
                    EveDataSet.invTypesRow item = assetItems[j];
                    int itemID = item.typeID;
                    long quantity = Assets.GetTotalQuantity(_assetAccessParams, item.typeID, _stationsIDs, _regionIDs,
                        _includeInTransit, _includeContainers);

                    decimal avgBuyPrice = 0, avgSellPrice = 0;
                    decimal marginAbs = 0, totalProfit = 0;
                    decimal reproValue = 0;
                    decimal bestProfit = 0;

                    List<int> itemIDs = new List<int>();
                    itemIDs.Add(itemID);

                    // Only add the item if we actually have any (although only items with positive amounts in a station
                    // are included, it would be possible to have included an item with positive and negative quantities
                    // in different stations that balance to 0 or less)..
                    if (quantity > 0)
                    {
                        // Get values from database
                        //Transactions.GetAverageBuyPrice(_financeAccessParams, itemIDs, _stationsIDs, _regionIDs,
                        //    quantity, 0, ref avgBuyPrice, ref blank1, true);
                        quantity = 0;
                        AssetList assets = Assets.GetAssets(_assetAccessParams, itemID, _stationsIDs, _regionIDs,
                            _includeInTransit, _includeContainers, true);
                        foreach (Asset a in assets)
                        {
                            avgBuyPrice += a.TotalBuyPrice;
                            quantity += a.Quantity;
                        }
                        if (quantity > 0)
                        {
                            avgBuyPrice /= quantity;
                            avgSellPrice = UserAccount.CurrentGroup.ItemValues.GetItemValue(item.typeID,
                                _valueRegionID, false);

                            // If we couldn't find a buy price for the sold items then try and
                            // get a buy price from other sources
                            if (avgBuyPrice == 0 || UserAccount.CurrentGroup.ItemValues.ForceDefaultBuyPriceGet(itemID))
                            {
                                bool tmp = UserAccount.CurrentGroup.Settings.UseEveCentral;
                                UserAccount.CurrentGroup.Settings.UseEveCentral = false;
                                avgBuyPrice = UserAccount.CurrentGroup.ItemValues.GetBuyPrice(itemID,
                                    _regionIDs.Count == 1 ? _regionIDs[0] : 0);
                                UserAccount.CurrentGroup.Settings.UseEveCentral = tmp;

                                if (avgBuyPrice == 0)
                                {
                                    // If we still fail to get a buy price then just set it to the same as the
                                    // sell price.
                                    avgBuyPrice = avgSellPrice;
                                }
                            }

                            //log.WriteLine(Items.GetItemName(itemID) + ", " + quantity + ", " + avgSellPrice);

                            // Calculate data for columns
                            if (avgSellPrice > 0) marginAbs = avgSellPrice - avgBuyPrice;
                            totalProfit = marginAbs * quantity;
                            bestProfit = totalProfit;

                            // Get reprocess value
                            // reproValue = quantity * Items.GetItemReprocessValue(itemID);
                            ReprocessJob job = new ReprocessJob(0, 0, 0);
                            job.AddItem(itemID, quantity, avgBuyPrice * quantity);
                            job.UpdateResults();
                            reproValue = job.TotalResultsValue;
                            if (reproValue > quantity * avgSellPrice)
                            {
                                bestProfit = reproValue - (avgBuyPrice * quantity);
                            }

                            // Add a row for this item to the grid.
                            EveDataSet.invTypesRow itemData = Items.GetItem(itemID);
                            string itemName = itemData.typeName;
                            ReportSection section = null;
                            if (_byItemGroup)
                            {
                                if (itemData.IsmarketGroupIDNull())
                                {
                                    section = _sections.GetSection("Non-Market Items");
                                }
                                else
                                {
                                    section = _sections.GetSection(itemData.marketGroupID.ToString());
                                }
                            }
                            else
                            {
                                section = _sections[0];
                            }
                            section.AddRow(_columns.Length, itemID.ToString(), itemName);

                            // Add the data for this row.
                            SetValue("Average Buy Price", itemID.ToString(), avgBuyPrice, true);
                            SetValue("Est. Sell Price", itemID.ToString(), avgSellPrice, true);
                            SetValue("Total Units", itemID.ToString(), quantity, true);
                            SetValue("Total Est. Value", itemID.ToString(), quantity * avgSellPrice, true);
                            SetValue("Total Est. Gross Profit", itemID.ToString(), totalProfit, true);
                            SetValue("Reprocess Value", itemID.ToString(), reproValue, true);
                            SetValue("Best Gross Profit", itemID.ToString(), bestProfit, true);

                            UpdateStatus(j, maxProgress, "", itemName, false);
                        }
                    }
                }
            //}
            //finally
            //{
            //    log.Close();
            //}
        }
예제 #2
0
        public decimal GetReprocessValue(int itemID)
        {
            if (this.ValueCalculationEvent != null)
            {
                ValueCalculationEvent(this, new ValueCalcEventArgs("Calculating reprocess value of " + Items.GetItemName(itemID)));
            }

            ReprocessJob job = new ReprocessJob(0, 0, 0);
            job.AddItem(itemID, 1, 1000);
            job.UpdateResults();

            if (this.ValueCalculationEvent != null)
            {
                ValueCalculationEvent(this, new ValueCalcEventArgs("Reprocess value = " + job.TotalResultsValue));
            }

            return job.TotalResultsValue;
        }