Ejemplo n.º 1
0
        public List<Course> GetAllCourse()
        {
            List<Course> courseList = new List<Course>();
            string query = "SELECT * FROM t_course";
            aSqlCommand = new SqlCommand(query, aSqlConnection);
            aSqlConnection.Open();
            SqlDataReader aSqlDataReader = aSqlCommand.ExecuteReader();

            while (aSqlDataReader.Read())
            {
                Course course = new Course();
                course.Id = (int)aSqlDataReader["id"];
                course.Name = aSqlDataReader["name"].ToString();
                course.Code = aSqlDataReader["code"].ToString();
                course.Credit =(decimal) aSqlDataReader["credit"];
                course.Description = aSqlDataReader["description"].ToString();
                course.Dept_id = (int)aSqlDataReader["dept_id"];
                course.Semester_id = (int)aSqlDataReader["semester_id"];

                courseList.Add(course);
            }
            aSqlDataReader.Close();
            aSqlConnection.Close();

            return courseList;
        }
Ejemplo n.º 2
0
        public Course FindName(string name)
        {
            string query = "SELECT * FROM t_course WHERE code='" + name + "'";
            aSqlConnection.Open();
            aSqlCommand = new SqlCommand(query, aSqlConnection);

            SqlDataReader aSqlDataReader = aSqlCommand.ExecuteReader();
            Course aCourse;

            if (aSqlDataReader.HasRows)
            {
                aCourse = new Course();
                aSqlDataReader.Read();
                aCourse.Name = aSqlDataReader["name"].ToString();
                aSqlDataReader.Close();
                aSqlConnection.Close();
                return aCourse;
            }
            else
            {
                aSqlDataReader.Close();
                aSqlConnection.Close();
                return null;
            }
        }
Ejemplo n.º 3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (codeTextBox.Text == "")
            {
                MessageBox.Show("insert code value");
                return;
            }
            else if (nameTextBox.Text == "")
            {
                MessageBox.Show("insert name value");
                return;
            }

            else if (creditTextBox.Text=="")
            {
                MessageBox.Show("insert credit value");
                return;
            }
            string code = codeTextBox.Text;
            string name = nameTextBox.Text;
            decimal credit = Convert.ToDecimal(creditTextBox.Text);

            string description = descriptionRichTextBox.Text;
            int deptId = (int)departmentComboBox.SelectedValue;
            int semesterId = (int) semesterComboBox.SelectedValue;

            Course aCourse = new Course(code, name, credit,description, deptId,semesterId);

            string msg = aCourseManager.Save(aCourse);
            MessageBox.Show(msg);
        }
Ejemplo n.º 4
0
 public CourseAssignToTeacher( int teacherId, int courseId, Department department, Teacher teacher, Course course)
 {
     Teacher_id = teacherId;
     Course_id = courseId;
     Department = department;
     Teacher = teacher;
     Course = course;
 }
Ejemplo n.º 5
0
        public string Save(Course aCourse)
        {
            if (aCourse.Code.Length >= 5)
            {
                if (aCourse.Credit >= (decimal) .5 && aCourse.Credit <= 5)
                {
                    Course courseForCodeCheck = aCourseGateway.FindCode(aCourse.Code);
                    Course courseForNameCheck = aCourseGateway.FindName(aCourse.Name);

                    if (courseForCodeCheck == null)
                    {
                        if (courseForNameCheck == null)
                        {
                            aCourseGateway.Save(aCourse);
                            return "Course added.";
                        }
                        else
                        {
                            return "Course Name already exists.";
                        }

                    }
                    else
                    {
                        return "Course CODE already exists.";
                    }
                }
                else
                {
                    return "Credit cannot be less than 0.5 and more than 5.0";
                }

            }
            else
            {
                return "Code length must be 5 characters long.";
            }
        }
Ejemplo n.º 6
0
        public void Save(Course aCourse)
        {
            string query = "INSERT INTO t_course VALUES('" + aCourse.Code + "', '" + aCourse.Name + "', '" + aCourse.Credit + "', '" + aCourse.Description + "', '" + aCourse.Dept_id + "', '" + aCourse.Semester_id + "')";
            aSqlConnection.Open();
            aSqlCommand = new SqlCommand(query, aSqlConnection);

            aSqlCommand.ExecuteNonQuery();
            aSqlConnection.Close();
        }