Пример #1
0
        public Form1()
        {
            InitializeComponent();
            //Helper.CreateConnectionString(null,null,null,null);
            //db = new MooglenomicsDatabaseDataContext(@"Data Source=moogle.no-ip.info;Initial Catalog=Mooglenomics;Persist Security Info=True;User ID=Moogle;Password=D&cMoogleMoney");
            db = new MooglenomicsDatabaseDataContext();
            AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();

            List<Item> items = db.Items.Where(p => p.isUntradeable == false).ToList();

            foreach (Item i in items)
            {
                acsc.Add(i.Name);
            }

            Search_Textbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            Search_Textbox.AutoCompleteCustomSource = acsc;
            Search_Textbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.Clear_Filter_Button_Click(null, null);
        }
Пример #2
0
        public static Best_Cost_Result Calculate_Item_CraftCost(Item i, MooglenomicsDatabaseDataContext db)
        {
            List<Recipe> recipes = i.Recipes.ToList();
            List<Best_Cost_Result> ListofCosts = new List<Best_Cost_Result>();
            foreach (Recipe r in recipes)
            {
                int reciptCost = 0;
                Best_Cost_Result recipeCost_result = new Best_Cost_Result();
                List<Ingredient> ingredients = r.Ingredients.ToList();
                foreach (Ingredient ing in ingredients)
                {
                    Best_Cost_Result ing_Best_Result = new Best_Cost_Result();
                    int cheapestCost = int.MaxValue;
                    Best_Cost_Result.Source cheapestSource = Best_Cost_Result.Source.NA;
                    Best_Cost_Result ingCraft_result = new Best_Cost_Result();
                    int ingCraftCost = int.MaxValue;
                    int vendorBought = int.MaxValue;
                    int marketBought = int.MaxValue;
                    int ingGatherCost = int.MaxValue;
                    Item mat = ing.Item;
                    if ((bool)mat.canCraft)
                    {
                        ingCraft_result = Calculate_Item_CraftCost(mat, db);
                        ingCraftCost = ingCraft_result.value;
                    }

                    if (cheapestCost > ingCraftCost)
                    {
                        cheapestCost = ingCraftCost;
                        cheapestSource = Best_Cost_Result.Source.Craft;
                    }

                    if ((bool)mat.isVendorBought && mat.buyFromVendor != null)
                    {
                        vendorBought = (int)mat.buyFromVendor;
                    }

                    if (cheapestCost > vendorBought)
                    {
                        cheapestCost = vendorBought;
                        cheapestSource = Best_Cost_Result.Source.Vendor;
                    }
                    LastMarket_value_View lmv = db.LastMarket_value_Views.SingleOrDefault(p => p.Item_ID_FK == mat.id);
                    if (lmv != null)
                    {
                        if (lmv.nqPrice == 0 && lmv.hqPrice == 0)
                        {
                            marketBought = int.MaxValue;
                        }
                        else if (lmv.nqPrice == 0 || lmv.nqPrice == null)
                        {
                            marketBought = (int)lmv.hqPrice;
                        }
                        else if (lmv.hqPrice == 0 || lmv.hqPrice == null)
                        {
                            marketBought = (int)lmv.nqPrice;
                        }
                        else
                        {
                            marketBought = (lmv.nqPrice < lmv.hqPrice) ? (int)lmv.nqPrice : (int)lmv.hqPrice;
                        }
                    }
                    if (cheapestCost > marketBought)
                    {
                        cheapestCost = marketBought;
                        cheapestSource = Best_Cost_Result.Source.Market;
                    }
                    //TODO: GatheringCost formula once it been complete;
                    if((bool)i.canGather)
                    {

                    }
                    if (cheapestCost > ingGatherCost)
                    {
                        cheapestCost = ingGatherCost;
                        cheapestSource = Best_Cost_Result.Source.Gather;
                    }
                    ing_Best_Result.value = cheapestCost;
                    ing_Best_Result.source = cheapestSource;
                    ing_Best_Result.item = mat;
                    if(cheapestSource == Best_Cost_Result.Source.Craft)
                    {
                        ing_Best_Result.Mats_Best_Source.Add(ingCraft_result);
                    }

                    recipeCost_result.Mats_Best_Source.Add(ing_Best_Result);

                    if(cheapestCost != int.MaxValue)
                    {
                        reciptCost += cheapestCost*(int)ing.quantity;
                    }
                }
                recipeCost_result.item = i;
                recipeCost_result.source = Best_Cost_Result.Source.Craft;
                recipeCost_result.value = reciptCost;
                ListofCosts.Add(recipeCost_result);
            }
            Best_Cost_Result toReturn = new Best_Cost_Result();
            foreach (Best_Cost_Result bcr in ListofCosts)
            {
                if(toReturn.value > bcr.value)
                {
                    toReturn = bcr;
                }
            }
            return toReturn;
        }