Exemple #1
0
        private void listView_AllSurveys_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView_AllSurveys.SelectedItems.Count != 1)
            {
                txt_EditSurveyDetailsName.Text = ""; txt_ViewSurveyDetailsName.Text = "";
                listView_ViewSurveyQuestions.Items.Clear(); listView_EditSurveyQuestions.Items.Clear();
                txt_ViewSurveyDetailsName.Tag         = null; txt_EditSurveyDetailsName.Tag = null;
                btn_StartSurvey.Enabled               = btn_StartSurvey.Visible = false;
                pic_SaveSurveyChanges.BackgroundImage = Properties.Resources.save_icon_disabled_24x24;
                pic_SaveSurveyChanges.Cursor          = Cursors.Arrow;
                IsSelectedSurveyOriginalNameChanged   = false;
                txt_EditSurveyDetailsName.Tag         = -1;
                return;
            }
            else
            {
                btn_StartSurvey.Enabled = btn_StartSurvey.Visible = true;
            }

            ListViewItem selectedItem = listView_AllSurveys.SelectedItems[0];
            long         SurveyID     = Convert.ToInt64(selectedItem.Tag);

            if (LoggedUser.IsAdministrator())
            {
                UpdateEditSurveyDetails(SurveyID);
            }
            else
            {
                UpdateViewSurveyDetails(SurveyID);
            }
        }
Exemple #2
0
        private void Settings_Load(object sender, EventArgs e)
        {
            AddManyTo(MenuPanels, panel_About, panel_Me, panel_Users, panel_Database);

            if (!LoggedUser.IsAdministrator())
            {
                RemoveManyFrom(treeView_Menu.Nodes, USERS, DATABASE);
            }

            treeView_Menu.SelectedNode = treeView_Menu.Nodes[ABOUT];
        }
Exemple #3
0
        // Promote / Demote users
        private void promoteDemoteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int SelectedUsersCount = listView_Users.SelectedItems.Count;

            if (SelectedUsersCount == 0)
            {
                return;
            }

            long AdminCount;
            long SelectedAdminCount;

            long AdminRoleID;
            long UserRoleID;

            using (UserController userController = new UserController())
                using (RoleController roleController = new RoleController())
                {
                    AdminRoleID = roleController.GetRoleID("Admin");
                    UserRoleID  = roleController.GetRoleID("User");

                    // Check if Admin want to demote all Admins
                    List <UserModelDataTransferObject> AdminsList = userController.GetUsersByRoleID(AdminRoleID);
                    AdminCount         = AdminsList.Count;
                    SelectedAdminCount = 0;

                    foreach (ListViewItem item in listView_Users.SelectedItems)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                        if (CurrentUser.IsAdministrator())
                        {
                            ++SelectedAdminCount;
                        }
                    }
                }

            if (AdminCount == SelectedAdminCount && AdminCount == listView_Users.SelectedItems.Count)
            {
                MaterialMessageBox.Show("You cannot demote all Administrators.", "Easy Survey - Demote Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                return;
            }


            // Check if Admin wants to demote himself
            bool AdminSelectedHimself = false;

            foreach (ListViewItem item in listView_Users.SelectedItems)
            {
                long UserID = Convert.ToInt64(item.Tag);
                if (LoggedUser.UserID == UserID)
                {
                    AdminSelectedHimself = true; break;
                }
            }
            if (AdminSelectedHimself)
            {
                MaterialMessageBox.Show("You cannot demote yourself.", "Easy Survey - Demote Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                return;
            }

            // Demote / Promote selected users.
            using (UserController userController = new UserController())
                using (UserRoleController userRoleController = new UserRoleController())
                    foreach (ListViewItem item in listView_Users.SelectedItems)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                        if (CurrentUser.IsAdministrator()) // Demote to standard user.
                        {
                            userRoleController.SetUserRole(UserID, UserRoleID);
                            item.Group = listView_Users.Groups["User"];
                        }
                        else if (!CurrentUser.IsAdministrator()) // Promote to admin.
                        {
                            userRoleController.SetUserRole(UserID, AdminRoleID);
                            item.Group = listView_Users.Groups["Administrator"];
                        }
                    }
        }
Exemple #4
0
        private void materialContextMenuStrip_Users_Opening(object sender, CancelEventArgs e)
        {
            long SelectedUsers = listView_Users.SelectedItems.Count;

            // Promote / Demote ...
            bool Promote = false;
            bool Demote  = false;

            using (UserController userController = new UserController())
                foreach (ListViewItem item in listView_Users.SelectedItems)
                {
                    long UserID = Convert.ToInt64(item.Tag);
                    UserModelDataTransferObject CurrentUser = userController.GetUserByID(UserID);
                    if (CurrentUser.IsAdministrator())
                    {
                        Demote = true;
                    }
                    else
                    {
                        Promote = true;
                    }
                }

            if (Promote == Demote)
            {
                promoteDemoteToolStripMenuItem.Enabled = false;
                promoteDemoteToolStripMenuItem.Text    = "Promote / Demote...";
            }
            else
            {
                promoteDemoteToolStripMenuItem.Enabled = true;
                if (Promote)
                {
                    promoteDemoteToolStripMenuItem.Image = Properties.Resources.promote_icon_16x16;
                    promoteDemoteToolStripMenuItem.Text  = "Promote...";
                }
                else if (Demote)
                {
                    promoteDemoteToolStripMenuItem.Image = Properties.Resources.demote_icon_16x16;
                    promoteDemoteToolStripMenuItem.Text  = "Demote...";
                }
            }

            // Change / New ...
            bool Change = false;
            bool New    = false;

            if (SelectedUsers == 0)
            {
                return;
            }

            foreach (ListViewItem item in listView_Users.SelectedItems)
            {
                long UserID = Convert.ToInt64(item.Tag);
                UserModelDataTransferObject CurrentUser;
                using (UserController userController = new UserController())
                    CurrentUser = userController.GetUserByID(UserID);
                if (CurrentUser.UserPassword == null)
                {
                    New = true;
                }
                else
                {
                    Change = true;
                }
            }

            if (Change && New)
            {
                newToolStripMenuItem.Text = "Change / New...";
            }
            else if (Change)
            {
                newToolStripMenuItem.Text = "Change...";
            }
            else if (New)
            {
                newToolStripMenuItem.Text = "New...";
            }
        }
Exemple #5
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int SelectedUsersCount = listView_Users.SelectedItems.Count;

            if (SelectedUsersCount == 0)
            {
                return;
            }

            IEnumerable <ListViewItem> SelectedUsers = listView_Users.SelectedItems.Cast <ListViewItem>();

            using (UserController userController = new UserController())
                using (RoleController roleController = new RoleController())
                {
                    // Check if Admin selected all Admins to be deleted.
                    long AdminRoleID = roleController.GetRoleID("Admin");
                    List <UserModelDataTransferObject> AdminsList = userController.GetUsersByRoleID(AdminRoleID);
                    long AdminCount         = AdminsList.Count;
                    long SelectedAdminCount = 0;
                    foreach (ListViewItem item in SelectedUsers)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        UserModelDataTransferObject SelectedUser = userController.GetUserByID(UserID);
                        if (SelectedUser.IsAdministrator())
                        {
                            ++SelectedAdminCount;
                        }
                    }
                    if (AdminCount == SelectedAdminCount)
                    {
                        MaterialMessageBox.Show("You cannot delete all Administrators.", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                        return;
                    }

                    // Check if Admin selected his account to de deleted.
                    bool SelectedSelfAccount = false;
                    foreach (ListViewItem item in SelectedUsers)
                    {
                        long UserID = Convert.ToInt64(item.Tag);
                        if (LoggedUser.UserID == UserID)
                        {
                            SelectedSelfAccount = true; break;
                        }
                    }
                    if (SelectedSelfAccount)
                    {
                        MaterialMessageBox.Show("You cannot delete your own account.", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error);
                        return;
                    }

                    // Delete selected users.
                    MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None;
                    result = MaterialMessageBox.Show("Are you sure you want to delete all " + SelectedUsersCount + " selected users?", "Easy Survey - Delete Users", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning);

                    if (result == MaterialMessageBox.MessageBoxResult.Yes)
                    {
                        foreach (ListViewItem item in SelectedUsers)
                        {
                            long UserID = Convert.ToInt64(item.Tag);

                            // Delete from Database
                            userController.Delete(UserID);

                            // Delete from ListView
                            foreach (ListViewItem listViewItemToDelete in listView_Users.SelectedItems)
                            {
                                long ListViewUserID = Convert.ToInt64(listViewItemToDelete.Tag);
                                if (UserID == ListViewUserID)
                                {
                                    listView_Users.Items.Remove(listViewItemToDelete);
                                }
                            }
                        }
                    }
                }
        }