static void dictate(Test.MysqlConnector mc) { var reader = mc.ExeQuery("SELECT * FROM words"); var ans = ""; var wrong = 0; var right = 0; while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { if (i % 2 != 0) { Console.Write(string.Format("Which word means {0} in French?\n"), reader.GetValue(i)); ans = Console.ReadLine(); } else { if (ans == reader.GetValue(i).ToString()) { Console.WriteLine("Bingo!You did a good job!"); right++; } else { Console.WriteLine("What a pity!The correct answer is ", reader.GetValue(i)); wrong++; } } } } Console.WriteLine(string.Format("You mispelt {0} word(s) and you spelt {1} word(s) correctly!", wrong, right)); Console.ReadKey(); }
static void Main(string[] args) { var mc = new Test.MysqlConnector(); mc.SetServer("127.0.0.1") .SetDataBase("test") //选择数据库 .SetUserID("root") //输入用户名 .SetPassword("root") //输入用户密码 .SetPort("3306") //设置端口号 .SetCharset("utf8"); //设置字符集 Console.WriteLine("********_ Welcome to PEC-Ta _********"); while (true) { Console.WriteLine("Enter A for adding words, enter D for dictating, enter E for exiting:"); switch (Console.ReadLine()) { case "A": while (addWords(mc)) { ; } Console.WriteLine(); break; case "D": dictate(mc); break; case "E": return; default: Console.WriteLine("Ouch!Wrong letter!"); break; } } }
static bool addWords(Test.MysqlConnector mc) { Console.Write("Please enter a chinese word: "); var cn = Console.ReadLine(); Console.Write("\nPlease enter a french word: "); var fr = Console.ReadLine(); mc.ExeUpdate(string.Format("INSERT INTO words ( Chinese, French ) VALUES( \"{0}\", \"{1}\" );", cn, fr)); Console.Write("Would you like to continue typing?(Y or N)"); return(Console.ReadLine() == "Y"); }