예제 #1
0
        private void button3Save_Click(object sender, EventArgs e)
        {
            // save or update user
            dataLayer.User user;

            // new user
            if (listBox3Users.SelectedIndex == 0)
            {
                user = new dataLayer.User();
            }
            // old user
            else
            {
                user = (dataLayer.User)listBox3Users.SelectedItem;
            }

            if (textBox3UserName.Text != "" &&
                textBox3Email.Text != "" &&
                textBox3PhoneNum.Text != "")
            {
                user.UserName  = textBox3UserName.Text;
                user.UserEmail = textBox3Email.Text;
                user.UserTel   = textBox3PhoneNum.Text;
                user.Save();
                PopulateUserPage();
                MessageBox.Show(this, "User saved.", "Success");
            }
            else
            {
                MessageBox.Show(this, "No field Can be left blank.", "Form Error");
            }
        }
예제 #2
0
        /// <summary>
        /// Fills the user page/tab with data
        /// </summary>
        private void PopulateUserPage()
        {
            // clear
            labelVal3UserId.Text  = "";
            textBox3UserName.Text = "";
            textBox3Email.Text    = "";
            textBox3PhoneNum.Text = "";

            // put users in box
            List <dataLayer.User> users = dataLayer.Users.GetAllUsers();

            dataLayer.User newUser = new dataLayer.User();
            newUser.UserName = "******";
            users.Insert(0, newUser);
            listBox3Users.DataSource    = users;
            listBox3Users.DisplayMember = "UserName";
        }
예제 #3
0
        private void listBox3Users_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show user info
            if (listBox3Users.SelectedIndex != 0)
            {
                dataLayer.User user = ((dataLayer.User)listBox3Users.SelectedItem);

                labelVal3UserId.Text  = user.UserId.ToString();
                textBox3UserName.Text = user.UserName;
                textBox3Email.Text    = user.UserEmail;
                textBox3PhoneNum.Text = user.UserTel;
            }
            //blank
            else
            {
                labelVal3UserId.Text  = "";
                textBox3UserName.Text = "";
                textBox3Email.Text    = "";
                textBox3PhoneNum.Text = "";
            }
        }
예제 #4
0
 private void button3Delete_Click(object sender, EventArgs e)
 {
     if (listBox3Users.SelectedIndex > 0)
     {
         dataLayer.User user = (dataLayer.User)listBox3Users.SelectedItem;
         // no delete admin
         if (user.UserId == 1)
         {
             MessageBox.Show(this, "Cannot delete admin.", "Error");
         }
         else
         {
             if (user.Delete())
             {
                 MessageBox.Show(this, "User Deleted.", "Success");
                 PopulateUserPage();
             }
             else
             {
                 MessageBox.Show(this, "Cannot delete user.", "Error");
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Click this button to sign the user in.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button0Go_Click(object sender, EventArgs e)
        {
            // make sure all tabs are removed
            if (tabsBugTracker.TabPages.Contains(tabPageApplications))
            {
                tabsBugTracker.TabPages.Remove(tabPageApplications);
            }
            if (tabsBugTracker.TabPages.Contains(tabPageBugs))
            {
                tabsBugTracker.TabPages.Remove(tabPageBugs);
            }
            if (tabsBugTracker.TabPages.Contains(tabPageUsers))
            {
                tabsBugTracker.TabPages.Remove(tabPageUsers);
            }

            string inputName = textBox0UserName.Text;
            bool   isAdmin   = (inputName.Equals("admin")); // flag for admin

            // look for user in database
            dataLayer.User user = dataLayer.Users.GetUserByUserName(inputName);

            // if user is in database, sign in
            if (user != null)
            {
                this.Text = FORM_TITLE + " - " + inputName;
                UserSignOn(isAdmin);         // sign on user
                tabsBugTracker.SelectTab(1); // move focus to next tab
                loggedInUser = user.UserId;
            }
            // else show pop up
            else
            {
                MessageBox.Show(this, "The user '" + inputName + "' was not found in the system.", "User Not Found");
            }
        }