目录
-
学习新单词
-
设计中的技巧:
- 顺序或随机学习的选择窗口可以在学习窗口的构造函数中弹出供选择,用一个变量记录选择状态。
- 随机学习时保证不重复:可以用一个vector打乱顺序作为乱序的“顺序”。
-
“RorL.h”
- 引入全局变量learningMode, learnflag;
- 组件声明:
private: System::Windows::Forms::Label^ label1; //“请选择学习模式:” private: System::Windows::Forms::Button^ button1; //“顺序”或“汉译英” private: System::Windows::Forms::Button^ button2; //“随机”或“英译汉”
- 事件方法
- 界面加载
private: System::Void RorL_Load(System::Object^ sender, System::EventArgs^ e) { if (!learnflag) {//判断选择情况:学习新单词还是复习测试 String^ EtoC = "汉译英"; this->button1->Text = EtoC; String^ CtoE = "英译汉"; this->button2->Text = CtoE; } }
-
单击“顺序”或“汉译英”
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { learningMode = true; this->Close(); }
-
单击“随机”或“英译汉”
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { learningMode = false; this->Close(); }
- 界面加载
-
“Study.h”
-
头文件引入”Word.h”; “RorL.h”; “MySQLDbConn.h”; “User.h”; <algorithm>(打乱顺序的random_shuffle函数); <time.h>(读取日期); <stdlib.h>; <string> (to_string函数)
- 引入全局变量member, wordlist, userConnect, word, temp, learnflag
- 组件声明
private: System::Windows::Forms::Label^ label1; //显示单词 private: System::Windows::Forms::Label^ label2; //“翻译:” private: System::Windows::Forms::Label^ label3; //中文 private: System::Windows::Forms::Label^ label4; //“词性:” private: System::Windows::Forms::Label^ label5; //词性 private: System::Windows::Forms::Button^ button1; //“下一个”按钮 int times = 1; // 记录学习的单词个数
- 事件方法
- 构造函数:
Study(void) { InitializeComponent(); learnflag = true; //选择学习模式 RorL form; form.ShowDialog(); }
- 界面加载
private: System::Void Study_Load(System::Object^ sender, System::EventArgs^ e) { char** w; w = wordlist.GetRow(); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id,wd,ch,ty,false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; String^ chi = gcnew String(word.GetChinese().c_str()); this->label3->Text = chi; String^ typ = gcnew String(word.GetType().c_str()); this->label5->Text = typ; }
-
单击“下一个”按钮
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (times < stoi(member.GetUserDailyPlan()) && wordlist.GetNextRow() != NULL) { char** w; if (learningMode) { //顺序学习 w = wordlist.GetNextRow(); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; String^ chi = gcnew String(word.GetChinese().c_str()); this->label3->Text = chi; String^ typ = gcnew String(word.GetType().c_str()); this->label5->Text = typ; } else {//随机学习 if (times == 1) { //打乱顺序 random_shuffle(temp.begin(), temp.end()); } //获取单词 w = wordlist.GetRandomRow(temp[times] %wordlist.GetListLength()); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; String^ chi = gcnew String(word.GetChinese().c_str()); this->label3->Text = chi; String^ typ = gcnew String(word.GetType().c_str()); this->label5->Text = typ; } times++; } else { System::Windows::Forms::MessageBox::Show("学习完成,休息一下吧!", "学习完成"); time_t tt = time(NULL); tm* t = localtime(&tt); string year = to_string(t->tm_year + 1900); string month = to_string(t->tm_mon + 1); string day = to_string(t->tm_mday); string sqlInsert = "insert into " + member.GetUsername() + "(year, month, day) values('" + year + "', '" + month + "', '" + day + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (userConnect.ExecuteSql(Sql)) { } else { System::Windows::Forms::MessageBox::Show("连接失败,请重试!", "连接失败!"); } Study::Close(); } }
- 构造函数:
-
-
实现效果:
-
在主界面单击“学习新单词”按钮后,会弹出学习模式选择
Caption -
学习界面
Caption -
学习够指定计划数的单词,或单词表浏览完毕后弹出提示
Caption
-
-
-
复习测试
-
设计中的技巧
- 测试使用选择题的形式,分为英译汉、汉译英两种模式,选择窗口可以重用上一个的“RorL.h”,只需更改文字显示即可。
- 正确选项使用3以内随机数确定,其余选项从单词表中选取。
- 每选对一个单词(单击“下一个”)后,将该单词移动到对应已背完单词表:“用户名+finish”。
- 没有选对的单词(单击“下一个”)后,将该单词复制到对应生词表:“用户名+newword”。
- 当未检测单词数量不够选项数量时,从已背完单词表读取。
- 选择对错应有提示。
- 最后,在日计划完成或单词表计划完成后,将已记忆单词和生词表单词输出为文件。
-
“Review.h”
- 头文件引入”Word.h”; ”RorL.h”; “MySQLDbConn.h”; “User.h”; <algorithm>; <time.h>; <string>; <fstream>; <iostrream>
- 引入全局变量:member, wordlist, userConnect, word, temp, learnMode;
- 组件声明:
private: System::Windows::Forms::Label^ label1; //单词或中文 private: System::Windows::Forms::Button^ button1; //选项A private: System::Windows::Forms::Button^ button2; //选项B private: System::Windows::Forms::Button^ button3; //选项C private: System::Windows::Forms::Button^ button4; //“下一个”按钮 int times = 0; //测试次数 int choice; // 正确选项号 bool test; //单词学习状态 private: System::Windows::Forms::Label^ label2; //“A.” private: System::Windows::Forms::Label^ label3; //“B.” private: System::Windows::Forms::Label^ label4; //“C.”
- 事件方法
- 界面加载:
private: System::Void Review_Load(System::Object^ sender, System::EventArgs^ e) { if (learningMode) { //汉译英 char** w; w = wordlist.GetNextRow(); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; //随机选项设置 choice = rand() % 3 + 1; switch (choice) { case 1: { if (wordlist.GetListLength() <= 3) { //当列表中的数据不够提供选项时,从已测列表中读取; string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = userConnect.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = userConnect.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } else { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = wordlist.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = wordlist.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } } case 2: { if (wordlist.GetListLength() <= 3) { string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = userConnect.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = userConnect.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } else { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = wordlist.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = wordlist.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } } case 3: { if (wordlist.GetListLength() <= 3) { string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = userConnect.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = userConnect.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } else { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = wordlist.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = wordlist.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } } default: break; } } else { //英译汉 char** w; w = wordlist.GetNextRow(); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ chi = gcnew String(word.GetChinese().c_str()); this->label1->Text = chi; //随机选项设置 choice = rand() % 3 + 1; switch (choice) { case 1: { if (wordlist.GetListLength() <= 3) { string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = userConnect.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = userConnect.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } else { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = wordlist.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = wordlist.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } } case 2: { if (wordlist.GetListLength() <= 3) { string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = userConnect.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = userConnect.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } else { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = wordlist.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = wordlist.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } } case 3: { if (wordlist.GetListLength() <= 3) { string sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = userConnect.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = userConnect.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } else { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = wordlist.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = wordlist.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } } default: break; } } times++; }
-
单击选项A
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { switch (choice) { case 1: { //选对了 String^ correct = "O"; this->label2->Text = correct; this->label2->ForeColor = Color::Green; word.SetTest(true); int id = word.GetNum(); string wid = to_string(id); //更改数据库内容 string sqlInsert = "insert into " + member.GetUsername() + "finish(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } string deletesql = "delete from " + member.GetUserCurrentPlan() + " where id = " + wid; Sql = deletesql.c_str(); string sqlSelectw = "select * from " + member.GetUserCurrentPlan(); const char* Sqlw = sqlSelectw.c_str(); if(!wordlist.ExecuteQuerySql(Sqlw)) { System::Windows::Forms::MessageBox::Show("Connection Error!", "Error"); } if (wordlist.GetListLength() <= 0) { string sqlUpdate = "update " + member.GetUsername() + " set history = '" + member.GetUserCurrentPlan() + "'; where name = '" + member.GetUsername() + "'"; const char* Sqlu = sqlUpdate.c_str(); userConnect.ExecuteSql(Sqlu); System::Windows::Forms::MessageBox::Show("恭喜你本计划已学习完成!", "学习完成"); } else if (!wordlist.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 2: { String^ correct = "X"; this->label2->Text = correct; this->label2->ForeColor = Color::Red; this->button2->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 3: { String^ correct = "X"; this->label2->Text = correct; this->label2->ForeColor = Color::Red; this->button3->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } default: break; } }
-
单击选项B
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { switch (choice) { case 2: { String^ correct = "O"; this->label3->Text = correct; this->label3->ForeColor = Color::Green; word.SetTest(true); int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "finish(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } string deletesql = "delete from " + member.GetUserCurrentPlan() + " where id = " + wid; Sql = deletesql.c_str(); string sqlSelectw = "select * from " + member.GetUserCurrentPlan(); const char* Sqlw = sqlSelectw.c_str(); if (!wordlist.ExecuteQuerySql(Sqlw)) { System::Windows::Forms::MessageBox::Show("Connection Error!", "Error"); } if (wordlist.GetListLength() <= 0) { string sqlUpdate = "update " + member.GetUsername() + " set history = '" + member.GetUserCurrentPlan() + "'; where name = '" + member.GetUsername() + "'"; const char* Sqlu = sqlUpdate.c_str(); userConnect.ExecuteSql(Sqlu); System::Windows::Forms::MessageBox::Show("恭喜你本计划已学习完成!", "学习完成"); } else if (!wordlist.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 1: { String^ correct = "X"; this->label3->Text = correct; this->label3->ForeColor = Color::Red; this->button1->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 3: { String^ correct = "X"; this->label3->Text = correct; this->label3->ForeColor = Color::Red; this->button3->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } default: break; } }
-
单击选项C
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { switch (choice) { case 3: { String^ correct = "O"; this->label4->Text = correct; this->label4->ForeColor = Color::Green; word.SetTest(true); int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "finish(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } string deletesql = "delete from " + member.GetUserCurrentPlan() + " where id = " + wid; Sql = deletesql.c_str(); string sqlSelectw = "select * from " + member.GetUserCurrentPlan(); const char* Sqlw = sqlSelectw.c_str(); if (!wordlist.ExecuteQuerySql(Sqlw)) { System::Windows::Forms::MessageBox::Show("Connection Error!", "Error"); } if (wordlist.GetListLength() <= 0) { string sqlUpdate = "update " + member.GetUsername() + " set history = '" + member.GetUserCurrentPlan() + "'; where name = '" + member.GetUsername() + "'"; const char* Sqlu = sqlUpdate.c_str(); userConnect.ExecuteSql(Sqlu); System::Windows::Forms::MessageBox::Show("恭喜你本计划已学习完成!", "学习完成"); } else if (!wordlist.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 2: { String^ correct = "X"; this->label4->Text = correct; this->label4->ForeColor = Color::Red; this->button2->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } case 1: { String^ correct = "X"; this->label4->Text = correct; this->label4->ForeColor = Color::Red; this->button1->ForeColor = Color::Green; int id = word.GetNum(); string wid = to_string(id); string sqlInsert = "insert into " + member.GetUsername() + "newword(id, word, chinese, type) values(" + wid + ", '" + word.Getword() + "', '" + word.GetChinese() + "', '" + word.GetType() + "');"; const char* Sql = nullptr; Sql = sqlInsert.c_str(); if (!userConnect.ExecuteSql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error", "Error!"); } break; } default: break; } }
-
单击“下一个”按钮
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { //恢复按钮和提示 this->label2->Text = "A."; this->label2->ForeColor = Color::Black; this->label3->Text = "B."; this->label3->ForeColor = Color::Black; this->label4->Text = "C."; this->label4->ForeColor = Color::Black; this->button1->ForeColor = Color::Black; this->button2->ForeColor = Color::Black; this->button3->ForeColor = Color::Black; if (word.GetTest()) { //输出上一个单词 ofstream outfile; string write = to_string(word.GetNum()) + "\t" + word.Getword() + "\t" + word.GetChinese() + "\t" + word.GetType() + "\n"; outfile.open("E:\\DATA\\Finish_wordlist.txt", ios::out | ios::app); if (!outfile.is_open()) { System::Windows::Forms::MessageBox::Show("文件创建失败,请重试!", "文件创建失败!"); } else { outfile << write; outfile.close(); } } else { ofstream outfile; string write = to_string(word.GetNum()) + "\t" + word.Getword() + "\t" + word.GetChinese() + "\t" + word.GetType() + "\n"; outfile.open("E:\\DATA\\New_wordlist.txt", ios::out | ios::app); if (!outfile.is_open()) { System::Windows::Forms::MessageBox::Show("文件创建失败,请重试!", "文件创建失败!"); } else { outfile << write; outfile.close(); } } if (times < stoi(member.GetUserDailyPlan())) { if (learningMode) { string sqlSelectw = "select * from " + member.GetUserCurrentPlan(); const char* Sqlw = sqlSelectw.c_str(); wordlist.ExecuteQuerySql(Sqlw); if (wordlist.GetListLength() > 0) { if (wordlist.GetListLength() >= 3) { char** w; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; choice = rand() % 3 + 1; switch (choice) { case 1: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } case 2: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } case 3: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } default: break; } } else { sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); char** w; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; choice = rand() % 3 + 1; switch (choice) { case 1: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = userConnect.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = userConnect.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } case 2: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = userConnect.GetNextRow(); string choice1 = w[2]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = userConnect.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } case 3: { string answer = w[2]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = userConnect.GetNextRow(); string choice2 = w[2]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = userConnect.GetNextRow(); string choice3 = w[2]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } default: break; } } } else { string sqlUpdate = "update " + member.GetUsername() + " set history = '" + member.GetUserCurrentPlan() + "'; where name = '" + member.GetUsername() + "'"; const char* Sqlu = sqlUpdate.c_str(); userConnect.ExecuteSql(Sqlu); System::Windows::Forms::MessageBox::Show("恭喜你本计划已学习完成!", "学习完成"); Review::Close(); } } else { string sqlSelectw = "select * from " + member.GetUserCurrentPlan(); const char* Sqlw = sqlSelectw.c_str(); wordlist.ExecuteQuerySql(Sqlw); if (wordlist.GetListLength()) { if (wordlist.GetListLength() >= 3) { char** w; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.GetChinese().c_str()); this->label1->Text = wrd; choice = rand() % 3 + 1; switch (choice) { case 1: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } case 2: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } case 3: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } default: break; } } else { sqlSelectw = "select * from " + member.GetUsername() + "finish"; const char* Sqlwd = sqlSelectw.c_str(); userConnect.ExecuteQuerySql(Sqlwd); char** w; w = wordlist.GetRandomRow((times++) % wordlist.GetListLength()); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.GetChinese().c_str()); this->label1->Text = wrd; choice = rand() % 3 + 1; switch (choice) { case 1: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button1->Text = an; w = userConnect.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button2->Text = ch1; w = userConnect.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button3->Text = ch2; break; } case 2: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button2->Text = an; w = userConnect.GetNextRow(); string choice1 = w[1]; String^ ch1 = gcnew String(choice1.c_str()); this->button3->Text = ch1; w = userConnect.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button1->Text = ch3; break; } case 3: { string answer = w[1]; String^ an = gcnew String(answer.c_str()); this->button3->Text = an; w = userConnect.GetNextRow(); string choice2 = w[1]; String^ ch2 = gcnew String(choice2.c_str()); this->button1->Text = ch2; w = userConnect.GetNextRow(); string choice3 = w[1]; String^ ch3 = gcnew String(choice3.c_str()); this->button2->Text = ch3; break; } default: break; } } } else { string sqlUpdate = "update " + member.GetUsername() + " set history = '" + member.GetUserCurrentPlan() + "'; where name = '" + member.GetUsername() + "'"; const char* Sqlu = sqlUpdate.c_str(); userConnect.ExecuteSql(Sqlu); System::Windows::Forms::MessageBox::Show("恭喜你本计划已学习完成!", "学习完成"); Review::Close(); } } } else { System::Windows::Forms::MessageBox::Show("学习完成,休息一下吧!", "学习完成"); Review::Close(); } }
- 界面加载:
-
成果展示
-
单击“复习旧单词”按钮后,选择测试模式
Caption -
汉译英模式
Caption -
英译汉模式
Caption -
选择正确与错误都会在选项上有所提示
-
用户记忆完的单词会存在“用户名+finish”中
Caption -
生词表的单词会存在“用户名+newword”中
Caption -
已记忆的单词会存在“Finish_wordlist.txt”
Caption -
生词表的单词会存在“New_wordlist.txt”;
Caption
-
-
-
生词表
-
设计中的技巧
- 套用学习新单词的界面设计,功能相似。
-
“Study.h”
- 头文件:同”Study.h”
- 引入全局变量:同”Study.h”
- 组件声明:同”Study.h”
- 事件方法:与”Study.h”基本相同
- 界面加载
private: System::Void Study1_Load(System::Object^ sender, System::EventArgs^ e) { string sqlSelect = "select * from " + member.GetUsername() + "newword"; const char* Sql = sqlSelect.c_str(); if (!userConnect.ExecuteQuerySql(Sql)) { System::Windows::Forms::MessageBox::Show("Connection Error!", "Error"); } else { char** w; w = userConnect.GetRow(); if (w != NULL) { int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; String^ chi = gcnew String(word.GetChinese().c_str()); this->label3->Text = chi; String^ typ = gcnew String(word.GetType().c_str()); this->label5->Text = typ; } else { System::Windows::Forms::MessageBox::Show("没有生词!请回吧!", "无生词"); Study1::Close(); } } times++; }
-
单击“下一个”按钮
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int count = userConnect.GetListLength(); if (times < count && times < stoi(member.GetUserDailyPlan())) { char** w; w = userConnect.GetNextRow(); int id = atoi(w[0]); string wd = w[1]; string ch = w[2]; string ty = w[3]; word.SetWord(id, wd, ch, ty, false); String^ wrd = gcnew String(word.Getword().c_str()); this->label1->Text = wrd; String^ chi = gcnew String(word.GetChinese().c_str()); this->label3->Text = chi; String^ typ = gcnew String(word.GetType().c_str()); this->label5->Text = typ; times++; } else { System::Windows::Forms::MessageBox::Show("学习完成,休息一下吧!", "学习完成"); } }
- 界面加载
-
成果展示
-
生词表学习与学习新单词模式一样
Caption
-
-
下期预告:查看历史记录。