Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Data;
  4. using System.Windows.Input;
  5. using System.Linq;
  6. using System.Data.Linq;
  7. using System.Collections;
  8.  
  9. namespace Assignment_7
  10. {
  11.  
  12. /// <summary>
  13. /// Interaction logic for MainWindow.xaml
  14. /// </summary>
  15. public partial class MainWindow : Window
  16. {
  17. static string conString = "Data Source=tod112.hib.no,1443;Initial Catalog=tod112;Persist Security Info=True;User ID=tod112;Password=tod112";
  18. static DataClasses1DataContext database = new DataClasses1DataContext(conString);
  19. static IQueryable<course> allCourses = from a in database.GetTable<course>() select a;
  20. static IQueryable<student> allStudents = from a in database.GetTable<student>() select a;
  21. static IQueryable<grade> allGrades = from a in database.GetTable<grade>() select a;
  22. public MainWindow()
  23. {
  24.  
  25. InitializeComponent();
  26.  
  27.  
  28. // var allStudents = from a in database.GetTable<student>() select a;
  29.  
  30. listView1.ItemsSource = allStudents;
  31.  
  32. // listBoxCourses.ItemsSource = courses;
  33. //listBoxCourses.DisplayMemberPath = "coursename";
  34.  
  35. //Binds the different fields in the gridview to the collumnames in the DB.
  36. gridViewID.DisplayMemberBinding = new Binding("id");
  37. gridViewName.DisplayMemberBinding = new Binding("studentname");
  38. gridViewAge.DisplayMemberBinding = new Binding("studentage");
  39. gridViewGrade.DisplayMemberBinding = new Binding("");
  40.  
  41.  
  42. // var allCourses = from a in database.GetTable<course>() select a;
  43.  
  44. courseListView.ItemsSource = allCourses;
  45. courseID.DisplayMemberBinding = new Binding("coursecode");
  46. courseName.DisplayMemberBinding = new Binding("coursename");
  47. courseSemester.DisplayMemberBinding = new Binding("semester");
  48. courseTeacher.DisplayMemberBinding = new Binding("teacher");
  49.  
  50.  
  51. }
  52.  
  53.  
  54. private void buttonSearch_Click(object sender, RoutedEventArgs e)
  55. {
  56. string searchString = textBoxSearch.Text;
  57.  
  58. var searching = from a in allStudents where a.studentname.StartsWith(searchString) select a;
  59.  
  60. listView1.ItemsSource = searching;
  61. }
  62.  
  63. private void button_Click(object sender, RoutedEventArgs e)
  64. {
  65. // TODO
  66. }
  67.  
  68. private void listBoxCourses_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  69. {
  70. // TODO: Sender is listboxviewitem
  71. ListBoxItem item = sender as ListBoxItem;
  72. }
  73.  
  74. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  75. {
  76.  
  77.  
  78. if (courseListView.SelectedItems.Count>0) {
  79. var itemSelected = e.AddedItems;
  80.  
  81.  
  82. var queryAllStudentInSelectedCourse = from stud in allStudents
  83. from course in allCourses
  84.  
  85.  
  86. select a;
  87.  
  88.  
  89.  
  90. }
  91.  
  92.  
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement