Ejemplo n.º 1
0
        /// Returns all cards in the specified expansions.
        /// <param name="idExpansion">Expansion's ID.</param>
        /// <returns>Array of card records, each record has the entries from the Inventory (use InventoryFields to get names of columns).
        /// Empty if idExpansion is invalid.</returns>
        public IEnumerable <DataRow> GetCardsInExpansion(string idExpansion)
        {
            var ret = InventorySinglesOnly.AsEnumerable()
                      .Where(r => r.Field <string>(InventoryFields.ExpansionID).Equals(idExpansion));

            if (ret.Count() == 0 && updateExpansionDatabase24hours()) // try again with up to date database
            {
                ret = InventorySinglesOnly.AsEnumerable()
                      .Where(r => r.Field <string>(InventoryFields.ExpansionID).Equals(idExpansion));
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns all cards in the specified expansions.
        /// </summary>
        /// <param name="idExpansion">Expansion's ID.</param>
        /// <returns>Array of card records, each record has the entries from the Inventory (use InventoryFields to get names of columns).
        /// Empty if idExpansion is invalid.</returns>
        public IEnumerable <DataRow> GetCardsInExpansion(string idExpansion)
        {
            var ret = InventorySinglesOnly.AsEnumerable()
                      .Where(r => r.Field <string>(InventoryFields.ExpansionID).Equals(idExpansion));

            if (ret.Count() == 0 && (DateTime.Now - File.GetLastWriteTime(@".\\mkmexpansions.csv")).TotalHours > 24)
            {
                MainView.Instance.LogMainWindow("Expansion id " + idExpansion + " not found in local database, updating database...");
                UpdateDatabaseFiles();
                ret = InventorySinglesOnly.AsEnumerable()
                      .Where(r => r.Field <string>(InventoryFields.ExpansionID).Equals(idExpansion));
            }
            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets all card entires with a given name.
        /// </summary>
        /// <param name="enName">English name of the card.</param>
        /// <returns>For each expansion the card has been printed in, one entry from the Inventory is returned (use InventoryFields to get names of columns).
        /// Empty if nothing found.</returns>
        public IEnumerable <DataRow> GetCardByName(string enName)
        {
            var ret = InventorySinglesOnly.AsEnumerable().Where(
                r => r.Field <string>(InventoryFields.Name) == enName);

            if (ret.Count() > 0)
            {
                return(ret);
            }
            else if ((DateTime.Now - File.GetLastWriteTime(@".\\mkminventory.csv")).TotalHours > 24)
            {
                MainView.Instance.LogMainWindow("Card " + enName + " not found in local database, updating database...");
                UpdateDatabaseFiles();
                return(InventorySinglesOnly.AsEnumerable().Where(r => r.Field <string>(InventoryFields.Name) == enName));
            }
            return(new DataRow[0]);
        }
Ejemplo n.º 4
0
        /// Gets the product ID based on expansionID and name.
        /// <param name="enName">English name of the card.</param>
        /// <param name="expansionID">ID of the expansion.</param>
        /// <returns>Strings of all matching products. Usually it will be exactly one, but can be empty if nothing is found,
        /// and in some cases there can be multiple products of the same name in a single expansion, e.g. basic lands.</returns>
        public string[] GetCardProductID(string enName, string expansionID)
        {
            var ret = InventorySinglesOnly.AsEnumerable().Where(
                r => r.Field <string>(InventoryFields.ExpansionID) == expansionID &&
                r.Field <string>(InventoryFields.Name) == enName);

            if (ret.Count() == 0 && updateExpansionDatabase24hours()) // try again with up to date database
            {
                ret = InventorySinglesOnly.AsEnumerable().Where(
                    r => r.Field <string>(InventoryFields.ExpansionID) == expansionID &&
                    r.Field <string>(InventoryFields.Name) == enName);
            }
            string[] retStrings = new string[ret.Count()];
            for (int i = 0; i < ret.Count(); i++)
            {
                retStrings[i] = ret.ElementAt(i)[InventoryFields.ProductID].ToString();
            }
            return(retStrings);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the product ID based on expansionID and name.
        /// </summary>
        /// <param name="enName">English name of the card.</param>
        /// <param name="expansionID">ID of the expansion.</param>
        /// <returns>Strings of all matching products. Usually it will be exactly one, but can be empty if nothing is found,
        /// and in some cases there can be multiple products of the same name in a single expansion, e.g. basic lands.</returns>
        public string[] GetCardProductID(string enName, string expansionID)
        {
            var ret = InventorySinglesOnly.AsEnumerable().Where(
                r => r.Field <string>(InventoryFields.ExpansionID) == expansionID &&
                r.Field <string>(InventoryFields.Name) == enName);

            if (ret.Count() == 0 && (DateTime.Now - File.GetLastWriteTime(@".\\mkmexpansions.csv")).TotalHours > 24)
            {
                MainView.Instance.LogMainWindow("Product " + enName + " from " + expansionID + " not found in local database, updating database...");
                UpdateDatabaseFiles();
                ret = InventorySinglesOnly.AsEnumerable().Where(
                    r => r.Field <string>(InventoryFields.ExpansionID) == expansionID &&
                    r.Field <string>(InventoryFields.Name) == enName);
            }
            string[] retStrings = new string[ret.Count()];
            for (int i = 0; i < ret.Count(); i++)
            {
                retStrings[i] = ret.ElementAt(i)[InventoryFields.ProductID].ToString();
            }
            return(retStrings);
        }