예제 #1
0
        public Form_MenuStudent(User u)
        {
            InitializeComponent();
            GeneralFuntion.Form_Center_FixedDialog(this);

            dal = new DbContextDal();

            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Student"))
                {
                    student           = dal.students.Find(user.ID);
                    lbl_userName.Text = lbl_userName.Text + student.Name;
                    lbl_title.Text    = lbl_title.Text + "Student";
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Student can enter to here)");
                    clickGoBack = true;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                this.Close();
            }
        }
예제 #2
0
        public Form_MenuSecretaryAdmin(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary         = dal.secretaries.Find(user.ID);
                    lbl_userName.Text = lbl_userName.Text + secretary.Name;
                    lbl_title.Text    = lbl_title.Text + "Secretary";
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin             = dal.admins.Find(user.ID);
                    lbl_userName.Text = lbl_userName.Text + admin.Name;
                    lbl_title.Text    = lbl_title.Text + "Admin";
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Secretary or Admin can enter to here)");
                    clickGoBack = true;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                this.Close();
            }
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
예제 #3
0
        // function example to update user password
        public static void changePasswordUser(int id, string newPassword)
        {
            try
            {
                DbContextDal dal = new DbContextDal();

                // פעולת חיפוש משתנה

                // יצירת אובייקט משתמש כדי שניקלוט אליו משתמש קיים מהבסיס נתונים
                User user;

                // מציאת משתמש לפי מפתח ראשי
                user = dal.users.Find(id);
                // או

                // מציאת סטודנט לפי סינון , ובחירה של הראשון או דיפולטיבי
                user = dal.users.Find(id);

                // שינוי נתונים באובייקט
                user.password = newPassword;

                // שמירת מצב השינויים
                dal.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.ToString());
            }
        }
예제 #4
0
        // function to add grade for the first time to student who learn some course
        public void addGradeToStudent(int idStudent, int idCourse, int grade)
        {
            // Get connection to DB
            DbContextDal context = new DbContextDal();

            // get Course by id
            Course course = context.courses.Find(idCourse);

            // get student by id
            Student student = context.students.Find(idStudent);

            // create new enrollment - connect student and course, adding new grade
            Enrollment enrollment = new Enrollment()
            {
                Student = student, Course = course
            };

            // add grade for the course the student learn
            enrollment.Grade = grade;

            // connect enroll to student
            student.Enrollments.Add(enrollment);

            // connect enroll to course
            course.Enrollments.Add(enrollment);

            // add new enrollment to database
            context.Enrollments.Add(enrollment);

            // save the database's change
            context.SaveChanges();
        }
        public Form_ScheduleStudent(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin = dal.admins.Find(user.ID);
                }
                else if (user.permission.Equals("Student"))
                {
                    student          = dal.students.Find(user.ID);
                    selected_student = student;
                    if (student == null)
                    {
                        return;
                    }
                    txt_CB_students.Text    = "S" + student.ID.ToString() + " : " + student.Name;
                    txt_CB_students.Enabled = false;
                    txt_CB_courses.Enabled  = true;
                    handlerShowCoursesStudent();
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Secretary / Admin can enter to here)");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            checkBox_onlyPractises.Enabled = true;
            checkBox_onlyLectures.Enabled  = true;
            checkBox_onlyLabs.Enabled      = true;

            checkBox_onlyLabs.Checked      = true;
            checkBox_onlyLectures.Checked  = true;
            checkBox_onlyPractises.Checked = true;

            checkBox_LessonsOfStudentSelected.Checked = false;
            checkBox_LessonsOfStudentSelected.Enabled = true;

            GeneralFuntion.Form_Center_FixedDialog(this);
            setEmptyDataInGridView();
            setStudents();
            updateButtons();
        }
예제 #6
0
        private void btn_moreOptionOfBranchA_Click(object sender, EventArgs e)
        {
            DbContextDal dal = new DbContextDal();
            User         u   = dal.users.Find(student.ID);

            this.Hide();
            Form_MenuStudent studentMenu = new Form_MenuStudent(u);

            studentMenu.refToLogInForm = this;
            studentMenu.Show();
        }
예제 #7
0
        private void Reload()
        {
            DbContextDal dal = new DbContextDal();

            student = dal.students.Where(x => x.ID == student.ID).FirstOrDefault();
            checkBox_grade.Checked = false;
            checkBox_test.Checked  = false;
            button_confirm.Hide();
            comboBox_Course.Items.Clear();
            studentCourses = SettingDatabase.GetAllLearnedCoursesOfStudent(student);
            foreach (Course item in studentCourses)
            {
                comboBox_Course.Items.Add(item.Name);
            }
            float             studentGrade      = 0;
            int               counter           = 0;
            List <Enrollment> allStudentCourses = student.Enrollments.ToList();

            dataGridView1.Rows.Clear();
            dataGridView1.Refresh();
            foreach (Enrollment item in allStudentCourses)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dataGridView1);  // this line was missing
                row.Cells[0].Value = item.Course.Name;
                if (item.Grade != null)
                {
                    row.Cells[1].Value = item.Grade;
                    studentGrade       = float.Parse(item.Grade.ToString());
                    counter++;
                }
                if (item.gradeAppeal != null)
                {
                    row.Cells[2].Value = item.gradeAppeal;
                }
                else
                {
                    row.Cells[2].Value = "Not requested";
                }
                if (item.additionalTest != null)
                {
                    row.Cells[3].Value = item.additionalTest;
                }
                else
                {
                    row.Cells[3].Value = "Not requested";
                }
                dataGridView1.Rows.Add(row);
            }

            studentGrade   = studentGrade / counter;
            label_GPA.Text = "GPA: " + studentGrade;
        }
예제 #8
0
        private void button_confirm_Click(object sender, EventArgs e)
        {
            if (checkBox_grade.Checked == false && checkBox_test.Checked == false)
            {
                MessageBox.Show("You have to pick type of request");
                return;
            }
            DbContextDal dal           = new DbContextDal();
            Enrollment   studentCourse = dal.Enrollments.Where(x => x.CourseId == currentCourse.ID && x.StudentId == student.ID).FirstOrDefault();

            if (checkBox_grade.Checked == true)
            {
                if (studentCourse.gradeAppeal != null)
                {
                    MessageBox.Show("You allready requested grade appeal");
                }
                else if (studentCourse.additionalTest != null)
                {
                    if (!(studentCourse.additionalTest.Equals(requestState.testPassed.ToString())))
                    {
                        MessageBox.Show("You allready requested for additional test, you cant request until final grade received");
                    }
                }
                else if (studentCourse.Grade == -1)
                {
                    MessageBox.Show("You don't have grade for this course yet. You can make request after you get the grade");
                }
                else
                {
                    studentCourse.gradeAppeal = requestState.Submitted.ToString();
                    SettingDatabase.Change_Grade_Status_Request(student, studentCourse);
                    Reload();
                }
            }
            else if (checkBox_test.Checked == true)
            {
                if (studentCourse.additionalTest != null)
                {
                    MessageBox.Show("You allready requested for additional test");
                }
                else if (studentCourse.Grade == -1)
                {
                    MessageBox.Show("You don't have grade for this course yet. You can make request after you get the grade");
                }
                else
                {
                    studentCourse.additionalTest = requestState.Submitted.ToString();
                    SettingDatabase.Change_Test_Status_Request(student, studentCourse);
                    Reload();
                }
            }
        }
예제 #9
0
        public List <Student> getAllStudentsInMyCourse(Course c)
        {
            DbContextDal dal = new DbContextDal();

            if (dal.approveLecturersCourse.Find(ID, c.ID) != null)
            {
                return(SettingDatabase.GetAllStudenstWhoLearchCourse(c));
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
        public RegistrarForms()
        {
            InitializeComponent();
            DbContextDal dal = new DbContextDal();
            var          IDs = dal.students.Select(x => x.ID).ToList();

            foreach (var ID in IDs)
            {
                comboBox_IDs.Items.Add(ID);
            }
            comboBox_formToGenerate.Items.Add("Annual fee permit");
            comboBox_formToGenerate.Items.Add("Annual study permit");
        }
예제 #11
0
        public List <Practitioner> getAllPractitionerInMyCourse(Course c)
        {
            DbContextDal dal = new DbContextDal();

            if (dal.approveLecturersCourse.Find(ID, c.ID) != null)
            {
                return(SettingDatabase.GetAllPractitionersWhoLearchCourse(c));
            }
            else
            {
                return(null);
            }
        }
예제 #12
0
        private void setAllLabsLessonOfPractitioner()
        {
            if (practitioner == null)
            {
                return;
            }

            DbContextDal dal = new DbContextDal();

            list_lessons = (from x in dal.LessonLabs
                            where x.practitionerID == practitioner.ID
                            select x).ToList <Lesson>();
        }
        public Form_AddConstraint(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Lecturer"))
                {
                    lecturer            = dal.lecturers.Find(user.ID);
                    listApprovedCourses = lecturer.getAllMyCourseInStateApproved();
                }
                else if (user.permission.Equals("Practitioner"))
                {
                    practitioner        = dal.practitiners.Find(user.ID);
                    listApprovedCourses = practitioner.getAllMyCourseInStateApproved();
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Lecturer / Practitioner can enter to here)");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            if (listApprovedCourses != null)
            {
                string[] CB_coursesItems = new string[listApprovedCourses.Count + 1];
                CB_coursesItems[0] = "";
                for (int i = 0; i < listApprovedCourses.Count; i++)
                {
                    string str = listApprovedCourses.ElementAt(i).ID.ToString() + " : " + listApprovedCourses.ElementAt(i).Name;
                    CB_coursesItems[i + 1] = str;
                }

                txt_CB_coursesApproved.DataSource = CB_coursesItems;
            }

            txt_checkBox_allCourses.Checked = true;
            updateButtonsAndTextBoxes();
            GeneralFuntion.BlockResizeListViewColumns(listView_constraints);
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
        public Form_addCourseToStaffAndStudent(User u)
        {
            InitializeComponent();
            // init connection to database
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    staffMember = secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    staffMember = admin = dal.admins.Find(user.ID);
                }
                else if (user.permission.Equals("Lecturer"))
                {
                    staffMember = lecturer = dal.lecturers.Find(user.ID);
                }
                else if (user.permission.Equals("Practitioner"))
                {
                    staffMember = practitioner = dal.practitiners.Find(user.ID);
                }
                else if (user.permission.Equals("Student"))
                {
                    student = dal.students.Find(user.ID);
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details!");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }
            resertDetailCourse();
            UpdateDefaultButton();
            initPermission();
            GeneralFuntion.BlockResizeListViewColumns(listView_coursesFounded);
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
예제 #15
0
        public bool add_Lesson(Lesson lesson)
        {
            List <Lesson> lessons = getAllMyLessons();
            DbContextDal  dal     = new DbContextDal();

            if (lesson != null)
            {
                if (lessons.Any(item => item.LCourseID == lesson.LCourseID && item.Type.Equals(lesson.Type)))
                {
                    MessageBox.Show("Student allready sighned to this " + lesson.Type);
                    return(false);
                }

                int numberOfStudents = 0;
                if (lesson.Type.Equals("Lab"))
                {
                    numberOfStudents = ((Lab)lesson).NumStudent;
                }
                else if (lesson.Type.Equals("Practise"))
                {
                    numberOfStudents = ((Practise)lesson).NumStudent;
                }
                else if (lesson.Type.Equals("Lecture"))
                {
                    numberOfStudents = ((Lecture)lesson).NumStudent;
                }
                if (numberOfStudents + 1 > lesson.classroom.maxStudents)
                {
                    MessageBox.Show("This " + lesson.Type + " allready have maximum number of students");
                    return(false);
                }

                foreach (Lesson item in lessons)
                {
                    if (lesson.Start > item.Start && lesson.Start < item.End || lesson.End > item.Start && lesson.End < item.End)
                    {
                        MessageBox.Show("Student allready have another lesson at this time " + lesson.Type + " not added");
                        return(false);
                    }
                }


                SettingDatabase.registerStudentToLesson(this, lesson, lesson.Type);
            }
            return(false);
        }
        public Form_AddUpdateStaffMember(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin = dal.admins.Find(user.ID);
                }
                else if (user.permission.Equals("Lecturer"))
                {
                    lecturer = dal.lecturers.Find(user.ID);
                }
                else if (user.permission.Equals("Practitioner"))
                {
                    practitioner = dal.practitiners.Find(user.ID);
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details!");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            updateButtons();
            listView_staffFounded.Items.Clear();
            GeneralFuntion.BlockResizeListViewColumns(listView_staffFounded);
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
        // the ctor of the frame
        public Form_AddUpdateStudent(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin = dal.admins.Find(user.ID);
                }
                else if (user.permission.Equals("Student"))
                {
                    studentAsPremission = dal.students.Find(user.ID);
                    studentSelected     = studentAsPremission;
                    txt_TB_ID.Text      = studentAsPremission.ID.ToString();
                    txt_TB_ID.Enabled   = false;
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Secretary or Admin or Student can enter here!)");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            updateButtons();
            GeneralFuntion.BlockResizeListViewColumns(listView_studentFounded);
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
예제 #18
0
        // function example to adding new user and student
        public static bool createAdminUser()
        {
            try
            {
                // פעולת הוספה
                DbContextDal dal = new DbContextDal();

                // יצירת אובייקט משתמש וסטודנט כדי להכניס לבסיס נתונים
                User  user  = new User(0, "admin", "Admin", "admin");
                Admin admin = new Admin();
                admin.ID     = 0;          // !שדה חובה
                admin.Name   = "Admin";
                admin.Gender = "Male";     // !שדה חובה
                admin.user   = user;
                admin.Type   = "Admin";
                DateTime date;
                bool     parseResult = DateTime.TryParse("01.01.1980", out date);
                if (parseResult)
                {
                    admin.BirthDate = date;
                    DateTime now = DateTime.Today;
                    int      age = now.Year - admin.BirthDate.GetValueOrDefault().Year;
                    if (now < admin.BirthDate.GetValueOrDefault().AddYears(age))
                    {
                        age--;
                    }

                    admin.Age = age;
                }
                dal.users.Add(user);
                dal.admins.Add(admin);

                dal.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.ToString());
            }
            return(false);
        }
        public Form_ScheduleLessonsByConstraint(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin = dal.admins.Find(user.ID);
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Secretary / Admin can enter to here)");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            setLecturersAndPractitionersWithApprovedCourses();
            setListViewClasses();

            GeneralFuntion.BlockResizeListViewColumns(listView_constraints);
            GeneralFuntion.BlockResizeListViewColumns(listView_freeClasses);
            GeneralFuntion.Form_Center_FixedDialog(this);
            setEmptyDataInGridView();
            updateComponents();
            string[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };
        }
예제 #20
0
        public Form_SearchingStudents(User u)
        {
            InitializeComponent();
            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Secretary"))
                {
                    secretary = dal.secretaries.Find(user.ID);
                }
                else if (user.permission.Equals("Admin"))
                {
                    admin = dal.admins.Find(user.ID);
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Secretary or Admin can enter here!)");

                    MessageBox.Show("Error: Could not identify user details!");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }
            rbtn_FailedAtCourse.Checked = true;
            UpdateCoursesInComboBox(courses);
            updateButtons();
            GeneralFuntion.BlockResizeListViewColumns(listView_studentCourseGrade);
            GeneralFuntion.Form_Center_FixedDialog(this);
        }
예제 #21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /*
             * for get this project in another computer and the PMC dont let you to add migration just ran the following command in PM:
             * PM> Get-Project -all | Uninstall-Package EntityFramework
             * and then run the command:
             * PM> Get-Project -all | Install-Package EntityFramework
             * and then restart the project (exit and return the visual studio)
             *
             * to run in in the first time, or if you want to run in from the begining with initilize data first
             * first at all:
             *      dont forget to change the Connection String in the file 'App.config' to availabe database
             * use the followin command in you Package Manager Console to delete all the table in the database for recreating agian
             * PM> update-database -TargetMigration:0 -Force
             * And then run the command
             * PM> add-migration a
             * And then run the command
             * PM> update-database
             */

            //SettingDatabase.setupFirstInitDB(true);
            try
            {
                DbContextDal      dal   = new DbContextDal();
                Form_toastMassage toast = new Form_toastMassage("check connection to database!");
                toast.Show();
                if (dal.users.Find(0) == null)
                {
                    GeneralFuntion.createAdminUser();
                }

                Application.Run(new Form_LoginStart());
            }
            catch (Exception) { MessageBox.Show("There isn't connection to database!"); }
        }
        public Form_MenuLecturerPractitioner(User u)
        {
            InitializeComponent();

            GeneralFuntion.Form_Center_FixedDialog(this);

            dal = new DbContextDal();

            user = u;
            if (user != null)
            {
                if (user.permission.Equals("Lecturer"))
                {
                    lecturer          = dal.lecturers.Find(user.ID);
                    lbl_userName.Text = lbl_userName.Text + lecturer.Name;
                    lbl_title.Text    = lbl_title.Text + "Lecturer";
                }
                else if (user.permission.Equals("Practitioner"))
                {
                    practitioner      = dal.practitiners.Find(user.ID);
                    lbl_userName.Text = lbl_userName.Text + practitioner.Name;
                    lbl_title.Text    = lbl_title.Text + "Practitioner";
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Lecturer or Practitioner can enter to here)");
                    clickGoBack = true;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                this.Close();
            }
        }
예제 #23
0
        // function example to deleting user and student
        public static void deleteUser(int id)
        {
            try
            {
                // פעולת מחיקה
                DbContextDal dal = new DbContextDal();

                // יצירת אובייקט משתמש כדי שניקלוט אליו משתמש קיים מהבסיס נתונים
                User    user;
                Student std;
                // בגלל שסטודנט הוא מפתח זר של משתמש, כלומר אם קיים סטודנט זה רק בתנאי שקיים משתמש כזה
                // אז אם נמחוק את המשתמש קודם, אז הסטודנט לא יעמוד בתנאי הזה!
                // ולכן חייבים למחוק את הסטודנט לפני שמוחקים את המשתמש
                // ככה הגדרתי , שהת.ז. של הסטודנט הוא מפתח זר של משתמש

                // מציאת משתמש וסטודנט לפי מפתח ראשי
                user = dal.users.Find(id);
                std  = dal.students.Find(id);

                // בדיקה אם מצאנו אובייקטים כלשהם במידה ולא, מסיימים את הפונקציה
                if (std == null || user == null)
                {
                    return;
                }

                // הסרת האובייקט מרשימת האובייקטים שבבסיס נתונים
                dal.students.Remove(std); // קודם מסירים את הסטודנט
                dal.users.Remove(user);   // ורק אז את המשתמש

                // שמירת מצב השינויים
                dal.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.ToString());
            }
        }
예제 #24
0
        private void CreateStudyForm()
        {
            bool             createForm = true;
            DbContextDal     dal        = new DbContextDal();
            int              ID         = int.Parse(comboBox_IDs.SelectedItem.ToString());
            StudentStudyForm StudyForm  = new StudentStudyForm()
            {
                ID = ID, FormCreateDate = DateTime.Today, ValidationDate = dateTimePicker1.Value.Date
            };
            StudentStudyForm SF = dal.StudentsStudyForms.Where(x => x.ID == ID).FirstOrDefault();

            if (SF != null)
            {
                DialogResult result = MessageBox.Show("Student allready have study form, do you want to change it?", "caption", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    createForm = false;
                }
                if (createForm == true)
                {
                    dal.Entry(SF).CurrentValues.SetValues(StudyForm);
                    dal.SaveChanges();
                    MessageBox.Show("Fee study added");
                }
                else
                {
                    MessageBox.Show("Fee study not added");
                }
            }
            else
            {
                dal.StudentsStudyForms.Add(StudyForm);
                dal.SaveChanges();
                MessageBox.Show("Study form added");
            }
        }
예제 #25
0
        public Form_MySchedule(User u)
        {
            InitializeComponent();

            dal = new DbContextDal();

            //Receives a staff member indicating what authorization is, to know what actions are allowed
            user = u;

            if (user != null)
            {
                if (user.permission.Equals("Lecturer"))
                {
                    lecturer         = dal.lecturers.Find(user.ID);
                    list_lessons     = lecturer.GetAllMyLesson();
                    list_lessons_fix = lecturer.GetAllMyLesson();

                    checkBox_lectures.Enabled = true;
                    checkBox_lectures.Checked = true;

                    checkBox_practises.Enabled = false;
                    checkBox_practises.Checked = false;
                    checkBox_labs.Enabled      = false;
                    checkBox_labs.Checked      = false;
                }
                else if (user.permission.Equals("Practitioner"))
                {
                    practitioner     = dal.practitiners.Find(user.ID);
                    list_lessons     = practitioner.GetAllMyLesson();
                    list_lessons_fix = practitioner.GetAllMyLesson();


                    checkBox_practises.Enabled = true;
                    checkBox_practises.Checked = true;
                    checkBox_labs.Enabled      = true;
                    checkBox_labs.Checked      = true;


                    checkBox_lectures.Enabled = false;
                    checkBox_lectures.Checked = false;
                }
                else if (user.permission.Equals("Student"))
                {
                    student                    = dal.students.Find(user.ID);
                    list_lessons               = student.getAllMyLessons();
                    list_lessons_fix           = student.getAllMyLessons();
                    checkBox_practises.Enabled = true;
                    checkBox_practises.Checked = true;
                    checkBox_labs.Enabled      = true;
                    checkBox_labs.Checked      = true;
                    checkBox_lectures.Enabled  = true;
                    checkBox_lectures.Checked  = true;
                }
                else
                {
                    MessageBox.Show("Error: Could not identify user details! (Only Student / Lecturer / Practitioner can enter to here)");
                    clickGoBack = true;
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Error: Could not identify user details!");
                clickGoBack = true;
                Close();
            }

            GeneralFuntion.Form_Center_FixedDialog(this);
            setEmptyDataInGridView();
            setDataInGridView();
            initListView();
        }
예제 #26
0
        private bool Add_Student(Student std, string pass = "")
        {
            try
            {
                string password = "******";
                if (pass.Length > 0)
                {
                    password = pass;
                }
                if (!SettingDatabase.Add_New_Student(std, password))
                {
                    MessageBox.Show("Some Error accure to create new user for this student");
                    return(false);
                }

                DbContextDal dal = new DbContextDal();
                //User UserStudent = dal.users.Find(std.ID);
                User UserStudent = dal.users.Find(std.ID);
                if (UserStudent != null)
                {
                    std.user = UserStudent;
                    dal.students.Add(std);
                    dal.SaveChanges();
                    MessageBox.Show("The Student " + std.ID + " Added!");
                    return(true);
                }
                else
                {
                    MessageBox.Show("Error to add student, because the user of this student deosnt created!");
                }
            }
            catch (DbEntityValidationException ex)
            {
                //MessageBox.Show("Db Entity Validation Exception");
                string str = "" + ex.Source + " : " + ex.GetType() + "\n-----------------------------------------------------------------------------------------------------\n" +
                             "Message: " + ex.Message + "\n\nExplain & solution:\nThe problem is that you try to insert an object with data that  does not fit the limitations of the data base to these object fields.\n\nThe following is a list of the incorrect features:\n";
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        str += ("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage + "\n");
                    }
                }
                MessageBox.Show(str);
            }
            catch (DbUnexpectedValidationException ex)
            {
                //MessageBox.Show("Db Unexpected Validation Exception");
                string str = "" + ex.Source + " : " + ex.GetType() + "\n-----------------------------------------------------------------------------------------------------\n" +
                             "Message: " + ex.Message;
                MessageBox.Show(str);
            }
            catch (DbUpdateException ex)
            {
                //MessageBox.Show("Db Update Exception");
                string str = "" + ex.Source + " : " + ex.GetType() + "\n-----------------------------------------------------------------------------------------------------\n" +
                             "Message: " + ex.Message + "\n\nExplain & solution:\nThe problem is that you are trying to insert an object that already exists in the system with the same key, or perform object updates with invalid variables in a database. You must enter differentiated data.";
                MessageBox.Show(str);
            }
            catch (InvalidOperationException ex)
            {
                //MessageBox.Show("Invalid Operation Exception");
                string str = "" + ex.Source + " : " + ex.GetType() + "\n-----------------------------------------------------------------------------------------------------\n" +
                             "Message: " + ex.Message + "\n\nExplain & solution:\nThe problem is that the database is formatted differently from what is currently in your class code. You must do 'add-migration update_i' to changes made during code writing in the class code, and then perform a 'update-database' in your PM.";
                MessageBox.Show(str);
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Exception");
                string str = "" + ex.Source + " : " + ex.GetType() + "\n-----------------------------------------------------------------------------------------------------\n" +
                             "Message: " + ex.Message;
                MessageBox.Show(str);
            }
            return(false);
        }
예제 #27
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (textBox_userName.TextLength == 0)
            {
                MessageBox.Show("Must enter user id first!");
                connect_with_facebook = false;
                return;
            }
            int id = -1;

            try
            {
                id   = System.Convert.ToInt32(textBox_userName.Text.ToString());
                user = SettingDatabase.GetUserById(id);
            }
            catch (Exception) { user = SettingDatabase.GetUserByEmail(textBox_userName.Text); }



            string pass = textBox_password.Text.ToString();

            if (user == null)
            {
                MessageBox.Show("The user " + textBox_userName.Text + " dont exist!");
                connect_with_facebook = false;
                ResetDetailsLogin();
                return;
            }

            if (user != null && pass.Equals(user.password) || connect_with_facebook)
            {
                // move to new form
                if ("Student".Equals(user.permission))
                {
                    try
                    {
                        DbContextDal dal = new DbContextDal(); //New database connection
                        MessageBox.Show("Successfull Login as " + user.permission + " , continue to the Option Menu for you.\n");
                        Student student = dal.students.Find(user.ID);
                        this.Hide();
                        StudentMenu studentMenu = new StudentMenu(student);
                        studentMenu.refToLogInForm = this;
                        studentMenu.Show();
                        ResetDetailsLogin();
                    }
                    catch (Exception) { }
                }
                else if ("Grader".Equals(user.permission))
                {
                    DbContextDal dal  = new DbContextDal(); //New database connection
                    Grader       StCo = dal.Graders.Find(user.ID);
                    this.Hide();
                    GraderMenu graderMenu = new GraderMenu();
                    graderMenu.refToLogInForm = this;
                    graderMenu.Show();
                    ResetDetailsLogin();
                }
                else if ("StudentCoordinator".Equals(user.permission))
                {
                    DbContextDal       dal  = new DbContextDal(); //New database connection
                    StudentCoordinator StCo = dal.StudentCoordinators.Find(user.ID);
                    this.Hide();
                    StudentCoordinatorMenu StCoMenu = new StudentCoordinatorMenu(StCo);
                    StCoMenu.refToLogInForm = this;
                    StCoMenu.Show();
                    ResetDetailsLogin();
                }
                else if ("Grader".Equals(user.permission))
                {
                    DbContextDal dal  = new DbContextDal(); //New database connection
                    Grader       StCo = dal.Graders.Find(user.ID);
                    this.Hide();
                    GraderMenu graderMenu = new GraderMenu();
                    graderMenu.refToLogInForm = this;
                    graderMenu.Show();
                    ResetDetailsLogin();
                }
                else if ("Registrar".Equals(user.permission))
                {
                    DbContextDal dal = new DbContextDal(); //New database connection
                    Registrar    reg = dal.Registrars.Find(user.ID);
                    this.Hide();
                    RegistrarMenu menu = new RegistrarMenu(reg);
                    menu.refToLogInForm = this;
                    menu.Show();
                    ResetDetailsLogin();
                }
                else if ("Secretary".Equals(user.permission) || "Admin".Equals(user.permission))
                {
                    try
                    {
                        DbContextDal dal = new DbContextDal(); //New database connection
                        MessageBox.Show("Successfull Login as " + user.permission + " , continue to the Option Menu for you");
                        this.Hide();
                        Form_MenuSecretaryAdmin myForm = new Form_MenuSecretaryAdmin(user);
                        myForm.refToLogInForm = this;
                        myForm.Show();
                        ResetDetailsLogin();
                    }
                    catch (Exception) { }
                }
                else if ("Lecturer".Equals(user.permission) || "Practitioner".Equals(user.permission))
                {
                    try
                    {
                        MessageBox.Show("Successfull Login as " + user.permission + " , continue to the Option Menu for you");
                        Form_MenuLecturerPractitioner myForm = new Form_MenuLecturerPractitioner(user);
                        this.Hide();
                        myForm.refToLogInForm = this;
                        myForm.Show();
                        ResetDetailsLogin();
                    }
                    catch (Exception) { }
                }
                else
                {
                    MessageBox.Show("Successfull Login, for Null permmision!");
                }
            }
            else
            {
                MessageBox.Show("Wrong password !");
                textBox_password.Text = "";
            }
        }