public Orders(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
     GetOrderList();
 }
 public StockClerkForm(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
     lbl_ResultsFound.Text = "";
 }
 public Checklist(UserAccount user, Order order, LoginForm loginForm)
 {
     InitializeComponent();
     userAccount = user;
     _order = order;
     _loginForm = loginForm;
 }
 public OrderForm(UserAccount user, LoginForm loginForm, Customer orderCustomer)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
     customer = orderCustomer;
 }
 public OrderForm(UserAccount user, Order _order, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     order = _order;
     InitializeComponent();
 }
 // standard constructor
 public Employee(Guid personId, string firstName, string lastName, string phoneNumber, string emailAddress,
                 Guid employeeId, UserAccount user)
     : base(personId, firstName, lastName, phoneNumber, emailAddress)
 {
     _employeeId = employeeId;
     _user = user;
     base.PersonType = Enumerations.PersonType.Employee;
 }
 // constructor for NEW Employee - This constructor creates a GUID for the new Employee
 public Employee(string firstName, string lastName, string phoneNumber, string emailAddress,
                 UserAccount user)
     : base(firstName, lastName, phoneNumber, emailAddress)
 {
     _employeeId = Guid.NewGuid();
     _user = user;
     base.PersonType = Enumerations.PersonType.Employee;
 }
 public OrderForm(UserAccount user, Guid orderId, InventoryItem invItem, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
     order = ApplicationObjects.GetOrder(orderId);
     inventoryItem = invItem;
 }
        public void Logout()
        {
            userAccount = null;
            this.txtUserName.Text = "";
            this.txtPassword.Text = "";

            this.Show();
        }
        public void ShowCheckListForm(UserAccount user, Order order, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "Checklist") == 0) { form.Show(); return; }
            }

            checkListForm = new Checklist(user, order, loginForm);
            checkListForm.Show();
        }
        public void ShowCustomerInfoForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "CustomerInfoForm") == 0) { form.Show(); return; }
            }

            customerInfoForm = new CustomerInfoForm(user, loginForm);
            customerInfoForm.Show();
        }
        public void ShowDashBoardSelectionForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name,"DashBoardSelectionForm") == 0) { form.Show(); return; }
            }

            dashBoardSelectionForm = new DashBoardSelectionForm(user, loginForm);
            dashBoardSelectionForm.Show();
        }
 public DashBoardSelectionForm(UserAccount user, LoginForm loginForm)
 {
     _loginForm = loginForm;
     userAccount = user;
     if (!user.PermissionSet.IsOperationsManager)
     {
         cbRole.Enabled = false;
         btnGO.Enabled = false;
     }
     InitializeComponent();
 }
 // ACTION EVENTS
 // FORM LOAD event
 public CustomerInfoForm(UserAccount user, LoginForm loginForm)
 {
     _loginForm = loginForm;
     userAccount = user;
     InitializeComponent();
     //Make sure all form fields are clear/empty
     ClearResults();
     //Make all customer data fields read-only by default
     MakeReadOnly();
     //Hide save changes button
     btn_SaveChanges.Visible = false;
     cbx_CustomerResultsList.Visible = false;
     cbx_SameAsMailing.Visible = false;
 }
        public static BusinessObject.UserAccount ToBusinessObject(Entities.UserAccess entity)
        {
            if (entity == null)
                return null;

            BusinessObject.UserAccount businessObject = new BusinessObject.UserAccount(
                entity.UserId,
                entity.PersonId,
                entity.UserName,
                entity.UserPassword,
                new PermissionSet(entity.PermissionToken),
                true);

            return businessObject;
        }
        public static BusinessObject.UserAccount ToBusinessObject(Entities.UserAccess entity)
        {
            if (entity == null)
            {
                return(null);
            }

            BusinessObject.UserAccount businessObject = new BusinessObject.UserAccount(
                entity.UserId,
                entity.PersonId,
                entity.UserName,
                entity.UserPassword,
                new PermissionSet(entity.PermissionToken),
                true);

            return(businessObject);
        }
        public static Entities.UserAccess ToEntity(BusinessObject.UserAccount businessObject)
        {
            if (businessObject == null)
            {
                return(null);
            }

            Entities.UserAccess entity = new Entities.UserAccess
            {
                UserId          = businessObject.UserAccountId,
                PersonId        = businessObject.PersonId,
                UserName        = businessObject.UserName,
                UserPassword    = businessObject.PasswordHash,
                PermissionToken = businessObject.PermissionSet.Token
            };

            return(entity);
        }
        // USER RELATED METHODS
        public static UserAccount AuthenticateUser(string userName, string password)
        {
            /// Accepts login input and sets the appropriate UserAccount object and permissions token
            BusinessObjects _businessObjects = new BusinessObjects();
            UserAccount userAccount = _businessObjects.GetUserAccountByUserName(userName);

            if(userAccount == null)
            {
                userAccount = new UserAccount("invalid", "invalid", true);
            }

            if(!userAccount.MatchPassword(password))
            {
                userAccount.ClearPermissionSet();
            }

            return userAccount;
        }
        public void ShowManagerMainForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "ManagerMain") == 0) { form.Show(); return; }
            }

            managerMainForm = new ManagerMain(user, loginForm);
            managerMainForm.Show();
        }
 public NewUser(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
 }
        private void btnAccept_Click(object sender, EventArgs e)
        {
            //Authenticate user
            userAccount = ApplicationObjects.AuthenticateUser(this.txtUserID.Text, this.txtOldPwd.Text);

            if (userAccount == null || userAccount.HighestPermission == null)
            {
                DialogResult result = MessageBox.Show("Failed to authenticate user.", "Authentication failed!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand);
                if (result == DialogResult.Retry)
                {
                    return;
                }
                else
                {
                    _loginForm.Logout();
                    this.Close();
                    return;
                }
            }

            //Verify the text boxes are not empty
            if (!(this.txtNewPwd.Text == String.Empty) && !(this.txtConfirmPwd.Text == String.Empty))
            {
                //Validate new and confirmed passwords match
                if (String.Compare(this.txtNewPwd.Text, this.txtConfirmPwd.Text) != 0)
                {
                    DialogResult result = MessageBox.Show("Your new and confirmed passwords did not match.", "Password mismatch", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand);
                    if (result == DialogResult.Retry)
                    {
                        return;
                    }
                    else
                    {
                        _loginForm.Logout();
                        this.Close();
                        return;
                    }
                }
            }
            else
            {
                DialogResult result = MessageBox.Show("Both new and confirmed password boxes must be populated.", "Invalid input!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Hand);
                if (result == DialogResult.Retry)
                {
                    return;
                }
                else
                {
                    _loginForm.Logout();
                    this.Close();
                    return;
                }
            }

            //Change password
            userAccount.PasswordHash = this.txtNewPwd.Text;
            ApplicationObjects.ChangePassword(userAccount);

            //Logout to re-authenticate
            MessageBox.Show("Password change complete. Please re-log in.","Success!",MessageBoxButtons.OK,MessageBoxIcon.None);
            _loginForm.Logout();
            this.Close();
        }
 public ManageUserForm(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
 }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //Do nothing if user name or password is empty.
            if ((txtUserName.Text == String.Empty) || (txtUserName.Text == null))
                return;
            if ((txtPassword.Text == String.Empty) || (txtPassword.Text == null))
                return;

            userAccount = ApplicationObjects.AuthenticateUser(txtUserName.Text, txtPassword.Text);

            if(userAccount.UserName == "invalid" && userAccount.PasswordHash == "invalid")
            {
                MessageBox.Show("Failed to authenticate with inputted username and password."
                    ,"Authentication Failed"
                    ,MessageBoxButtons.OK
                    ,MessageBoxIcon.Exclamation);
                Logout();
                return;
            }

            if (userAccount.HighestPermission == null)
            {
                MessageBox.Show("Invalid permissions token. Please contact your manager."
                    , "Authentication Failed"
                    , MessageBoxButtons.OK
                    , MessageBoxIcon.Exclamation);
                return;
            }

            //Auto forward them to the highest permission user page.
            switch (userAccount.HighestPermission)
            {
                case (Permission.OperationsManager):
                    ShowDashBoardSelectionForm(userAccount, this);
                    this.Hide();
                    break;
                case (Permission.SalesPerson):
                    ShowSalesEmployeeForm(userAccount, this);
                    this.Hide();
                    break;
                case (Permission.WorkSpecialist):
                    ShowWorkSpecialistForm(userAccount, this);
                    this.Hide();
                    break;
                case (Permission.StockClerk):
                    ShowStockClerkForm(userAccount, this);
                    this.Hide();
                    break;
            }
        }
        public void ShowWorkSpecialistForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "WorkSpecialistForm") == 0) { form.Show(); return; }
            }

            workSpecialistForm = new WorkSpecialistForm(user, loginForm);
            workSpecialistForm.Show();
        }
        public void ShowStockClerkForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "StockClerkForm") == 0) { form.Show(); return; }
            }

            stockClerkForm = new StockClerkForm(user, loginForm);
            stockClerkForm.Show();
        }
        public void ShowOrdersForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "Orders") == 0) { form.Show(); return; }
            }

            ordersForm = new Orders(user, loginForm);
            ordersForm.Show();
        }
        public void ShowOrderForm(UserAccount user, Guid orderId, InventoryItem inventoryItem, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "OrderForm") == 0) { form.Show(); return; }
            }

            orderForm = new OrderForm(user, orderId, inventoryItem, loginForm);
            orderForm.Show();
        }
 public ManagerMain(UserAccount user, LoginForm loginForm)
 {
     _loginForm = loginForm;
     userAccount = user;
     InitializeComponent();
 }
 public NewCustomer(UserAccount user, LoginForm loginForm)
 {
     _loginForm = loginForm;
     userAccount = user;
     InitializeComponent();
 }
 public WorkSpecialistForm(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
 }
 public SalesEmployeeForm(UserAccount user, LoginForm loginForm)
 {
     userAccount = user;
     _loginForm = loginForm;
     InitializeComponent();
 }
        public void ShowNewUserForm(UserAccount user, LoginForm loginForm)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (String.Compare(form.Name, "NewUser") == 0) { form.Show(); return; }
            }

            newUser = new NewUser(user, loginForm);
            newUser.Show();
        }