Example #1
0
        protected void grd_students_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    _studentId  = int.Parse(e.CommandArgument.ToString());
            string _actionName = e.CommandName;

            if (_actionName == "DeleteStudent")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Student _student = _context.Students.Where(a => a.St_Id == _studentId).FirstOrDefault();
                if (_student.Exams.Count == 0 && _student.Stud_Course.Count == 0)
                {
                    _context.Students.Remove(_student);
                    _context.SaveChanges();
                    show_students();
                    lbl_meesage.Text = "";
                }
                else
                {
                    lbl_meesage.Text = "Student " + _student.St_Fname + " Can't be deleted !";
                }
            }
            else if (_actionName == "EditCurrentStudent")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Student _student = _context.Students.Where(a => a.St_Id == _studentId).FirstOrDefault();
                txt_fname.Text         = _student.St_Fname;
                txt_lname.Text         = _student.St_Lname;
                txt_age.Text           = _student.St_Age.ToString();
                txt_address.Text       = _student.St_Address;
                ddl_dept.SelectedValue = _student.Dept_Id.ToString();
                btn_save.Text          = "Update";
                st_hidden_id.Value     = _studentId.ToString();
            }
        }
Example #2
0
        protected void grd_topics_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    _TopicId    = int.Parse(e.CommandArgument.ToString());
            string _actionName = e.CommandName;

            if (_actionName == "DeleteTopic")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Topic _Topic = _context.Topics.Where(a => a.Top_Id == _TopicId).FirstOrDefault();

                _context.Topics.Remove(_Topic);
                _context.SaveChanges();
                show_topics();
            }
            else if (_actionName == "EditCurrentTopic")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Topic _Topic = _context.Topics.Where(a => a.Top_Id == _TopicId).FirstOrDefault();
                txt_topic_id.Text            = _Topic.Top_Id.ToString();
                txt_topic_name.Text          = _Topic.Top_Name;
                ddl_coursename.SelectedValue = _Topic.Crs_Id.ToString();
                btn_save_topic.Text          = "Update";
                Topic_Hidden_id.Value        = _TopicId.ToString();
            }
        }
        protected void grd_Questions_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    _QuestionId = int.Parse(e.CommandArgument.ToString());
            string _actionName = e.CommandName;

            if (_actionName == "DeleteQuestion")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Question _Question = _context.Questions.Where(a => a.Qstn_Id == _QuestionId).FirstOrDefault();
                if (_Question.Choices.Count == 0 && _Question.Exam_Question.Count == 0)
                {
                    _context.Questions.Remove(_Question);
                    _context.SaveChanges();
                    show_Questions();
                }
                else
                {
                    lbl_msg_q.Text = "this Question can't be deleted";
                }
            }
            else if (_actionName == "EditCurrentQuestion")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Question _Question = _context.Questions.Where(a => a.Qstn_Id == _QuestionId).FirstOrDefault();
                txt_qid.Text              = _Question.Qstn_Id.ToString();
                txt_qtext.Text            = _Question.Qstn_Text;
                txt_qtype.Text            = _Question.Qstn_Type;
                txt_qanswer.Text          = _Question.Qstn_Answer;
                ddl_courses.SelectedValue = _Question.Crs_Id.ToString();
                btn_save_Q.Text           = "Update";
                Q_hidden_id.Value         = _QuestionId.ToString();
            }
        }
Example #4
0
        protected void btn_save_topic_Click(object sender, EventArgs e)
        {
            if (btn_save_topic.Text == "Save")
            {
                Topic new_topic = new Topic();
                new_topic.Top_Id   = int.Parse(txt_topic_id.Text);
                new_topic.Top_Name = txt_topic_name.Text;
                new_topic.Crs_Id   = int.Parse(ddl_coursename.SelectedValue);
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                _container.Topics.Add(new_topic);
                _container.SaveChanges();

                show_courses();
                show_topics();
                clear_all();
            }
            else
            {
                int Topic_Id = int.Parse(Topic_Hidden_id.Value);
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                Topic topic_update = _container.Topics.Where(a => a.Top_Id == Topic_Id).FirstOrDefault();
                topic_update.Top_Id   = int.Parse(txt_topic_id.Text);
                topic_update.Top_Name = txt_topic_name.Text;
                topic_update.Crs_Id   = int.Parse(ddl_coursename.SelectedValue);


                _container.SaveChanges();
                show_topics();
                clear_all();
                btn_save_topic.Text = "Save";
            }
        }
        protected void grd_instructors_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int    _InstructorId = int.Parse(e.CommandArgument.ToString());
            string _actionName   = e.CommandName;

            if (_actionName == "DeleteInstructor")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Instructor _Instructor = _context.Instructors.Where(a => a.Ins_Id == _InstructorId).FirstOrDefault();
                if (_Instructor.Ins_Course.Count == 0)
                {
                    _context.Instructors.Remove(_Instructor);
                    _context.SaveChanges();
                    show_instructors();
                }
                else
                {
                    lbl_msg_instructor.Text = "instructor" + _Instructor.Ins_Name + "can't be deleted";
                }
            }
            else if (_actionName == "EditCurrentInstructor")
            {
                OnlineExamsProjectDBEntities _context = new OnlineExamsProjectDBEntities();
                Instructor _Instructor = _context.Instructors.Where(a => a.Ins_Id == _InstructorId).FirstOrDefault();
                txt_ins_id.Text              = _Instructor.Ins_Id.ToString();
                txt_ins_name.Text            = _Instructor.Ins_Name;
                txt_ins_degree.Text          = _Instructor.Ins_Degree;
                txt_ins_salary.Text          = _Instructor.Salary.ToString();
                ddl_department.SelectedValue = _Instructor.Dept_Id.ToString();
                btn_save_instructor.Text     = "Update";
                Instructor_Hidden_id.Value   = _InstructorId.ToString();
            }
        }
Example #6
0
        public void show_departments()
        {
            OnlineExamsProjectDBEntities _container      = new OnlineExamsProjectDBEntities();
            List <Department>            all_departments = _container.Departments.ToList();

            ddl_dept.DataSource = all_departments;
            ddl_dept.DataBind();
        }
Example #7
0
        public void show_students()
        {
            OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
            List <Student> all_students             = _container.Students.ToList();

            grd_students.DataSource = all_students;
            grd_students.DataBind();
        }
Example #8
0
        public void show_topics()
        {
            OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
            List <Topic> alltopics = _container.Topics.ToList();

            grd_topics.DataSource = alltopics;
            grd_topics.DataBind();
        }
Example #9
0
        public void show_courses()
        {
            OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
            List <Course> allcourses = _container.Courses.ToList();

            ddl_coursename.DataSource = allcourses;
            ddl_coursename.DataBind();
        }
        public void show_Questions()
        {
            OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
            List <Question> allQuestions            = _container.Questions.ToList();

            grd_Questions.DataSource = allQuestions;
            grd_Questions.DataBind();
        }
        public void show_instructors()
        {
            OnlineExamsProjectDBEntities _container     = new OnlineExamsProjectDBEntities();
            List <Instructor>            allinstructors = _container.Instructors.ToList();

            grd_instructors.DataSource = allinstructors;
            grd_instructors.DataBind();
        }
        protected void btn_save_Q_Click(object sender, EventArgs e)
        {
            if (btn_save_Q.Text == "Save")
            {
                Question new_question = new Question();
                new_question.Qstn_Text = txt_qtext.Text;
                lbl_Qtype.Text         = "";
                if (txt_qtype.Text == "MCQ" || txt_qtype.Text == "TFQ")
                {
                    new_question.Qstn_Type = txt_qtype.Text;
                }
                else
                {
                    lbl_Qtype.Text = "Must be MCQ or TFQ";
                }
                if (txt_qanswer.Text == "a" || txt_qanswer.Text == "b" ||
                    txt_qanswer.Text == "c" || txt_qanswer.Text == "d" ||
                    txt_qanswer.Text == "TRUE" || txt_qanswer.Text == "FALSE")

                {
                    new_question.Qstn_Answer = txt_qanswer.Text;
                    lbl_Qanswer.Text         = "";
                }
                else
                {
                    lbl_Qanswer.Text = "value must be a,b,c,d,TRUE,FALSE";
                }

                new_question.Qstn_Id = int.Parse(txt_qid.Text);
                new_question.Crs_Id  = int.Parse(ddl_courses.SelectedValue);

                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                _container.Questions.Add(new_question);
                _container.SaveChanges();

                show_courses();
                show_Questions();
                clearvalues();
            }
            else
            {
                int Question_Id = int.Parse(Q_hidden_id.Value);
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                Question Q_update = _container.Questions.Where(a => a.Qstn_Id == Question_Id).FirstOrDefault();
                Q_update.Qstn_Text   = txt_qtext.Text;
                Q_update.Qstn_Type   = txt_qtype.Text;
                Q_update.Qstn_Answer = txt_qanswer.Text;


                _container.SaveChanges();
                show_Questions();
                clearvalues();
                btn_save_Q.Text = "Save";
            }
        }
Example #13
0
        protected void btn_save_Click(object sender, EventArgs e)
        {
            if (btn_save.Text == "Save")
            {
                Student new_student = new Student();
                new_student.St_Fname   = txt_fname.Text;
                new_student.St_Lname   = txt_lname.Text;
                new_student.St_Address = txt_address.Text;
                new_student.St_Age     = int.Parse(txt_age.Text);
                new_student.Dept_Id    = int.Parse(ddl_dept.SelectedValue);

                //add to DB that object
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                _container.Students.Add(new_student);
                _container.SaveChanges();

                //to add reload grid view by new data inserted from DB
                show_students();
                show_departments();
                clear_values();
            }
            else //btn_save.Text == "Update"
            {
                //when reload ..keep id value in hidden value to update by this id
                int student_Id = int.Parse(st_hidden_id.Value);
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                Student stu_update = _container.Students.Where(a => a.St_Id == student_Id).FirstOrDefault();
                stu_update.St_Fname   = txt_fname.Text;
                stu_update.St_Lname   = txt_lname.Text;
                stu_update.St_Age     = int.Parse(txt_age.Text);
                stu_update.St_Address = txt_address.Text;

                _container.SaveChanges();
                show_students();
                clear_values();
                btn_save.Text = "Save";
            }
        }
        protected void btn_save_instructor_Click(object sender, EventArgs e)
        {
            if (btn_save_instructor.Text == "Save")
            {
                Instructor new_instructor = new Instructor();
                new_instructor.Ins_Name   = txt_ins_name.Text;
                new_instructor.Ins_Id     = int.Parse(txt_ins_id.Text);
                new_instructor.Ins_Degree = txt_ins_degree.Text;
                new_instructor.Salary     = int.Parse(txt_ins_salary.Text);
                new_instructor.Dept_Id    = int.Parse(ddl_department.SelectedValue);

                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                _container.Instructors.Add(new_instructor);
                _container.SaveChanges();

                show_departments();
                show_instructors();
                clear_ins();
            }
            else
            {
                int Instructor_Id = int.Parse(Instructor_Hidden_id.Value);
                OnlineExamsProjectDBEntities _container = new OnlineExamsProjectDBEntities();
                Instructor Instructor_update            = _container.Instructors.Where(a => a.Ins_Id == Instructor_Id).FirstOrDefault();
                Instructor_update.Ins_Id     = int.Parse(txt_ins_id.Text);
                Instructor_update.Ins_Name   = txt_ins_name.Text;
                Instructor_update.Ins_Degree = txt_ins_degree.Text;
                Instructor_update.Salary     = int.Parse(txt_ins_salary.Text);
                Instructor_update.Dept_Id    = int.Parse(ddl_department.SelectedValue);

                _container.SaveChanges();
                show_instructors();
                clear_ins();
                btn_save_instructor.Text = "Save";
            }
        }