public void clsCourse() { String strConnection = "server= localhost;database=tafeprojectC;Trusted_Connection=yes"; List <clsCourse> list = new List <clsCourse>(); SqlConnection objConnection = new SqlConnection(strConnection); objConnection.Open(); SqlCommand objCommand = new SqlCommand("select * from course", objConnection); SqlDataReader objDataReader = objCommand.ExecuteReader(); while (objDataReader.Read()) { clsCourse objCourse = new clsCourse(); objCourse.CourseId = objDataReader.GetInt32(objDataReader.GetOrdinal("CourseId")); objCourse.CourseName = objDataReader.GetString(objDataReader.GetOrdinal("CourseName")); //objCourse.CourseDuradion = objDataReader.GetInt32(objDataReader.GetOrdinal("CourseDuration")); list.Add(objCourse); } list.Sort(delegate(clsCourse x, clsCourse y) { return(x.CourseId - y.CourseId); }); foreach (clsCourse objCourse in list) { Console.WriteLine(objCourse.ToString()); } }
private void btnSearch_Click(object sender, RoutedEventArgs e) { //Course Id validation if (clsValidation.ValidateForEmptiness(TxtCourseId.Text) == false) { MessageBox.Show("Course id is required"); } else if (clsValidation.ValidateForNumeric(TxtCourseId.Text) == false) { MessageBox.Show("Course id is not a number"); } else if (clsValidation.ValidateForLength(TxtCourseId.Text, 5) == false) { MessageBox.Show("Course id is not 5 digits"); } else { clsCourse ObjCourse = new clsCourse(); ObjCourse.CourseId = int.Parse(TxtCourseId.Text); bool found = ObjCourse.SearchCourse(); if (found) { MessageBox.Show("Success to search this Course"); TxtCourseId.Text = ObjCourse.CourseId.ToString(); TxtCourseName.Text = ObjCourse.CourseName.ToString(); LabCourseModes.Content = ObjCourse.CourseModes.ToString(); if ("FullTime".Equals(ObjCourse.CourseModes)) { RadioFullTime.IsChecked = true; } else if ("PartTime".Equals(ObjCourse.CourseModes)) { RadioPartTime.IsChecked = true; } else { RadioOnline.IsChecked = true; } } else { MessageBox.Show("This Course id does not exist"); TxtCourseName.Text = ""; RadioFullTime.IsChecked = true; } } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { //Course Id validation if (clsValidation.ValidateForEmptiness(TxtCourseId.Text) == false) { MessageBox.Show("Course id is required"); } else if (clsValidation.ValidateForNumeric(TxtCourseId.Text) == false) { MessageBox.Show("Course id is not a number"); } else if (clsValidation.ValidateForLength(TxtCourseId.Text, 5) == false) { MessageBox.Show("Course id is not 5 digits"); } //Course Name validation else if (clsValidation.ValidateForEmptiness(TxtCourseName.Text) == false) { MessageBox.Show("Course name is required"); } else { String CourseModes = ""; if (RadioFullTime.IsChecked == true) { CourseModes = "FullTime"; } else if (RadioPartTime.IsChecked == true) { CourseModes = "PartTime"; } else { CourseModes = "Online"; } clsCourse ObjCourse = new clsCourse(int.Parse(TxtCourseId.Text), TxtCourseName.Text, CourseModes); int Courseid = ObjCourse.AddCourse(); if (Courseid == -1) { MessageBox.Show("Can't add this Course"); } else { TxtCourseId.Text = Courseid.ToString(); } } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { //Course Id validation if (clsValidation.ValidateForEmptiness(TxtCourseId.Text) == false) { MessageBox.Show("Course id is required"); } else if (clsValidation.ValidateForNumeric(TxtCourseId.Text) == false) { MessageBox.Show("Course id is not a number"); } else if (clsValidation.ValidateForLength(TxtCourseId.Text, 5) == false) { MessageBox.Show("Course id is not 5 digits"); } else { clsCourse ObjCourse = new clsCourse(); ObjCourse.CourseId = int.Parse(TxtCourseId.Text); ObjCourse.DeleteCourse(); } }