//==================================Additional functions==================================== //========================================================================================== //Load data from sql server public void loadData() { //Load topic BOTopic bot = new BOTopic(); topicList = bot.ListAll(); cbbTopic.DataSource = topicList; //Load questions and answers BOQuestion boq = new BOQuestion(); BOAnswer boa = new BOAnswer(); answerList = boa.ListAll(); questionList = boq.ListAll(); for (int i = 0; i < questionList.Count; i++) { questionList[i].Answers = new List<Answer>(); for (int j = 0; j < answerList.Count; j++) if (answerList[j].QCode == questionList[i].Code) { questionList[i].Answers.Add(answerList[j]); } } }
private void btUpdate_Click(object sender, EventArgs e) { int i = lbQuestion.SelectedIndex; if (i == -1) { MessageBox.Show("Select a question to change"); return; }else if(txtCode.Text.Equals("")) { MessageBox.Show("Question code must not be empty!!!"); return; } else { int n = questionList[lbQuestion.SelectedIndex].Code; if ( n==Convert.ToInt32(txtCode.Text)||codeList.Contains(Convert.ToInt32(txtCode.Text))==false) { if (input() != null) { BOQuestion boq = new BOQuestion(); boq.Update(input(),n); clearInfo(); } } else { MessageBox.Show("The question code has been existed!!!"); return; } } }
private void btDelete_Click(object sender, EventArgs e) { int index = lbQuestion.SelectedIndex; if (index == -1) { MessageBox.Show("Select a question to delete"); return; } else { BOQuestion boq = new BOQuestion(); boq.Delete(questionList[index]); loadData(); clearInfo(); } }
//Save data to the sql database public void saveData(Question q) { BOQuestion boq = new BOQuestion(); BOAnswer boa = new BOAnswer(); boq.Add(q); }