Esempio n. 1
0
        /// <summary>
        /// Gets a Part with the given part number
        /// </summary>
        /// <param name="partNumber">The number of the desired Part</param>
        /// <returns>The Part with the given part number</returns>
        public static Part GetPart(int partNumber)
        {
            string[] result = Queries.Query("SELECT * FROM `part` WHERE `part number` = " + partNumber);
            if (result.Length > 0)
            {
                string[] p    = result[0].Split('\0');
                string   type = p[1].ToLower();
                if (type.Equals("graphics card"))
                {
                    type = "graphicscard";
                }
                else if (type.Equals("power supply"))
                {
                    type = "powersupply";
                }
                else if (type.Equals("pc case"))
                {
                    type = "pc case";
                }
                result = Queries.Query("SELECT * FROM `" + type + "` WHERE `part number` = " + partNumber);
                if (result.Length > 0)
                {
                    switch (type)
                    {
                    case "storage":
                        return(Storage.GetFromQuery(result[0]));

                    case "graphicscard":
                        return(GraphicsCard.GetFromQuery(result[0]));

                    case "pc case":
                        return(Case.GetFromQuery(result[0]));

                    case "powersupply":
                        return(PowerSupply.GetFromQuery(result[0]));

                    case "cpu":
                        return(CPU.GetFromQuery(result[0]));

                    case "fan":
                        return(Fan.GetFromQuery(result[0]));

                    case "memory":
                        return(Memory.GetFromQuery(result[0]));

                    case "motherboard":
                        return(MOBO.GetFromQuery(result[0]));

                    default:
                        return(null);
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Searches for parts based on a name
        /// </summary>
        /// <param name="partName">The name of the Part</param>
        /// <returns>A List containing the results of the search</returns>
        public static List <Part> Search(string partName)
        {
            List <Part> parts = new List <Part>();

            for (int i = 0; i < tables.Length; i++)
            {
                string[] result = Queries.Query(string.Format("SELECT * FROM `{0}` WHERE name like '%{1}%'", tables[i], partName));
                switch (i)
                {
                case 0:
                    foreach (string p in result)
                    {
                        parts.Add(CPU.GetFromQuery(p));
                    }
                    break;

                case 1:
                    foreach (string p in result)
                    {
                        parts.Add(Fan.GetFromQuery(p));
                    }
                    break;

                case 2:
                    foreach (string p in result)
                    {
                        parts.Add(GraphicsCard.GetFromQuery(p));
                    }
                    break;

                case 3:
                    foreach (string p in result)
                    {
                        parts.Add(Memory.GetFromQuery(p));
                    }
                    break;

                case 4:
                    foreach (string p in result)
                    {
                        parts.Add(MOBO.GetFromQuery(p));
                    }
                    break;

                case 5:
                    foreach (string p in result)
                    {
                        parts.Add(Case.GetFromQuery(p));
                    }
                    break;

                case 6:
                    foreach (string p in result)
                    {
                        parts.Add(PowerSupply.GetFromQuery(p));
                    }
                    break;

                case 7:
                    foreach (string p in result)
                    {
                        parts.Add(Storage.GetFromQuery(p));
                    }
                    break;
                }
            }
            return(parts);
        }