コード例 #1
0
        private void submit_btn_Click(object sender, EventArgs e)
        {
            try
            {
                var username    = username_tb.Text;
                var employee    = employee_tb.Text;
                var password    = password_tb.Text;
                var accessLevel = accessLevel_cb.Text;
                var roleId      = (int)accessLevel_cb.SelectedValue;
                //var startDate = startDate_dtp.Text;



                if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(employee))
                {
                    MessageBox.Show("Missing Information (Username/Password)");
                }
                if (string.IsNullOrWhiteSpace(password_tb.Text) || string.IsNullOrWhiteSpace(accessLevel_cb.Text))
                {
                    MessageBox.Show("Missing Information (Password/Access Level)");
                }
                if (string.IsNullOrWhiteSpace(startDate_dtp.Text))
                {
                    MessageBox.Show("Missing Information (Start Date)");
                }


                var user = new UsersLogin
                {
                    username      = username,
                    password      = password,
                    active_status = true,
                    employee_name = employee,
                    start_date    = startDate_dtp.Value,
                };

                notebookAppEntities.UsersLogins.Add(user);
                notebookAppEntities.SaveChanges();

                var userid   = user.id;
                var userRole = new UserRole
                {
                    rolesID = roleId,
                    userID  = userid,
                };


                notebookAppEntities.UserRoles.Add(userRole);
                notebookAppEntities.SaveChanges();
                MessageBox.Show("User Added Successfully...");
                Close();
            }

            catch (Exception)
            {
                MessageBox.Show("An Error has Occured...");
            }
        }
コード例 #2
0
        private void reset_btn_Click(object sender, EventArgs e)
        {
            try
            {
                var password        = newPassword_tb.Text;
                var confirmPassword = confirmPassword_tb.Text;
                var user            = notebookAppEntities.UsersLogins.FirstOrDefault(q => q.username == _user.username);
                //UsersLogin.FirstOrDefault(q => q.id == _user.id);

                if (password != confirmPassword)
                {
                    MessageBox.Show("Passwords do not match. Please try again!");
                }
                _user.password = Utils.HashPassword(password);

                notebookAppEntities.SaveChanges();

                MessageBox.Show("Password Reset Successful...");
                Close();
            }
            catch (Exception)
            {
                MessageBox.Show("An Error Has Occured.Please Try Again...");
            }
        }