示例#1
0
        private void AuthenticateUser(User user)
        {
            if (user == null)
            {
                MessageBox.Show("Email or password is invalid!", "No such user!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UserCategory category = UsersDAL.GetUserCategory(user.UserID);
            switch (category)
            {
                case UserCategory.ADMIN: //open admin window
                    AdminMenu a_menu = new AdminMenu(user.UserID);
                    a_menu.FormClosed += (o, s) =>
                    {
                        Application.Exit();
                    };
                    a_menu.Owner = this;
                    a_menu.Show();
                    this.Hide();
                    break;
                case UserCategory.PARENT: //open parent window
                    ParentMenu p_menu = new ParentMenu(user.UserID);
                    p_menu.FormClosed += (o, s) =>
                    {
                        Application.Exit();
                    };
                    p_menu.Owner = this;
                    p_menu.Show();
                    this.Hide();
                    break;
                case UserCategory.STUDENT: //open student window
                    StudentMenu s_menu = new StudentMenu(user.UserID);
                    s_menu.FormClosed += (o, s) =>
                    {
                        Application.Exit();
                    };
                    s_menu.Owner = this;
                    s_menu.Show();
                    this.Hide();
                    break;
                case UserCategory.TEACHER: //open teacher window
                    TeacherMenu t_menu = new TeacherMenu(user.UserID);
                    t_menu.FormClosed += (o, s) =>
                    {
                        Application.Exit();
                    };
                    t_menu.Owner = this;
                    t_menu.Show();
                    this.Hide();
                    break;
                case UserCategory.NONE: //show error
                    goto default;
                default: MessageBox.Show("Internal error occured in resolving user category!");
                    return;
            }
        }
        private void btnAddNewParent_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtLastName.Text.Length == 0 || txtFirstName.Text.Length == 0 || txtPatronymic.Text.Length == 0)
                    throw new ArgumentException("FIO fields can't be null!");
                if (txtEmail.Text.Length == 0)
                    throw new ArgumentException("Email is required!");
                if (txtPassword.Text.Length == 0)
                    throw new ArgumentException("Password is required!");
                if (!Util.IsValidEmail(txtEmail.Text))
                    throw new ArgumentException("Email is not valid!");
                User basicUserInfo = new User
                {
                    LastName = txtLastName.Text,
                    FirstName = txtFirstName.Text,
                    Patronymic = txtPatronymic.Text,
                    DateOfBirth = dateTimePickerBirth.Value.Year == 9998 ? null : new DateTime?(dateTimePickerBirth.Value),
                    Email = txtEmail.Text,
                    Password = txtPassword.Text,
                    Phone = txtPhone.Text
                };

                Parent p = new Parent
                {
                    user = basicUserInfo,
                    Job = txtJob.Text
                };

                ParentDAL.AddNewParent(p);
                StudentDAL.AddParent(this.StudentID, p.ParentID);
                MessageBox.Show("Parent successfully added!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
 public UserInfo(User u)
 {
     UserID = u.UserID;
     FirstName = u.FirstName;
     LastName = u.LastName;
     Patronymic = u.Patronymic;
     DoB = u.DateOfBirth;
     Email = u.Email;
     Password = u.Password;
     Phone = u.Phone;
 }
示例#4
0
        private void GatherInfoFromFields()
        {
            User u = new User();
            u.UserID = int.Parse(lblUserID.Text);
            u.FirstName = lblFirstName.Text;
            u.LastName = txtLastName.Text;
            u.Patronymic = lblPatronymic.Text;
            try
            {
                u.DateOfBirth = DateTime.Parse(lblDob.Text);
            }
            catch
            { u.DateOfBirth = null; }
            u.Password = this.info.Password;

            if (!Util.IsValidEmail(txtEmail.Text))
                throw new ArgumentException("Email string is not a valid email!");
            u.Email = txtEmail.Text;
            u.Phone = txtPhone.Text;
            UserInfo newInfo = new UserInfo(u);
            this.info = newInfo;
        }