Пример #1
0
        // on form load
        private void frmLogin_Load(object sender, EventArgs e)
        {
            // creates instance of databasehelper on db
            db     = new clDB();
            helper = new clHelper();

            // empties error message label
            lblLoginError.Text = String.Empty;
        }
Пример #2
0
        // event method for when the form is loaded
        private void frmNewBook_Load(object sender, EventArgs e)
        {
            // creates new instance of the databasehelper object
            db   = new clDB();
            help = new clHelper();

            if (tempVars.bookingMode == tempVars.modes.View)
            {
                foreach (Control c in this.Controls)
                {
                    if (c is TextBox || c is Button || c is NumericUpDown || c is DateTimePicker)
                    {
                        c.Enabled = false;
                    }
                }
            }

            // defaults edit mode to false
            modeEdit = false;

            // if a booking id has been set
            if (tempVars.editBookingId != -1)
            {
                // set all vars to edit mode
                this.Text = "Edit Booking";
                modeEdit  = true;
                editID    = tempVars.editBookingId;

                // gets booking details
                book = db.getBooking(tempVars.editBookingId);

                // fills out the form elements with the existing details
                txtNotes.Text   = book.notes;
                txtPeriod.Value = book.period;
                txtRoom.Value   = book.roomID;
                dtDate.MinDate  = DateTime.MinValue;
                dtDate.MaxDate  = DateTime.MaxValue;
                dtDate.Value    = book.date;

                // resets the booking id
                tempVars.editBookingId = -1;
            }
            else
            {
                // sets all vars to new book mode
                this.Text             = "New Booking";
                modeEdit              = false;
                btnDeleteBook.Enabled = false;
                btnDeleteBook.Visible = false;
            }

            // if user has permission to edit booking (either booked themselves or they're an admin

            if (book != null && (book.UserID == session.userID || session.role == user.roles.Admin))
            {
                // enable ability to delete booking
                btnDeleteBook.Enabled = true;
            }
            else
            {
                btnDeleteBook.Enabled = false;
            }
        }
Пример #3
0
        // method called when the form is loaded
        private void frmEditUser_Load(object sender, EventArgs e)
        {
            // if the form has been opened in view mode
            if (tempVars.userMode == tempVars.modes.View)
            {
                // foreach control, disable it if it's a textbox or button
                foreach (Control c in this.Controls)
                {
                    if (c is TextBox || c is Button)
                    {
                        c.Enabled = false;
                    }
                }
            }

            // disable delete button by default
            btnDeleteUser.Enabled = false;


            // adding roles to the role dropdown list
            bxRoleList.Items.Add("Admin");
            bxRoleList.Items.Add("Teacher");
            bxRoleList.Items.Add("Student");

            // setting the dropdown type
            bxRoleList.DropDownStyle = ComboBoxStyle.DropDownList;

            // enable the role selection if the user is an admin
            if (session.role != user.roles.Admin)
            {
                bxRoleList.Enabled = false;
            }
            else
            {
                bxRoleList.Enabled = true;
                // since the user is an admin, enable the delete button
                if (session.userID != tempVars.editUserId)
                {
                    btnDeleteUser.Enabled = true;
                }
            }

            // create new object of helper class
            helper = new clHelper();
            // create new object of database class
            db = new clDB();

            // if the form is loaded to edit a user
            if (tempVars.editUserId != -1)
            {
                // set the form title
                this.Text = "Edit user";

                // define that a new user is not being created
                newUserMode = false;

                // set the local variable userID
                userID = tempVars.editUserId;

                // get the user details from the database
                user = db.getUser(userID);

                // reset the Id stored in tempvars back to default
                tempVars.editUserId = 0;

                // fill the controls with the user details
                txtName1.Text = user.firstname;
                txtName2.Text = user.secondname;
                switch (user.role)
                {
                case (user.roles.Admin):
                    bxRoleList.Text = "Admin";
                    break;

                case (user.roles.Teacher):
                    bxRoleList.Text = "Teacher";
                    break;

                case (user.roles.Student):
                    bxRoleList.Text = "Student";
                    break;

                default:
                    bxRoleList.Text = "Student";
                    break;
                }
                txtUsername.Text = user.username;
            }
            // if the form is loaded to create a new user
            else
            {
                // set the title of the form
                this.Text = "New User";

                // set the mode to new user
                newUserMode = true;

                // disable and hide the delete button
                btnDeleteUser.Enabled = false;
                btnDeleteUser.Visible = false;

                // enable selection of role
                bxRoleList.Enabled = true;
            }
        }