void AddExpansionToDatabase(JToken cardList, string expansion, string abbreviation)
        {
            if (!DatabaseManager.CheckIfSetExists(expansion))
            {
                DatabaseManager.AddNewSet(expansion, abbreviation, null, "non_mtg");
                Logger.LogActivity("Adding new set: " + expansion + " to databse");
            }
            foreach (var card in cardList)
            {
                try
                {
                    string multiverseID = PrepareString(card, "multiverseid");
                    if (DatabaseManager.CheckIfCardExists(multiverseID))
                    {
                        continue;
                    }

                    Dictionary <string, object> values = new Dictionary <string, object>();

                    values.Add("category", PrepareString(card, "category"));
                    values.Add("number", PrepareString(card, "number"));
                    values.Add("name", PrepareString(card, "name"));
                    values.Add("team", PrepareString(card, "team"));
                    values.Add("printRun", PrepareString(card, "printRun"));
                    values.Add("odds", PrepareString(card, "odds"));
                    values.Add("other", PrepareString(card, "other"));
                    values.Add("inventory", 0);

                    try
                    {
                        DatabaseManager.AddNewCard("non_mtg", values);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Adding MtG card to database", ex.ToString(), card.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //TODO: THROW MY OWN EXCEPTIONS
                    Logger.LogError("Preparing MtG card data to be added to database", ex.ToString(), card.ToString());
                }
            }
        }
Example #2
0
        void SaveData()
        {
            //TODO: Parse file name correctly
            var setExists = true;

            if (!DatabaseManager.CheckIfSetExists(SetData["Set"]))
            {
                DatabaseManager.AddNewSet(SetData["Set"], null, null, "non_mtg");
                Logger.LogActivity("Adding new set: " + SetData["Set"] + " to databse");

                setExists = false;
            }

            for (int i = 0; i < dataGridView_CardList.Rows.Count - 1; i++)
            {
                var row = dataGridView_CardList.Rows[i];

                Dictionary <string, object> values = new Dictionary <string, object>();
                values.Add("Expansion", SetData["Set"]);
                values.Add("Year", SetData["Year"]);
                values.Add("Sport", SetData["Sport"]);
                values.Add("Brand", SetData["Brand"]);

                for (int j = 0; j < dataGridView_CardList.Columns.Count; j++)
                {
                    var columnName = Regex.Replace(dataGridView_CardList.Columns[j].Name, " ", String.Empty);
                    columnName = Regex.Replace(columnName, "'", String.Empty);

                    if (columnName == "Inventory")
                    {
                        continue;
                    }

                    var columnData = Convert.ToString(row.Cells[j].Value);

                    if (columnName == "Expansion" || columnName == "Set")
                    {
                        //TODO: Something here?
                        continue;
                    }
                    if (columnName == "SetName" || columnName == "CardSet" || columnName == "Subset")
                    {
                        columnName = "Category";
                    }
                    if (columnName == "Card" || columnName == "Checklist")
                    {
                        columnName = "Number";
                    }
                    if (columnName == "Description" || columnName == "Player")
                    {
                        columnName = "Name";
                    }
                    if (columnName == "TeamCity")
                    {
                        columnName = "Team";
                    }
                    if (columnName.Contains("#"))
                    {
                        columnName = "PrintRun";
                    }
                    if (columnName == "TeamName")
                    {
                        values["Team"] += " " + columnData;
                        continue;
                    }

                    if (columnName == "Plates" && !String.IsNullOrWhiteSpace(columnData))
                    {
                        //TODO: Create new record
                    }

                    if (columnName.Contains("Foil") && !String.IsNullOrWhiteSpace(columnData))
                    {
                        //TODO: Create new record
                    }

                    var newColumnName = PrepColumnName(columnName);
                    if (newColumnName == "ExtraData")
                    {
                        object entry;
                        values.TryGetValue("ExtraData", out entry);

                        if (entry == null)
                        {
                            values.Add("ExtraData", "");
                            values.TryGetValue("ExtraData", out entry);
                        }
                        if (!String.IsNullOrWhiteSpace(columnData))
                        {
                            if (columnName.Contains("("))
                            {
                                var firstPart = columnName.Split('(').First();
                                var lastPart  = columnName.Split(')').Last();

                                columnName = firstPart + lastPart;
                            }
                            if (!String.IsNullOrWhiteSpace(entry.ToString()))
                            {
                                values["ExtraData"] += ", " + columnName + ": " + columnData;
                            }
                            else
                            {
                                values["ExtraData"] = columnName + ": " + columnData;
                            }
                        }
                        continue;
                    }

                    if (columnData == null)
                    {
                        columnData = String.Empty;
                    }

                    values.Add(columnName, columnData);
                }

                var md5 = String.Empty;
                if (setExists)
                {
                    md5 = CheckForDuplicates(values);
                }
                if (md5 == String.Empty)
                {
                    continue;
                }
                values.Add("MD5Hash", md5);

                var amount = String.IsNullOrWhiteSpace(Convert.ToString(row.Cells["Inventory"].Value)) ? "0" : row.Cells["Inventory"].Value.ToString();
                values.Add("Inventory", amount);

                try
                {
                    DatabaseManager.AddNewCard("non_mtg", values);
                }
                catch (Exception ex)
                {
                    Logger.LogError("Attempting to add CC card to database", ex.ToString(), dataGridView_CardList.Rows[i].ToString());
                }
            }
        }