Exemplo n.º 1
0
        /// <summary>
        /// Logs into the system if the username and password match.
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The event args</param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.AppStarting;
            if (UsernameBox.Text != "Username")
            {
                User user = DatabaseParser.GetUserByUsername(UsernameBox.Text);
                if (user == null || user.Password != PasswordBox.Text)
                {
                    CustomMsgBox.ShowOk("Wrong username or password", "Error", CustomMsgBoxIcon.Error);

                    // resets password with false login information
                    if (PasswordBox.Text != "Password")
                    {
                        PasswordBox.Clear();
                    }
                    return;
                }

                Session.LoadUser(user);

                this.Hide();
                MainWindow main = new MainWindow();
                main.ShowDialog(this);
                Session.LogOut();
                // resets information after logout
                ResetInformation();
                Cursor = Cursors.Arrow;
            }
            else
            {
                CustomMsgBox.ShowOk("Wrong username or password", "Error", CustomMsgBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers the given user in the system, if all fields are valid.
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The event args</param>
        private void registerCreateNewUserButton_Click(object sender, EventArgs e)
        {
            if (_isFirstnameOk && _isLastnameOk && _isPhoneOk && _isEmailOk && _isCprOk && _isAdressOk &&
                _isCityOk && _isZipOk && _isUsernameOk && _isPasswordOk && _isVerifyPasswordOk && _isSignatureOk)
            {
                bool UserCreated = DatabaseParser.AddUser(registerFirstnameBox.Text, registerLastnameBox.Text,
                                                          registerPhoneBox.Text, registerEmailBox.Text,
                                                          registerCprBox.Text, registerAdressBox.Text, registerZipBox.Text, registerCityBox.Text,
                                                          registerUsernameBox.Text, registerPasswordBox.Text, _uploader.SaveProfilePicture(ProfileImage, Properties.Settings.Default["PictureUpload"].ToString()),
                                                          _uploader.SavePicture(_signatureImage, Properties.Settings.Default["PictureUpload"].ToString()));

                if (UserCreated)
                {
                    CustomMsgBox.ShowOk("You have succesfully created a user", "Sucess", CustomMsgBoxIcon.Complete);
                    this.Dispose();
                    _loginForm.Show();
                }
                else
                {
                    CustomMsgBox.ShowOk("Failed to create new user, please try again later!", "Failed",
                                        CustomMsgBoxIcon.Error);
                }
            }
            else
            {
                foreach (TextboxBorderColor tb in this.Controls.OfType <TextboxBorderColor>())
                {
                    if (string.IsNullOrEmpty(tb.Text))
                    {
                        tb.BorderColor = Color.Crimson;
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method used to add the selected period as an appointment to the database
        /// </summary>
        /// <param name="sender">The Object Sender</param>
        /// <param name="e">The EventArgs</param>
        private void AddAppointmentButton_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(LessonTypecomboBox.Text) && !String.IsNullOrEmpty(StartTimecomboBox.Text) && !String.IsNullOrEmpty(lessonsComboBox.Text))
            {
                TimeSpan startTime = TimeSpan.Parse(StartTimecomboBox.Text);
                DateTime dateToAdd = date.Date + startTime;

                bool appointmentAdded = DatabaseParser.AddAppointment(LessonTypecomboBox.Text, dateToAdd, (int)lessonsComboBox.SelectedItem,
                                                                      Session.LoggedInUser.Id.ToString());

                if (appointmentAdded)
                {
                    CustomMsgBox.ShowOk("Succes", "Appointment succesfully added", CustomMsgBoxIcon.Complete);

                    AppointmentStructure appointmentStructure =
                        new AppointmentStructure(-1, Session.LoggedInUser.Id,
                                                 dateToAdd, (int)lessonsComboBox.SelectedItem, LessonTypecomboBox.Text, false,
                                                 Session.LoggedInUser.Fullname);

                    _appointments.Add(new Appointment(appointmentStructure));
                    this.Dispose();
                }
                else
                {
                    CustomMsgBox.ShowOk("Failure", "Appointment failed to upload", CustomMsgBoxIcon.Error);
                }
            }
            else
            {
                CustomMsgBox.ShowOk("Failure", "Some fields need to be filled", CustomMsgBoxIcon.Warrning);
            }
        }
        public static DialogResult Show(string text, string caption, Image symbol)
        {
            MsgBox = new CustomMsgBox();
            MsgBox.textLabel.Text         = text;
            MsgBox.captionLabel.Text      = caption;
            MsgBox.symbolpictureBox.Image = symbol;
            MsgBox.ShowDialog();

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Checks if changes were made else show warning
 /// </summary>
 /// <param name="sender">The object sender</param>
 /// <param name="e">The EventArgs</param>
 private void saveButton_Click(object sender, EventArgs e)
 {
     if (edited)
     {
         this.Hide();
     }
     else
     {
         CustomMsgBox.ShowOk("Please write your signature in the box", "Missing Signature",
                             CustomMsgBoxIcon.Error);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Completes or denies lessons and closes the form
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The EventArgs</param>
        private void saveButton_Click(object sender, EventArgs e)
        {
            StringBuilder text = new StringBuilder();

            text.AppendLine("Are you sure you want to complete the lesson with the following attendees?");
            text.AppendLine();
            text.AppendLine("Attended:");
            // Lists All the students who attended the lesson
            for (int i = 0; i < attendingStudentsList.Items.Count; i++)
            {
                if (attendingStudentsList.Items[i].Checked)
                {
                    text.AppendLine(attendingStudentsList.Items[i].SubItems[1].Text);
                }
            }
            text.AppendLine();
            text.AppendLine("Did Not Attend:");
            // Lists All the students who did not attend the lesson
            for (int i = 0; i < attendingStudentsList.Items.Count; i++)
            {
                if (!attendingStudentsList.Items[i].Checked)
                {
                    text.AppendLine(attendingStudentsList.Items[i].SubItems[1].Text);
                }
            }

            // Show the dialog and save result
            DialogResult result = CustomMsgBox.ShowConfirm(text.ToString(), "Confirm Attendees", CustomMsgBoxIcon.Complete, 20 * attendingStudentsList.Items.Count + 80);

            if (result == DialogResult.OK)
            {
                for (int i = 0; i < attendingStudentsList.Items.Count; i++)
                {
                    // If row is checked then complete lesson else deny lesson
                    if (attendingStudentsList.Items[i].Checked)
                    {
                        DatabaseParser.SetLessonToStatus(_lessonList[i].StudentId, _lessonList[i].AppointmentID,
                                                         _lessonList[i].Progress, true);
                    }
                    else
                    {
                        List <Lesson> deleteList = DatabaseParser.FindLessonsToCancel(_lessonList[i].TemplateID,
                                                                                      _lessonList[i].Progress, _lessonList[i].StudentId);
                        DatabaseParser.DeleteLessons(deleteList);
                    }
                }
                this.DialogResult = DialogResult.Yes;
                this.Close();
            }
        }
        /// <summary>
        /// Saves all the changes made
        /// </summary>
        /// <param name="sender">The object sender</param>
        /// <param name="e">The event args</param
        private void saveChangesButton_Click(object sender, EventArgs e)
        {
            if (!(usernameOk && passwordOk && verifyPasswordOk && firstnameOk && lastnameOk && phoneOk && emailOk && addressOk && zipOk && cityOk))
            {
                CustomMsgBox.ShowOk("Please fix the red boxes before saving", "Failed", CustomMsgBoxIcon.Warrning);
                return;
            }

            bool   updateSuccess;
            string picturePath   = uploader.SaveProfilePicture(ProfilePicture, Settings.Default["PictureUpload"].ToString());
            string signaturePath = uploader.SavePicture(_signatureImage, Settings.Default["PictureUpload"].ToString());

            if (picturePath == null)
            {
                picturePath = _user.PicturePath;
            }

            if (signaturePath == null)
            {
                signaturePath = _user.SignaturePath;
            }

            if (editPasswordBox.Text != editPasswordBox.defaultText)
            {
                updateSuccess = DatabaseParser.UpdateUser(_user.Cpr, firstnameBox.Text, lastnameBox.Text, phoneBox.Text, emailBox.Text, addressBox.Text,
                                                          zipBox.Text, cityBox.Text, usernameBox.Text, editPasswordBox.Text, picturePath, signaturePath, instructorCheckBox.Checked ? "true" : "false");
                _user.PicturePath   = picturePath;
                _user.SignaturePath = signaturePath;
            }
            else
            {
                updateSuccess = DatabaseParser.UpdateUser(_user.Cpr, firstnameBox.Text, lastnameBox.Text, phoneBox.Text, emailBox.Text, addressBox.Text,
                                                          zipBox.Text, cityBox.Text, usernameBox.Text, _user.Password, picturePath, signaturePath, instructorCheckBox.Checked ? "true" : "false");
                _user.PicturePath   = picturePath;
                _user.SignaturePath = signaturePath;
            }

            if (updateSuccess)
            {
                CustomMsgBox.ShowOk("You have succesfully updated the profile", "Success", CustomMsgBoxIcon.Complete);
                Session.LoggedInUser = DatabaseParser.GetUserByUsername(usernameBox.Text);
                this.Dispose();
            }
            else
            {
                CustomMsgBox.ShowOk("No connection could be made to the database, please try again later", "No Connection", CustomMsgBoxIcon.Error);
            }
        }
        public static DialogResult Show(string text, string caption, Image symbol, int extraHeight)
        {
            MsgBox      = new CustomMsgBox();
            MsgBox.Size = new Size(MsgBox.Size.Width, MsgBox.Size.Height + extraHeight);
            MsgBox.textLabel.Visible      = false;
            MsgBox.messageBox.Size        = new Size(MsgBox.messageBox.Size.Width, MsgBox.messageBox.Size.Height + extraHeight);
            MsgBox.messageBox.Location    = new Point(MsgBox.messageBox.Location.X, 40);
            MsgBox.messageBox.Text        = text;
            MsgBox.messageBox.Visible     = true;
            MsgBox.okButton.Text          = "Confirm";
            MsgBox.okButton.Location      = new Point(MsgBox.okButton.Location.X + 50, MsgBox.Size.Height - 30);
            MsgBox.button1.Location       = new Point(MsgBox.button1.Location.X, MsgBox.Size.Height - 30);
            MsgBox.button2.Location       = new Point(MsgBox.button2.Location.X, MsgBox.Size.Height - 30);
            MsgBox.cancelButton.Location  = new Point(MsgBox.cancelButton.Location.X - 110, MsgBox.Size.Height - 30);
            MsgBox.cancelButton.Visible   = true;
            MsgBox.captionLabel.Text      = caption;
            MsgBox.symbolpictureBox.Image = symbol;
            MsgBox.ShowDialog();

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Method used when a user clicks on add appointment, makes sure that the selected perido is added to the database
        /// </summary>
        /// <param name="sender">The Object Sender</param>
        /// <param name="e">The EventArgs</param>
        private void AddAppointmentButton_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(lessonsComboBox.Text) && !String.IsNullOrWhiteSpace(StartTimecomboBox.Text))
            {
                bool result = AddLesson();

                if (result)
                {
                    CustomMsgBox.ShowOk("Successfully booked!", "Sucess", CustomMsgBoxIcon.Complete);
                    _appointment.AppointmentHighlight(ColorScheme.CalendarBooked);
                    this.Dispose();
                }
                else
                {
                    CustomMsgBox.ShowOk("Error connecting to database", "Failure", CustomMsgBoxIcon.Error);
                }
            }
            else
            {
                CustomMsgBox.ShowOk("Please select a timeperiod you wish to book your appointment", "Warning", CustomMsgBoxIcon.Warrning);
            }
        }