/// <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); }
/// <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); } }