示例#1
0
        /// <summary>
        /// Gets all Parts in the Part database
        /// </summary>
        /// <returns>A Part[] containing all Parts in the database</returns>
        public static Part[] GetAllParts()
        {
            Storage[] storages = Storage.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, storages.Length.ToString());
            GraphicsCard[] cards = GraphicsCard.GetAll(); // bad
            Queries.Log(Queries.LogLevel.DEBUG, cards.Length.ToString());
            Case[] cases = Case.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, cases.Length.ToString());
            PowerSupply[] supplies = PowerSupply.GetAll(); //bad
            Queries.Log(Queries.LogLevel.DEBUG, supplies.Length.ToString());
            CPU[] cpus = CPU.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, cpus.Length.ToString());
            Fan[] fans = Fan.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, fans.Length.ToString());
            Memory[] mems = Memory.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, mems.Length.ToString());
            MOBO[] mobs = MOBO.GetAll();
            Queries.Log(Queries.LogLevel.DEBUG, mobs.Length.ToString());
            int length = storages.Length + cards.Length + cases.Length + supplies.Length + cpus.Length + fans.Length + mems.Length + mobs.Length;

            Part[] parts = new Part[length];
            storages.CopyTo(parts, 0);
            cards.CopyTo(parts, storages.Length);
            cases.CopyTo(parts, cards.Length + storages.Length);
            supplies.CopyTo(parts, cases.Length + cards.Length + storages.Length);
            cpus.CopyTo(parts, cases.Length + cards.Length + storages.Length + supplies.Length);
            fans.CopyTo(parts, cases.Length + cards.Length + storages.Length + supplies.Length + cpus.Length);
            mems.CopyTo(parts, cases.Length + cards.Length + storages.Length + supplies.Length + cpus.Length + fans.Length);
            mobs.CopyTo(parts, cases.Length + cards.Length + storages.Length + supplies.Length + cpus.Length + fans.Length + mems.Length);
            return(parts);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// A function for grabbing part info off of pcpart picker
        /// </summary>
        /// <param name="current">The Current table to populate</param>
        private static void PopulateTable(CurrentType current)
        {
            string content = File.ReadAllText("..//..//part data//" + current + ".html");

            if (current == CurrentType.cpu)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";\"") + 3);
                    string speed = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";\"") + 3);
                    string cores = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";\"") + 3);
                    string tdp = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string price = sub.Substring(0, sub.IndexOf("<"));
                    CPU    cpu;
                    try {
                        cpu = new CPU(partNumber, name, double.Parse(price), double.Parse(speed.Substring(0, speed.IndexOf("GH"))), int.Parse(cores), int.Parse(tdp.Substring(0, tdp.IndexOf("W"))));
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    cpu.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.fan)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";\"") + 3);
                    string speed = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";\"") + 3);
                    string nl = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string price = sub.Substring(0, sub.IndexOf("<"));
                    Fan    fan;
                    try {
                        if (speed.IndexOf("-") != -1)
                        {
                            speed = speed.Substring(speed.IndexOf("-") + 1);
                        }
                        speed = speed.Substring(0, speed.IndexOf("RPM"));
                        if (nl.IndexOf("-") != -1)
                        {
                            nl = nl.Substring(nl.IndexOf("-") + 1);
                        }
                        nl  = nl.Substring(0, nl.IndexOf("dbA"));
                        fan = new Fan(partNumber, name, double.Parse(price), int.Parse(speed), double.Parse(nl));
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    fan.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.motherboard)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    string socket = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    string form = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string slots = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string maxRam = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string price = sub.Substring(0, sub.IndexOf("<"));
                    MOBO   mBoard;
                    try {
                        mBoard = new MOBO(partNumber, name, double.Parse(price), socket, form, maxRam, int.Parse(slots));
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    mBoard.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.memory)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string speed = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string type = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string cas = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string modules = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string size = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string price = sub.Substring(0, sub.IndexOf("<"));
                    Memory memory;
                    try {
                        memory = new Memory(partNumber, name, double.Parse(price), speed, type, cas, modules, size);
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    memory.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.storage)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    string series = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string form = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string type = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string capacity = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string cache = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string  price   = sub.Substring(0, sub.IndexOf("<"));
                    Storage storage = new Storage(partNumber, name, double.Parse(price), series, form, type, capacity, cache);
                    storage.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.graphicsCard)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    string series = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string chipset = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string memory = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string coreclock = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string       price = sub.Substring(0, sub.IndexOf("<"));
                    GraphicsCard graphicsCard;
                    try { //Some have no price, ignore those
                        graphicsCard = new GraphicsCard(partNumber, name, double.Parse(price), series, chipset, memory, coreclock);
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    graphicsCard.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.powerSupply)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    string series = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string form = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string efficiency = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string watts = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string modular = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string      price = sub.Substring(0, sub.IndexOf("<"));
                    PowerSupply powerSupply;
                    try { //Some have no price, ignore those
                        powerSupply = new PowerSupply(partNumber, name, double.Parse(price), series, form, efficiency, watts, modular);
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    powerSupply.AddToDatabase();
                    partNumber++;
                }
            }
            else if (current == CurrentType.pcCase)
            {
                while (content.IndexOf("<tr>") != -1)
                {
                    content = content.Substring(content.IndexOf("<tr>") + 2);
                    string sub = content.Substring(0, content.IndexOf("</tr>"));
                    sub = sub.Substring(sub.IndexOf("a href"));
                    sub = sub.Substring(sub.IndexOf(">") + 1);
                    string name = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string type = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("<td>") + 4);
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string ext514 = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string in312 = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf(";") + 3);
                    string powersupply = sub.Substring(0, sub.IndexOf("<"));
                    sub = sub.Substring(sub.IndexOf("price") + 8);
                    string price = sub.Substring(0, sub.IndexOf("<"));
                    Case   pcCase;
                    try { //Some have no price, just ignore those
                        pcCase = new Case(partNumber, name, double.Parse(price), type, int.Parse(ext514), int.Parse(in312), powersupply);
                    }
                    catch (Exception e) {
                        Log(LogLevel.ERROR, e.StackTrace);
                        continue;
                    }
                    pcCase.AddToDatabase();
                    partNumber++;
                }
            }
            else
            {
                Console.WriteLine("invalid input: " + current);
            }
        }