private void remove_Click_4(object sender, RoutedEventArgs e) { int id = qselected.IDeas; string type = qselected.Type; if (questionss.SelectedItem != null) { Quesition tt = (Quesition)questionss.SelectedItem; var quet = (from quesst in context2.questions where quesst.QustCode == tt.IDeas select quesst).FirstOrDefault(); questionss.Items.Remove(questionss.SelectedItem); context2.questions.Remove(quet); context2.SaveChanges(); } else { MessageBox.Show("false"); } }
private void questionCourse_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { questionss.Items.Clear(); var CourseName = sender as ComboBox; var CourseNName = CourseName.SelectedItem.ToString(); //MessageBox.Show(CourseName.SelectedItem.ToString()); var query = (from Idcourse in context2.courses where Idcourse.Name == CourseNName select Idcourse.CourseId).FirstOrDefault(); var query2 = (from coursee in context2.course_question where query == coursee.Course_ID select coursee.Qust_codr).ToList(); var query3 = (from questions in context2.questions where query2.Contains(questions.QustCode) select questions).ToList(); List <Quesition> ListOfClassQuesitions = new List <Quesition>(); foreach (var item in query3) { //Question.Degree = item.Degree; //Question.type = item.type; if (item.type == "text") { var query4 = (from questions in context2.questions join textQuestion in context2.textquestions on questions.QustCode equals textQuestion.QustCode where questions.QustCode == item.QustCode select textQuestion.question).FirstOrDefault(); Quesition ClassQuestion = new Quesition(); ClassQuestion.IDeas = int.Parse(item.QustCode.ToString()); ClassQuestion.Degree = int.Parse(item.Degree.ToString()); ClassQuestion.Type = item.type; ClassQuestion.TextQuesition = query4; ListOfClassQuesitions.Add(ClassQuestion); } else if (item.type == "MSQ") { var query4 = (from questions in context2.questions join mcq in context2.multichoices on questions.QustCode equals mcq.QustCode select mcq.question).FirstOrDefault(); Quesition ClassQuestion = new Quesition(); ClassQuestion.IDeas = int.Parse(item.QustCode.ToString()); ClassQuestion.Degree = int.Parse(item.Degree.ToString()); ClassQuestion.Type = item.type; ClassQuestion.TextQuesition = query4; ListOfClassQuesitions.Add(ClassQuestion); } else if (item.type == "true&false") { var query4 = (from questions in context2.questions join tf in context2.qtruefalses on questions.QustCode equals tf.QustCode select tf.question).FirstOrDefault(); Quesition ClassQuestion = new Quesition(); ClassQuestion.IDeas = int.Parse(item.QustCode.ToString()); ClassQuestion.Degree = int.Parse(item.Degree.ToString()); ClassQuestion.Type = item.type; ClassQuestion.TextQuesition = query4.ToString(); ListOfClassQuesitions.Add(ClassQuestion); } } foreach (var item in ListOfClassQuesitions) { questionss.Items.Add(item); // questionss.Items.Clear(); } // questionss.ItemsSource = ListOfClassQuesitions; }
private void questionss_SelectionChanged(object sender, SelectionChangedEventArgs e) { qselected = questionss.SelectedItem as Quesition; }