/// <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(); //} }
/// <summary> /// Delete the specified reprocess job from the database. /// </summary> /// <param name="jobData"></param> public static void DeleteJob(ReprocessJob jobData) { StoreJob(jobData, true); }
private static void StoreJob(ReprocessJob jobData, bool delete) { EMMADataSet.ReprocessJobDataTable table = new EMMADataSet.ReprocessJobDataTable(); EMMADataSet.ReprocessJobRow row = null; bool newRow = false; int? newID = 0; try { if (jobData.ID != 0) { // See if we can find the existing job in the database. lock (jobTableAdapter) { jobTableAdapter.FillByID(table, jobData.ID); } row = table.FindByID(jobData.ID); // make sure we clear the items and results for that job. lock (itemTableAdapter) { itemTableAdapter.ClearByJob(jobData.ID); } lock (resultTableAdapter) { resultTableAdapter.ClearByJob(jobData.ID); } } if (row == null) { // We either couldn't find the existing job or we're dealing with a // new job. // Either way, we need to create a new row. row = table.NewReprocessJobRow(); newRow = true; } // Set the values for the job row itself and store it. row.JobDate = jobData.Date; row.StationID = jobData.StationID; row.GroupID = jobData.ReportGroupID; row.OwnerID = jobData.OwnerID; if (newRow) { lock (jobTableAdapter) { jobTableAdapter.StoreNew(row.JobDate, row.StationID, row.GroupID, row.OwnerID, ref newID); } } else { if (delete) { row.Delete(); } else { newID = row.ID; } lock (jobTableAdapter) { jobTableAdapter.Update(table); } } if (newID.HasValue) { // Store the items and results of the job. foreach (ReprocessItem item in jobData.SourceItems) { item.JobID = newID.Value; StoreItem(item); } foreach (ReprocessResult result in jobData.Results) { result.JobID = newID.Value; StoreResult(result, jobData.Date); } } } catch (Exception ex) { EMMAException emmaEx = ex as EMMAException; if (emmaEx == null) { throw new EMMADataException(ExceptionSeverity.Error, "Problem storing reprocessing job data", ex); } else { throw ex; } } }
/// <summary> /// Store the specified reprocess job in the database. /// If the job already exists then the database is updated with any new information. /// </summary> /// <param name="jobData">The job data to be stored</param> /// <exception cref="EMMADataException"></exception> public static void StoreJob(ReprocessJob jobData) { StoreJob(jobData, false); }
private void RefreshItemList() { Cursor = Cursors.WaitCursor; try { DataGridViewColumn sortColumn = ItemsToReprocessView.SortedColumn; ListSortDirection sortDirection = ListSortDirection.Ascending; if (ItemsToReprocessView.SortOrder == SortOrder.Descending) { sortDirection = ListSortDirection.Descending; } _assets = new AssetList(); _reprocessJob = null; Asset container = null; if (cmbContainers.SelectedItem != null) { container = ((ContainerItem)cmbContainers.SelectedItem).Data; } if ((long)txtStation.Tag != 0 && cmbDefaultReprocessor.SelectedValue != null) { CharCorp charcorp = (CharCorp)cmbDefaultReprocessor.SelectedValue; long station = (long)txtStation.Tag; _reprocessJob = new ReprocessJob(station, UserAccount.CurrentGroup.ID, charcorp.ID); _reprocessJob.SetDefaultResultPrices(_resultPrices); if (container == null) { _assets = Assets.LoadReprocessableAssets(charcorp.ID, station, 1, false, true); } else { _assets = container.Contents; } foreach (Asset asset in _assets) { asset.ForceNoReproValAsUnitVal = true; } } ItemsToReprocessView.DataSource = _assets; decimal total = 0; foreach (Asset asset in _assets) { if (asset.Selected) { total += asset.TotalValue; } } lblValueBefore.Tag = total; lblValueBefore.Text = new IskAmount(total).ToString(); if (sortColumn != null) { ItemsToReprocessView.Sort(sortColumn, sortDirection); } } catch (Exception ex) { new EMMAException(ExceptionSeverity.Error, "Problem refreshing available assets", ex); MessageBox.Show("Problem refreshing available assets.\r\nSee Logging/exceptionlog.txt" + " for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } }
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; }