Example #1
0
 /// <summary>
 /// Fetches a card from the product database.
 /// </summary>
 /// <param name="idProduct">Product ID of the card - it must be a single MtG cards, other products will not be found. If the card has not been
 /// found, it will attempt to update the local database if it is more than 24 hours old.</param>
 /// <param name="idProduct">Product ID of the card - it must be a single MtG cards, other products will not be found. If the card has not been
 /// found, it will attempt to update the local database if it is more than 24 hours old.</param>
 /// <returns>The card info with the entries from the Inventory (use InventoryFields to get names of columns).
 /// Returns null in case the product ID is invalid.</returns>
 public DataRow GetSingleCard(string idProduct)
 {
     if (SinglesByProductId.ContainsKey(idProduct))
     {
         return(InventorySinglesOnly[SinglesByProductId[idProduct]]);
     }
     else if ((DateTime.Now - File.GetLastWriteTime(@".\\mkminventory.csv")).TotalHours > 24)
     {
         MainView.Instance.LogMainWindow("Card id " + idProduct + " not found in local database, updating database...");
         UpdateDatabaseFiles();
         if (SinglesByProductId.ContainsKey(idProduct))
         {
             return(InventorySinglesOnly[SinglesByProductId[idProduct]]);
         }
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Writes the specified value for a specified item in the inventory.
        /// If the value is different from current value, marks the inventory as modified
        /// -> will save it to file before closing the application.
        /// </summary>
        /// <param name="productID">The product identifier.</param>
        /// <param name="inventoryField">The field (column) to which to write the value.</param>
        /// <param name="value">The value to enter in the database.</param>
        public void WriteValueToInventory(string idProduct,
                                          string inventoryField, string value)
        {
            if (!SinglesByProductId.ContainsKey(idProduct) &&
                (DateTime.Now - File.GetLastWriteTime(@".\\mkminventory.csv")).TotalHours > 24)
            {
                MainView.Instance.LogMainWindow("Card id " + idProduct + " not found in local database, updating database...");
                UpdateDatabaseFiles();
                if (!SinglesByProductId.ContainsKey(idProduct))
                {
                    LogError("writing " + inventoryField + " " + value + " for product id " + idProduct,
                             "Specified product ID does not exist.", false);
                }
            }
            int index = SinglesByProductId[idProduct];

            if (InventorySinglesOnly[index][inventoryField].ToString() != value)
            {
                InventorySinglesOnly[index][inventoryField] = value;
            }
        }