예제 #1
0
 public static Recipe CreateRecipe(string recipeID, int crafterCatID, MooglenomicsDatabaseDataContext db)
 {
     Recipe r = new Recipe();
     r.RecipeID = recipeID;
     r = UpdateRecipe(r, crafterCatID, db);
     return r;
 }
예제 #2
0
        public Form1()
        {
            InitializeComponent();
            db = new MooglenomicsDatabaseDataContext();
            try
            {
                User u = db.Users.SingleOrDefault(p => p.UserID == 1);
                if (u == null)
                {
                    User systemUser = new User();
                    systemUser.UserID = 1;
                    systemUser.UserName = "******";
                    systemUser.password = "******";
                    db.Users.InsertOnSubmit(systemUser);
                    db.SubmitChanges();
                }

                List<string> catNames = new List<string>();
                foreach (ItemCategory ic in db.ItemCategories.ToList())
                {
                    catNames.Add(ic.CategoryName);
                }
                category_Combobox.Items.AddRange(catNames.ToArray());

            }
            catch
            {
                MessageBox.Show("Database Connection Failed.  Exiting");
            }
        }
예제 #3
0
        public static Recipe UpdateRecipe(Recipe r, int crafterCatID, MooglenomicsDatabaseDataContext db)
        {
            r.craftingClass = crafterCatID.ToString();
            WebClient webClient = new WebClient();
            string pageSource = webClient.DownloadString(baseURL + "recipe/" + r.RecipeID);
            r.isHQCraftable = pageSource.Contains("HQ Craftable");
            r.isQuickSynthesis = pageSource.Contains("Quick Synthesis Available");
            MatchCollection m1 = Regex.Matches(pageSource, "<dd class=\"mb20\">(\\d*)", RegexOptions.Singleline);
            r.yeild = Convert.ToInt32(m1[0].Groups[1].Value);
            r.difficulty = Convert.ToInt32(m1[1].Groups[1].Value);
            r.durability = Convert.ToInt32(m1[2].Groups[1].Value);
            r.maxQuality = Convert.ToInt32(m1[3].Groups[1].Value);
            m1 = Regex.Matches(pageSource, "Lv. <span>(\\d*)", RegexOptions.Singleline);
            r.craftingLevel = m1[0].Groups[1].Value;
            m1 = Regex.Matches(pageSource, "Control Required: (\\d*)", RegexOptions.Singleline);
            if (m1.Count != 0)
            {
                r.minControl = Convert.ToInt32(m1[0].Groups[1].Value);
            }
            else
            {
                r.minControl = 0;
            }
            m1 = Regex.Matches(pageSource, "Craftsmanship Required: (\\d*)", RegexOptions.Singleline);
            if (m1.Count != 0)
            {
                r.minCraftmanship = Convert.ToInt32(m1[0].Groups[1].Value);
            }
            else
            {
                r.minCraftmanship = 0;
            }

            //Get Ingredients

            //<a href=\"/lodestone/playguide/db/item/[a-z,A-Z,0-9]*/\" class=\"db_popup highlight\">([A-Z,a-z,\\s]*)<\\/a

            //<a href=\"/lodestone/playguide/db/item/[a-z,A-Z,0-9]*/\" class=\"db_popup highlight\">([A-Z,a-z,\\s]*)&nbsp;\\((\\d*)\\)

            m1 = Regex.Matches(pageSource, "<a href=\"/lodestone/playguide/db/item/[a-z,A-Z,0-9]*/\" class=\"db_popup highlight\">([A-Z,a-z,\\s]*)<\\/a", RegexOptions.Singleline);

            foreach (Match m in m1)
            {
                string itemName = m.Groups[1].Value.Trim();
                Item i = db.Items.SingleOrDefault(p => p.Name.Equals(itemName) && p.isUntradeable == false);
                Ingredient ig = r.Ingredients.SingleOrDefault(p => p.Item == i);
                if (ig == null)
                {
                    ig = new Ingredient();
                    ig.Recipe = r;
                    ig.Item = i;
                    r.Ingredients.Add(ig);
                }
                ig.quantity = 1;

            }

            m1 = Regex.Matches(pageSource, "<a href=\"/lodestone/playguide/db/item/[a-z,A-Z,0-9]*/\" class=\"db_popup highlight\">([A-Z,a-z,\\s]*)&nbsp;\\((\\d*)\\)", RegexOptions.Singleline);

            foreach (Match m in m1)
            {
                string itemName = m.Groups[1].Value.Trim();
                Item i = db.Items.SingleOrDefault(p => p.Name.Equals(itemName) && p.isUntradeable == false);
                Ingredient ig = r.Ingredients.SingleOrDefault(p => p.Item == i);
                if (ig == null)
                {
                    ig = new Ingredient();
                    ig.Recipe = r;
                    ig.Item = i;
                    r.Ingredients.Add(ig);
                }
                ig.quantity = Convert.ToInt32(m.Groups[2].Value);

            }

            m1 = Regex.Matches(pageSource, "<a href=\"/lodestone/playguide/db/item/([a-z,A-Z,0-9]*)/\">\\s*<img", RegexOptions.Singleline);
            string itemID = m1[0].Groups[1].Value;
            r.Item = db.Items.Single(p => p.ItemID.Equals(itemID));
            return r;
        }