Exemplo n.º 1
0
        private void CreateCourseBtn_Click(object sender, EventArgs e)
        {
            if (CreateEditCourseBtn.Text == "Create")
            {
                if (string.IsNullOrWhiteSpace(CourseTitleBox.Text)) //if nothing is written in the title box
                {
                    CourseTitleErrorLabel.Show();                   //Highlight it
                }
                else
                {
                    CourseTitleErrorLabel.Hide();
                    if (UsersList.SelectedItems.Count == 0)
                    {
                        DialogResult question = MessageBox.Show("You didn't select a professor. Do you want to continue?", "No selection", MessageBoxButtons.YesNo);
                        if (question == DialogResult.Yes)
                        {
                            LocalCoursesDatabase.Add(CourseTitleBox.Text);
                            LocalCoursesDatabase.Add("");
                            ChangeMsgLabel("SuccessCreate", "Courses");
                            UpdateList("Courses");
                            ClearBoxes();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        LocalCoursesDatabase.Add(CourseTitleBox.Text);
                        LocalCoursesDatabase.Add(UsersList.SelectedItems[0].SubItems[0].Text);//Add professor to the course
                        ChangeMsgLabel("SuccessCreate", "Courses");
                        UpdateList("Courses");
                        ClearBoxes();
                    }
                }
            }
            else
            {
                try
                {
                    //The problem is: When the admin wants to change only the course's title, we have to write the same
                    //professor to the list, next to the course.
                    string tempProf = CoursesList.SelectedItems[0].SubItems[1].Text;
                    DeleteSelectedItems(CoursesList.SelectedItems[0].SubItems[0].Text, "Courses");
                    if (UsersList.SelectedItems.Count == 0)//If no new prof is selected then add the old one
                    {
                        LocalCoursesDatabase.Add(CourseTitleBox.Text);
                        LocalCoursesDatabase.Add(tempProf);
                        ChangeMsgLabel("SuccessEdit", "Courses");
                        ClearBoxes();
                        UpdateList("Courses");
                    }
                    else
                    {
                        LocalCoursesDatabase.Add(CourseTitleBox.Text);
                        LocalCoursesDatabase.Add(UsersList.SelectedItems[0].SubItems[0].Text);
                        ChangeMsgLabel("SuccessEdit", "Courses");
                        ClearBoxes();
                        UpdateList("Courses");
                    }

                    /*
                     * try//if else with try catch
                     * {//if the admin does now want to select a new professor an exception will happen by the following code
                     *  reverseList.Add(UsersList.SelectedItems[0].SubItems[1].Text);
                     * }
                     * catch(Exception msg)
                     * {//The admin didn't select a new prof, so we added the previous one
                     *  reverseList.Add(tempProf);
                     * }
                     * finally
                     * {
                     *  reverseList.Add(CourseTitleBox.Text);
                     * }
                     * LocalCoursesDatabase.Add(reverseList[1]);//First add the course title
                     * LocalCoursesDatabase.Add(reverseList[0]);//then add the professor
                     */
                }
                catch (Exception msg)
                {
                    MessageBox.Show("Please first select a course");
                }
            }
        }
Exemplo n.º 2
0
        public AdminForm()
        {
            InitializeComponent();

            UserGroupBox.Controls.Add(NameBox);
            UserGroupBox.Controls.Add(RegNumBox);
            UserGroupBox.Controls.Add(SurnameBox);
            UserGroupBox.Controls.Add(PassBox);
            UserGroupBox.Controls.Add(EmailBox);
            UserGroupBox.Controls.Add(CapacityBox);
            UserGroupBox.Controls.Add(CreateEditUserBtn);
            UserGroupBox.Controls.Add(NameLabel);
            UserGroupBox.Controls.Add(RegNumLabel);
            UserGroupBox.Controls.Add(SurnameLabel);
            UserGroupBox.Controls.Add(PassLabel);
            UserGroupBox.Controls.Add(EmailLabel);
            UserGroupBox.Controls.Add(CapacityLabel);



            //Creating the UsersList
            UsersList.Bounds        = new Rectangle(new Point(196, 12), new Size(375, 500));
            UsersList.View          = View.Details;
            UsersList.FullRowSelect = true;
            UsersList.GridLines     = true;
            UsersList.Sorting       = SortOrder.Ascending;
            UsersList.Columns.Add("Registration Number", -2, HorizontalAlignment.Left);
            UsersList.Columns.Add("Name", -2, HorizontalAlignment.Left);
            UsersList.Columns.Add("Surname", -2, HorizontalAlignment.Left);
            UsersList.Columns.Add("Email", -2, HorizontalAlignment.Left);
            UsersList.Columns.Add("Capacity", -2, HorizontalAlignment.Left);

            //============================================================================



            LocalUsersDatabase.Add("kp0000");
            LocalUsersDatabase.Add("Mike");
            LocalUsersDatabase.Add("Kalliafas");
            LocalUsersDatabase.Add("*****@*****.**");
            LocalUsersDatabase.Add("Professor");

            LocalUsersDatabase.Add("p50000");
            LocalUsersDatabase.Add("Alberto");
            LocalUsersDatabase.Add("Makavegias");
            LocalUsersDatabase.Add("*****@*****.**");
            LocalUsersDatabase.Add("Student");

            LocalCoursesDatabase.Add("Algebra");
            LocalCoursesDatabase.Add("Professor 1");
            LocalCoursesDatabase.Add("Physics");
            LocalCoursesDatabase.Add("Professor 2");



            //Users Right Click menu creation
            ToolStripMenuItem UsersRightClickMenuEdit   = new ToolStripMenuItem("Edit");
            ToolStripMenuItem UsersRightClickMenuDelete = new ToolStripMenuItem("Delete");

            UsersRightClickMenuDelete.Click += new EventHandler(UserDelete_RightClick);
            UsersRightClickMenuEdit.Click   += new EventHandler(UserEdit_RightClick);
            UsersRightClickMenu.Items.AddRange(new ToolStripItem[] { UsersRightClickMenuEdit, UsersRightClickMenuDelete });

            //===================================================================================


            //Courses Right Click menu creation
            ToolStripMenuItem CoursesRightClickMenuEdit   = new ToolStripMenuItem("Edit");
            ToolStripMenuItem CoursesRightClickMenuDelete = new ToolStripMenuItem("Delete");

            CoursesRightClickMenuDelete.Click += new EventHandler(CoursesDelete_RightClick);
            CoursesRightClickMenuEdit.Click   += new EventHandler(CoursesEdit_RightClick);
            CoursesRightClickMenu.Items.AddRange(new ToolStripItem[] { CoursesRightClickMenuEdit, CoursesRightClickMenuDelete });
            //===================================================================================



            //Creating the CoursesList
            CoursesList.Bounds        = new Rectangle(new Point(150, 12), new Size(250, 500));
            CoursesList.View          = View.Details;
            CoursesList.FullRowSelect = true;
            CoursesList.GridLines     = true;
            CoursesList.Sorting       = SortOrder.Ascending;
            CoursesList.Columns.Add("Courses", -2, HorizontalAlignment.Left);
            CoursesList.Columns.Add("Professor", -2, HorizontalAlignment.Left);
            //=============================================================================



            ChangeMsgLabel("Create", "Users");

            CourseGroupBox.Text = "";
            UserGroupBox.Text   = "";

            CoursesList.Hide();
            UsersList.Hide();
            CourseGroupBox.Hide();
            CourseTitleErrorLabel.Hide();
            AssignMsgLabel.Hide();
            AssignCourseBtn.Hide();
            RegMsgLabel.Hide();
            NameMsgLabel.Hide();
            SurnameMsgLabel.Hide();
            EmailMsgLabel.Hide();
            PassMsgLabel.Hide();
            CapacityMsgLabel.Hide();
            CancelCoursesBtn.Hide();
            RegNumErrorLabel.Hide();
            NameErrorLabel.Hide();
            SurnameErrorLabel.Hide();
            EmailErrorLabel.Hide();
            PassErrorLabel.Hide();
            CapacityErrorLabel.Hide();
            CancelUsersBtn.Hide();

            RegNumErrorLabel.SendToBack();
            NameErrorLabel.SendToBack();
            SurnameErrorLabel.SendToBack();
            EmailErrorLabel.SendToBack();
            PassErrorLabel.SendToBack();
            CapacityErrorLabel.SendToBack();



            UserGroupBox.Left = (this.ClientSize.Width - UserGroupBox.Width + 100) / 2;
            UserGroupBox.Top  = (this.ClientSize.Height - UserGroupBox.Height - 100) / 2;

            UpdateList("Users");
            UpdateList("Courses");
        }