private void DeleteQuestion_Click(object sender, RoutedEventArgs e) { try { if (DatGridDisplayQuestion.SelectedItem != null) { var questionId = int.Parse(DatGridDisplayQuestion.SelectedValue.ToString()); QuestionPool question = (from Q in context.QuestionPools where Q.ID == questionId select Q).Single(); if (question.Type == "Text") { var ID = new SqlParameter("@QuestionPoolID", question.ID); var Type = new SqlParameter("@QuestionType", question.Type); var result = context.Database.SqlQuery <string>(" exec DeleteQuestionpool @QuestionPoolID, @QuestionType ", ID, Type).FirstOrDefault(); if (string.Compare(result, "delete succefully") == 0) { MessageBox.Show("Deleted"); LoadTextQuestion(DatGridDisplayQuestion, Displaycourse); } } else if (question.Type == "MCQ") { var ID = new SqlParameter("@QuestionPoolID", question.ID); var Type = new SqlParameter("@QuestionType", question.Type); var result = context.Database.SqlQuery <string>(" exec DeleteQuestionpool @QuestionPoolID, @QuestionType ", ID, Type).FirstOrDefault(); if (string.Compare(result, "delete succefully") == 0) { MessageBox.Show("Deleted"); LoadMcqQuestion(DatGridDisplayQuestion, Displaycourse); } } else if (question.Type == "True/False") { var ID = new SqlParameter("@QuestionPoolID", question.ID); var Type = new SqlParameter("@QuestionType", question.Type); var result = context.Database.SqlQuery <string>(" exec DeleteQuestionpool @QuestionPoolID, @QuestionType ", ID, Type).FirstOrDefault(); if (string.Compare(result, "delete succefully") == 0) { MessageBox.Show("Deleted"); LoadTrueFalseQuestion(DatGridDisplayQuestion, Displaycourse); } } } else { MessageBox.Show("please select the question you want delete"); } } catch { MessageBox.Show("something wrong"); } }
private void BtnaddChoise(object sender, RoutedEventArgs e) { try { var questionId = int.Parse(DGridDisplayUpdateQuestion.SelectedValue.ToString()); QuestionPool question = (from Q in context.QuestionPools where Q.ID == questionId select Q).Single(); bool ans; if (TextBoxUpdateChoiseAnswer.Text == "") { MessageBox.Show("you must write in textbox the choise you want to add "); } else { if (UpdateTrueChoiseAnswer.IsChecked == true) { ans = true; } else { ans = false; } context.Choices.Add(new Choice() { Body = TextBoxUpdateChoiseAnswer.Text, Answer = ans, QuestionPoolID = question.ID }); context.SaveChanges(); LoadChoise(questionId); } } catch { MessageBox.Show("please check input data"); } }
private void Updatequestion_Click(object sender, RoutedEventArgs e) { try { if (DGridDisplayUpdateQuestion.SelectedItem != null) { var questionselected = int.Parse(DGridDisplayUpdateQuestion.SelectedValue.ToString()); QuestionPool question = (from Q in context.QuestionPools where Q.ID == questionId select Q).Single(); if (UpdateQuestionBody.Text != null) { if (UpdateQuestionHeader.Text != null) { if (question.Type == "Text") { if (TextboxUpdateQuestionAnswer.Text != null) { GridUpdateTrueFalseAnswer.Visibility = Visibility.Collapsed; GridUpdateMcqAnswer.Visibility = Visibility.Collapsed; GridUpdateTextAnswer.Visibility = Visibility.Visible; GridAddDeleteChoise.Visibility = Visibility.Collapsed; var ID = new SqlParameter("@QuestionPoolID", question.ID); var Body = new SqlParameter("@QuestionBody", UpdateQuestionBody.Text); var Header = new SqlParameter("@QuestionHeader", UpdateQuestionHeader.Text); var Answer = new SqlParameter("@QuestionAnswer", TextboxUpdateQuestionAnswer.Text); var result = context.Database.SqlQuery <string>(" exec updateTextQuestion @QuestionPoolID, @QuestionBody,@QuestionHeader,@QuestionAnswer ", ID, Body, Header, Answer).FirstOrDefault(); if (string.Compare(result, "Update Succefully") == 0) { MessageBox.Show("Updated"); LoadTextQuestion(DGridDisplayUpdateQuestion, DisplaycourseUpdate); } } else { MessageBox.Show("you must add the answer of th question"); } } else if (question.Type == "True/False") { GridUpdateTrueFalseAnswer.Visibility = Visibility.Visible; GridUpdateMcqAnswer.Visibility = Visibility.Collapsed; GridUpdateTextAnswer.Visibility = Visibility.Collapsed; GridAddDeleteChoise.Visibility = Visibility.Collapsed; var ID = new SqlParameter("@QuestionPoolID", question.ID); var Body = new SqlParameter("@QuestionBody", UpdateQuestionBody.Text); var Header = new SqlParameter("@QuestionHeader", UpdateQuestionHeader.Text); if (UpdateTrueAnswer.IsChecked == true) { var Answer = new SqlParameter("@QuestionAnswer", "True"); var result = context.Database.SqlQuery <string>(" exec updateTruefalseQuestion @QuestionPoolID, @QuestionBody,@QuestionHeader,@QuestionAnswer ", ID, Body, Header, Answer).FirstOrDefault(); if (string.Compare(result, "Update Succefully") == 0) { MessageBox.Show("Updated"); LoadTrueFalseQuestion(DGridDisplayUpdateQuestion, DisplaycourseUpdate); } } else if (UpdateFalseAnswer.IsChecked == true) { var Answer = new SqlParameter("@QuestionAnswer", "False"); var result = context.Database.SqlQuery <string>(" exec updateTruefalseQuestion @QuestionPoolID, @QuestionBody,@QuestionHeader,@QuestionAnswer ", ID, Body, Header, Answer).FirstOrDefault(); if (string.Compare(result, "Update Succefully") == 0) { MessageBox.Show("Updated"); LoadTrueFalseQuestion(DGridDisplayUpdateQuestion, DisplaycourseUpdate); } } else { MessageBox.Show("you must check the answer of question"); } } else if (question.Type == "MCQ") { GridUpdateTrueFalseAnswer.Visibility = Visibility.Collapsed; GridUpdateMcqAnswer.Visibility = Visibility.Visible; GridUpdateTextAnswer.Visibility = Visibility.Collapsed; GridAddDeleteChoise.Visibility = Visibility.Visible; var ID = new SqlParameter("@QuestionPoolID", question.ID); var Body = new SqlParameter("@QuestionBody", UpdateQuestionBody.Text); var Header = new SqlParameter("@QuestionHeader", UpdateQuestionHeader.Text); var result = context.Database.SqlQuery <string>(" exec updateMcqQuestion @QuestionPoolID, @QuestionBody,@QuestionHeader ", ID, Body, Header).FirstOrDefault(); if (string.Compare(result, "Update Succefully") == 0) { MessageBox.Show("Updated"); LoadMcqQuestion(DGridDisplayUpdateQuestion, DisplaycourseUpdate); } } } else { MessageBox.Show("you must enter Header of the question you want updated"); } } else { MessageBox.Show("you must enter Body of the question you want updated"); } } else { MessageBox.Show("you must select question you want update"); } } catch { MessageBox.Show("please check the input data"); } }
private void AddQuestion(object sender, RoutedEventArgs e) { try { if (DisplaycourseAdd.SelectedItem != null) { var id = (from c in context.Courses where c.Name == DisplaycourseAdd.SelectedItem.ToString() select c.ID).FirstOrDefault(); questionPool = new QuestionPool(); if (QuestionBody.Text != "") { questionPool.Body = QuestionBody.Text; questionPool.CourseID = id; if (AddQuestionType.Text != "") { questionPool.Type = AddQuestionType.Text; context.QuestionPools.Add(questionPool); context.SaveChanges(); if (QuestionHeader.Text != "") { if (AddQuestionType.SelectedIndex == 0) { if (textBox.Text != "") { var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", (textBox.Text)); var result = context.Database.SqlQuery <string>(" exec addTextQuestion @questionpoolId, @Header,@Answer ", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } else { MessageBox.Show("you must add answer of question"); } } else if (AddQuestionType.SelectedIndex == 1) { var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var result = context.Database.SqlQuery <string>(" exec addMcqQuestion @questionpoolId, @Header", QuestionPoolID, header).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { foreach (var item in choices) { item.QuestionPoolID = questionPool.ID; context.Choices.Add(item); } MessageBox.Show("added"); } } else if (AddQuestionType.SelectedIndex == 2) { if (TrueAnswer.IsChecked == true) { var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", "True"); var result = context.Database.SqlQuery <string>(" exec AddTrueFalseQuestionPool @questionpoolId, @Header,@Answer", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } else if (FalseAnswer.IsChecked == true) { var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", "False"); var result = context.Database.SqlQuery <string>(" exec AddTrueFalseQuestionPool @questionpoolId, @Header,@Answer ", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } } } else { MessageBox.Show("You must add Header To question"); } } else { MessageBox.Show("You must add choise type of question"); } } else { MessageBox.Show("You must add Body To question"); } } context.SaveChanges(); } catch { MessageBox.Show("You must Enter input Correctly"); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (Displaycourse.SelectedItem != null) { var id = (from c in context.Courses where c.Name == Displaycourse.SelectedItem.ToString() select c.ID).FirstOrDefault(); QuestionPool questionPool = new QuestionPool(); // if(QuestionBody.Text=="") questionPool.Body = QuestionBody.Text; questionPool.CourseID = id; questionPool.Type = QuestionType.Text; context.QuestionPools.Add(questionPool); context.SaveChanges(); if (QuestionType.SelectedIndex == 0) { answerText.SetValue(Panel.ZIndexProperty, 1);//.Visibility = true; TrueFalseAnswer.SetValue(Panel.ZIndexProperty, 0); var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", (answerText.Text)); var result = context.Database.SqlQuery <string>(" exec addTextQuestion @questionpoolId, @Header,@Answer ", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } else if (QuestionType.SelectedIndex == 1) { AddedMCQ = new McqQuestion(); AddedMCQ.QuestionPoolID = questionPool.ID; var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var result = context.Database.SqlQuery <string>(" exec addMcqQuestion @questionpoolId, @Header", QuestionPoolID, header).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } else if (QuestionType.SelectedIndex == 2) { if (TrueAnswer.IsChecked == true) { var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", "True"); var result = context.Database.SqlQuery <string>(" exec AddTrueFalseQuestionPool @questionpoolId, @Header,@Answer ", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } else if (FalseAnswer.IsChecked == true) { //trueFalseQuestion.Answer = false; var QuestionPoolID = new SqlParameter("@questionpoolId", questionPool.ID); var header = new SqlParameter("@Header", QuestionHeader.Text); var answer = new SqlParameter("@Answer", "False"); var result = context.Database.SqlQuery <string>(" exec AddTrueFalseQuestionPool @questionpoolId, @Header,@Answer ", QuestionPoolID, header, answer).FirstOrDefault(); if (string.Compare(result, "added sucessfully") == 0) { MessageBox.Show("added"); } } } context.SaveChanges(); } }