private void Btn_AddTopic_Click(object sender, RoutedEventArgs e) { try { var data = DbUtility.ReadXml <ObservableCollection <Topic> >("Topics.xml"); var topic = new ObservableCollection <Topic>(); Topic ts = new Topic(); XmlDocument doc = new XmlDocument(); doc.Load("Topics.xml"); int count = 1; foreach (XmlNode xn in doc.SelectNodes("ArrayOfTopic/Topic")) { count = count + 1; } string topicid = Convert.ToString(count); ts.TopicId = topicid; ts.TopicTitle = TopicName.Text; { data.Add(ts); DbUtility.WriteXml <ObservableCollection <Topic> >(data, "Topics.xml"); MessageBox.Show("Topic Successfully Added"); var gobacktomain = new MainWindow(); gobacktomain.Show(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Btn_UpdateTopic_Click(object sender, RoutedEventArgs e) { var pro = DbUtility.ReadXml <ObservableCollection <Topic> >("Topics.xml"); var topic = new ObservableCollection <Topic>(); var tp = pro.First(f => f.TopicId == Topicid.Text); tp.TopicTitle = TopicName.Text; DbUtility.WriteXml <ObservableCollection <Topic> >(pro, "Topics.xml"); MessageBox.Show("Topic Successfully Updated"); var addtopic = new AddTopic(); addtopic.Show(); this.Close(); }
private void Btn_UpdateQuestion_Click(object sender, RoutedEventArgs e) { var pro = DbUtility.ReadXml <ObservableCollection <Question> >("Questions.xml"); var question = new ObservableCollection <Question>(); var qs = pro.First(f => f.QuestionId == Questionid.Text); qs.QuestionTitle = Question.Text; qs.OptionA = OptionA.Text; qs.OptionB = OptionB.Text; qs.OptionC = OptionC.Text; qs.OptionD = OptionD.Text; qs.CorectionAnswer = CorrectAnswer.Text; DbUtility.WriteXml <ObservableCollection <Question> >(pro, "Questions.xml"); MessageBox.Show("Question Successfully Updated"); var manageQuestion = new ManageQuestion(); manageQuestion.Show(); this.Close(); }
private void Btn_AddQuestion_Click(object sender, RoutedEventArgs e) { try { var data = DbUtility.ReadXml <ObservableCollection <Question> >("Questions.xml"); var question = new ObservableCollection <Question>(); Question qs = new Question(); qs.TopicId = topicid; XmlDocument doc = new XmlDocument(); doc.Load("Questions.xml"); int count = 1; foreach (XmlNode xn in doc.SelectNodes("ArrayOfQuestion/Question")) { count = count + 1; } string questionid = Convert.ToString(count); qs.QuestionId = questionid; qs.QuestionTitle = Question.Text; qs.OptionA = OptionA.Text; qs.OptionB = OptionB.Text; qs.OptionC = OptionC.Text; qs.OptionD = OptionD.Text; qs.CorectionAnswer = CorrectAnswer.Text; Random random = new Random(); var code = Convert.ToString(random.Next(999, 10000)); qs.QuestionCode = code; { data.Add(qs); DbUtility.WriteXml <ObservableCollection <Question> >(data, "Questions.xml"); MessageBox.Show("Question Successfully Added"); var gobacktomain = new MainWindow(); gobacktomain.Show(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }