public override string[] Show() { var uids = dbhandler.Query("SELECT id FROM users;", 0); HashSet <int> uidset = new HashSet <int>(); Dictionary <int, string> unames = new Dictionary <int, string>(); Dictionary <string, int> uidd = new Dictionary <string, int>(); foreach (string id in uids) { var nid = Convert.ToInt32(id); uidset.Add(nid); var uname = dbhandler.Query(String.Format("SELECT id,name FROM users WHERE id={0}", id), 1)[0]; unames.Add(nid, uname); try { uidd.Add(uname, nid); } catch { } } //have a spot here for someone to type in their username while (true) { Console.Clear(); Console.WriteLine(new string('-', Console.WindowWidth)); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please enter your username or ID:"); Console.Write(">"); var un = Console.ReadLine(); int isid = -1; string sid = ""; try { isid = Convert.ToInt32(un); } catch { sid = un; } if (isid != -1) { if (uidset.Contains(isid)) { return(new string[] { isid.ToString(), unames[isid] }); } } if (sid != "") { if (uidd.ContainsKey(sid)) { return(new string[] { uidd[sid].ToString(), sid }); } } Console.WriteLine("INVALID USERID OR USERNAME!"); Thread.Sleep(1000); } }
public override string[] Show() { Console.Clear(); Console.WriteLine("Signed in as: {0}", this.username); Console.WriteLine(new string('-', Console.WindowWidth)); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please enter your question (blank for exit):"); Console.Write(">"); var qu = Console.ReadLine(); // use this implementation or do all the sql stuff in this class //INSERT INTO questions(question, ownerid) VALUES('', 12); dBConnectionHandler.Query(String.Format("INSERT INTO questions(question,ownerid) VALUES('{0}', {1});", qu, this.userID.ToString()), 0); return(new string[] { qu }); }
public string[] Show(string questionID) { var questionText = dBConnectionHandler.Query(String.Format("SELECT id,question FROM questions WHERE id={0};", questionID), 0)[0]; return(Show(questionID, questionText)); }