Advertisement
Guest User

Main Window

a guest
Oct 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using BusinessObjects;
  15.  
  16. namespace Demo
  17. {
  18. /// <summary>
  19. /// Interaction logic for MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. private ModuleList store = new ModuleList();
  24. private Student s;
  25.  
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. }
  30.  
  31.  
  32. private void btnAdd_Click(object sender, RoutedEventArgs e)
  33. {
  34.  
  35. s = new Student();
  36.  
  37. //Store textbox text to the student properties
  38. //s.Matric = Int32.Parse(txtMatric.Text);
  39.  
  40.  
  41.  
  42. if ((int.Parse(txtMatric.Text) <10001 || int.Parse(txtMatric.Text) >50000) || txtMatric.Text.Length == 0)
  43. {
  44. lblContents.Content ="Invalid input";
  45. }
  46. else
  47. {
  48. s.Matric = int.Parse(txtMatric.Text);
  49. txtMatric.Text = String.Empty;
  50. }
  51.  
  52. if (txtFirstName.Text.Length == 0)
  53. {
  54. lblContents.Content = "Invalid Input";
  55. }
  56. else
  57. {
  58. s.firstName = txtFirstName.Text;
  59. txtFirstName.Text = String.Empty;
  60. }
  61.  
  62. if (txtSurname.Text.Length == 0)
  63. {
  64. lblContents.Content = "Invalid Input";
  65. }
  66. else
  67. {
  68. s.Surname = txtSurname.Text;
  69. txtSurname.Text = String.Empty;
  70. }
  71.  
  72. if (txtDate_Of_Birth.Text.Length == 0)
  73. {
  74. lblContents.Content = "Invalid Input";
  75. }
  76.  
  77. else
  78. {
  79. s.dateOfBirth = txtDate_Of_Birth.Text;
  80. txtDate_Of_Birth.Text = String.Empty;
  81. }
  82.  
  83. if ((int.Parse(txtCourseworkMark.Text) < 0 || int.Parse(txtCourseworkMark.Text) > 20) || txtCourseworkMark.Text.Length == 0)
  84. {
  85. lblContents.Content = "Invalid Input";
  86. }
  87. else
  88. {
  89. s.courseworkMark = int.Parse(txtCourseworkMark.Text);
  90. txtCourseworkMark.Text = String.Empty;
  91. }
  92.  
  93. if ((int.Parse(txtExamMark.Text) < 0 || int.Parse(txtExamMark.Text) > 40) || txtExamMark.Text.Length == 0)
  94. {
  95. lblContents.Content = "Invalid Input";
  96. }
  97. else
  98. {
  99. s.examMark = int.Parse(txtExamMark.Text);
  100. txtExamMark.Text = String.Empty;
  101. }
  102.  
  103.  
  104. store.add(s);
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. //s.firstName = txtFirstName.Text;
  114. //s.Surname = txtSurname.Text;
  115. //s.courseworkMark = Double.Parse(txtCourseworkMark.Text);
  116. //s.examMark = Double.Parse(txtExamMark.Text);
  117. //s.dateOfBirth = txtDate_Of_Birth.Text;
  118.  
  119.  
  120.  
  121.  
  122. ////Check if the data inputted in valid
  123. //if ((s.Matric >= 10001 & s.Matric <= 50000) )
  124. //{
  125. // S
  126. // //Student added to the store
  127. // store.add(s);
  128.  
  129. // //Textbox text cleared
  130. // txtMatric.Text = String.Empty;
  131. // txtFirstName.Text = String.Empty;
  132. // txtSurname.Text = String.Empty;
  133. // txtCourseworkMark.Text = String.Empty;
  134. // txtDate_Of_Birth.Text = String.Empty;
  135. // txtExamMark.Text = String.Empty;
  136. //}
  137.  
  138.  
  139. ////Display message indicating that the data inputted is not valid
  140. //else
  141. //{
  142. // lblContents.Content = "Data inputted is not valid";
  143. //}
  144.  
  145.  
  146.  
  147.  
  148. }
  149.  
  150. //Find matric number and store the matric number to the form.
  151. private void btnFind_Click(object sender, RoutedEventArgs e)
  152. {
  153. s = new Student();
  154. int matricNumber = Int32.Parse(txtMatric.Text);
  155. s = store.find(matricNumber);
  156. lblContents.Content = s.Matric + " " + s.firstName + " " + s.Surname + " " + s.courseworkMark + " " + s.examMark + " " + s.getMark();
  157.  
  158.  
  159.  
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement