/// <summary> /// Mapping between BestBargainTypes Enum and marketlog properties /// </summary> /// <param name="bbt">BestBargainTypes</param> /// <returns>Proper property value</returns> internal double GetHighLowByBargainType(BestBargainTypes bbt) { switch (bbt) { case BestBargainTypes.SecondHighestBidderLowestRegion: case BestBargainTypes.HighestBidderLowestRegion: case BestBargainTypes.SecondHighestBuy: case BestBargainTypes.HighestBuy: return(HighestBuy); case BestBargainTypes.SecondLowestSellerHighestRegion: case BestBargainTypes.LowestSellerHighestRegion: case BestBargainTypes.SecondLowestSell: case BestBargainTypes.LowestSell: return(LowestSell); case BestBargainTypes.HighestSell: return(HighestSell); case BestBargainTypes.LowestBuy: return(LowestBuy); default: return(-1); } }
private void cbBargainTypeL_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cb = (ComboBox)sender; BestBargainTypes selectedBargainType = (BestBargainTypes)cb.SelectedIndex; FindBargain(selectedBargainType, ref cbRegionsL); _abbtSelectedType[0] = selectedBargainType; }
/// <summary> /// Mapping between BestBargainTypes Enum and marketlog properties /// </summary> /// <param name="bbt">BestBargainTypes</param> /// <returns>Proper property value</returns> internal double GetHighLowByBargainType(BestBargainTypes bbt) { switch (bbt) { case BestBargainTypes.SecondHighestBidderLowestRegion: case BestBargainTypes.HighestBidderLowestRegion: case BestBargainTypes.SecondHighestBuy: case BestBargainTypes.HighestBuy: return HighestBuy; case BestBargainTypes.SecondLowestSellerHighestRegion: case BestBargainTypes.LowestSellerHighestRegion: case BestBargainTypes.SecondLowestSell: case BestBargainTypes.LowestSell: return LowestSell; case BestBargainTypes.HighestSell: return HighestSell; case BestBargainTypes.LowestBuy: return LowestBuy; default: return -1; } }
/// <summary> /// Finds the best region on a particular bargain type i.e. Lowest Sell /// </summary> /// <param name="bbtType">The type of bargain selected by user.</param> /// <param name="cbRegions">The originating ComboBox.</param> private static void FindBargain(BestBargainTypes bbtType, ref ComboBox cbRegions) { int iCbIndex = 0; int iBargainIndex = 0; List <KeyValuePair <int, double> > dicPrices = new List <KeyValuePair <int, double> >(); // Skip if no data if (cbRegions.DataSource == null) { return; } // Loop the marketlogs and add to list based on bargain type foreach (MarketLog ml in (ArrayList)cbRegions.DataSource) { // skip marketlog on empty filename if (ml.FileName == string.Empty) { continue; } // increment the index iCbIndex++; // add the High or Low value to dictionary dicPrices.Add(new KeyValuePair <int, double>(iCbIndex, ml.GetHighLowByBargainType(bbtType))); } // Sortings switch (bbtType) { case BestBargainTypes.HighestBuy: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondHighestBuy: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; // The lowest region of all the highest bidders // (Where to place your Buy orders) case BestBargainTypes.HighestBidderLowestRegion: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondHighestBidderLowestRegion: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; //----------------------------------------------- case BestBargainTypes.LowestSell: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondLowestSell: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; // The Highest region of the lowest sellers //(Where to place you Sell orders) case BestBargainTypes.LowestSellerHighestRegion: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondLowestSellerHighestRegion: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; } // Set the selected region in the referenced combobox if (iBargainIndex != 0) { cbRegions.SelectedIndex = iBargainIndex; } }
/// <summary> /// Finds the best region on a particular bargain type i.e. Lowest Sell /// </summary> /// <param name="bbtType">The type of bargain selected by user.</param> /// <param name="cbRegions">The originating ComboBox.</param> private static void FindBargain(BestBargainTypes bbtType, ref ComboBox cbRegions) { int iCbIndex = 0; int iBargainIndex = 0; List<KeyValuePair<int, double>> dicPrices = new List<KeyValuePair<int, double>>(); // Skip if no data if (cbRegions.DataSource == null) return; // Loop the marketlogs and add to list based on bargain type foreach (MarketLog ml in (ArrayList)cbRegions.DataSource) { // skip marketlog on empty filename if (ml.FileName == string.Empty) continue; // increment the index iCbIndex++; // add the High or Low value to dictionary dicPrices.Add(new KeyValuePair<int, double>(iCbIndex, ml.GetHighLowByBargainType(bbtType))); } // Sortings switch (bbtType) { case BestBargainTypes.HighestBuy: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondHighestBuy: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; // The lowest region of all the highest bidders // (Where to place your Buy orders) case BestBargainTypes.HighestBidderLowestRegion: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondHighestBidderLowestRegion: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; //----------------------------------------------- case BestBargainTypes.LowestSell: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondLowestSell: dicPrices.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; // The Highest region of the lowest sellers //(Where to place you Sell orders) case BestBargainTypes.LowestSellerHighestRegion: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); iBargainIndex = dicPrices[0].Key; break; case BestBargainTypes.SecondLowestSellerHighestRegion: dicPrices.Sort((firstPair, nextPair) => nextPair.Value.CompareTo(firstPair.Value)); // second high/low price in different region iBargainIndex = Utility.findSecondRegion(dicPrices); break; } // Set the selected region in the referenced combobox if (iBargainIndex != 0) cbRegions.SelectedIndex = iBargainIndex; }