private void deleteToolStripMenuItem_Delete_Click(object sender, EventArgs e) { int SelectedResults = listView_UserReports.SelectedItems.Count; if (SelectedResults == 0) { return; } MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; result = MaterialMessageBox.Show("Are you sure you want to delete " + SelectedResults + " selected reports?", "Easy Survey - Delete Reports", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning); IEnumerable <ListViewItem> SelectedUserReports = listView_UserReports.SelectedItems.Cast <ListViewItem>(); if (result == MaterialMessageBox.MessageBoxResult.Yes) { using (ResultController resultController = new ResultController()) foreach (ListViewItem reportItem in SelectedUserReports) { long ResultID = Convert.ToInt64(reportItem.Tag); resultController.Delete(ResultID); listView_UserReports.Items.Remove(reportItem); } RefreshReports(); } }
private void pic_Restore_Click(object sender, EventArgs e) { string AppPath = Assembly.GetExecutingAssembly().Location; string DirectoryApp = Path.GetDirectoryName(AppPath); string BackupDirectory = DirectoryApp + "\\backup"; openFileDialog_Restore.InitialDirectory = BackupDirectory; DialogResult Result = openFileDialog_Restore.ShowDialog(); if (Result == DialogResult.OK) { string RestoreBackupPath = openFileDialog_Restore.FileName; try { using (Database DB = new Database()) DB.Restore(RestoreBackupPath); MaterialMessageBox.Show("Database Backup has been restored successfully!" + Environment.NewLine + "You will be redirecte to Login Page.", "Easy Survey - Database Restore", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Information); Program.frm_MainForm.Close(); base.Close(); } catch (Exception ex) { MaterialMessageBox.Show(ex.ToString(), "Easy Survey - Database Restore", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error); } } }
private void pic_Export_Click(object sender, EventArgs e) { string DatabaseExportName; using (Database DB = new Database()) DatabaseExportName = DB.Export(); MaterialMessageBox.Show("Database has been exported with name " + DatabaseExportName, "Easy Survey - Database export", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Information); }
private void pic_Backup_Click(object sender, EventArgs e) { string DatabaseBackupName; using (Database DB = new Database()) DatabaseBackupName = DB.Backup(Database.BackupReason.User); MaterialMessageBox.Show("Backup has been saved with name " + DatabaseBackupName, "Easy Survey - Database backup", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Information); }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { int SelectedSurveysCount = listView_AllSurveys.SelectedItems.Count; MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; string TextMessage = "Sunteti sigur ca vrei sa stergeti chestionarele selectate?"; MaterialMessageBox.MessageBoxIcon IconMessage = MaterialMessageBox.MessageBoxIcon.Warning; //Check if any Question from Surveys are contained into Attitudes long QuestionsCount = 0; using (AttitudeController attitudeController = new AttitudeController()) using (QuestionController questionController = new QuestionController()) { foreach (ListViewItem selectedItem in listView_AllSurveys.SelectedItems) { long SurveyID = Convert.ToInt64(selectedItem.Tag); List <Question> Questions = questionController.GetQuestionsForSurvey(SurveyID); foreach (Question question in Questions) { if (attitudeController.Contains(question.QuestionID)) { ++QuestionsCount; } } } } if (QuestionsCount > 0) { IconMessage = MaterialMessageBox.MessageBoxIcon.Error; TextMessage += Environment.NewLine + QuestionsCount + " (de) intrebari sunt continute in cateva Definitii de Atitudini(daca selectati DA acestea vor fi sterse din Definitii)."; } if (SelectedSurveysCount > 0) { result = MaterialMessageBox.Show(TextMessage, "Easy Survey - Delete Surveys", MaterialMessageBox.MessageBoxButtons.YesNo, IconMessage); } if (result == MaterialMessageBox.MessageBoxResult.Yes) { using (SurveyController surveyController = new SurveyController()) foreach (ListViewItem selectedItem in listView_AllSurveys.SelectedItems) { long SurveyID = Convert.ToInt64(selectedItem.Tag); Surveys.Remove(Surveys.Find(i => i.SurveyID == SurveyID)); surveyController.Delete(SurveyID); listView_AllSurveys.Items.Remove(selectedItem); } } }
private void toolStripMenuItem_DeleteQuestions_Click(object sender, EventArgs e) { int SelectedQuestionsCount = listView_EditSurveyQuestions.SelectedItems.Count; MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; string TextMessage = "Sunteti sigur ca vrei sa stergeti intrebarile selectate?"; MaterialMessageBox.MessageBoxIcon IconMessage = MaterialMessageBox.MessageBoxIcon.Warning; long QuestionCount = 0; using (AttitudeController attitudeController = new AttitudeController()) foreach (ListViewItem selectedItem in listView_EditSurveyQuestions.SelectedItems) { long QuestionID = Convert.ToInt64(selectedItem.Tag); if (attitudeController.Contains(QuestionID)) { QuestionCount++; } } if (QuestionCount > 0) { TextMessage += Environment.NewLine + QuestionCount + " (de) intrebari sunt continute in Definitii de Atitudini(daca selectati DA acestea vor fi sterse din Definitii)"; IconMessage = MaterialMessageBox.MessageBoxIcon.Error; } if (SelectedQuestionsCount > 0) { result = MaterialMessageBox.Show(TextMessage, "Easy Survey - Delete Questions", MaterialMessageBox.MessageBoxButtons.YesNo, IconMessage); } if (result == MaterialMessageBox.MessageBoxResult.Yes) { using (QuestionController questionController = new QuestionController()) foreach (ListViewItem selectedItem in listView_EditSurveyQuestions.SelectedItems) { long QuestionID = Convert.ToInt64(selectedItem.Tag); long SurveyID = Convert.ToInt64(txt_EditSurveyDetailsName.Tag); questionController.Delete(QuestionID, SurveyID); listView_EditSurveyQuestions.Items.Remove(selectedItem); } } }
private void ConductSurvey_FormClosing(object sender, FormClosingEventArgs e) { if (FinalResult != null) { if (FinalResult.ResultID == 0) { MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; result = MaterialMessageBox.Show("Are you sure you want to exit? The Result of Survey will not be saved.", "Easy Survey - Conduct Survey", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning); if (result != MaterialMessageBox.MessageBoxResult.Yes) { e.Cancel = true; return; } } } Program.frm_MainForm.Location = base.Location; Program.frm_MainForm.Size = base.Size; Program.frm_MainForm.Show(); }
// Remove password protection private void removeToolStripMenuItem_Click(object sender, EventArgs e) { int SelectedUsersCount = listView_Users.SelectedItems.Count; if (SelectedUsersCount == 0) { return; } MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; result = MaterialMessageBox.Show("Are you sure you want to remove password protection for all selected users?", "Easy Survey - Manage Users", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Information); using (UserController userController = new UserController()) if (result == MaterialMessageBox.MessageBoxResult.Yes) { foreach (ListViewItem item in listView_Users.SelectedItems) { long UserID = Convert.ToInt64(item.Tag); userController.UpdatePassword(UserID, null); item.ForeColor = Color.Red; } } }
private void toolStripMenuItem_DeleteAttitudeDefinitions_Click(object sender, EventArgs e) { int SelectedAttributesCount = listView_EditAttitudeDefinition.SelectedItems.Count; MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; if (SelectedAttributesCount > 0) { result = MaterialMessageBox.Show("Sunteti sigur ca vrei sa stergeti intrebarile selectate din definitia atitudinii?", "Easy Survey - Delete Attitude Definition", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning); } if (result == MaterialMessageBox.MessageBoxResult.Yes) { using (AttitudeDefinitionController attitudeDefinitionController = new AttitudeDefinitionController()) foreach (ListViewItem selectedItem in listView_EditAttitudeDefinition.SelectedItems) { long QuestionID = Convert.ToInt64(selectedItem.Tag); long AttitudeID = Convert.ToInt64(txt_EditAttitudeDetailsName.Tag); attitudeDefinitionController.Delete(QuestionID, AttitudeID); listView_EditAttitudeDefinition.Items.Remove(selectedItem); } } }
private void deleteAttitudeToolStripMenuItem_Click(object sender, EventArgs e) { int SelectedAttitudesCount = listView_AllAttitudes.SelectedItems.Count; MaterialMessageBox.MessageBoxResult result = MaterialMessageBox.MessageBoxResult.None; if (SelectedAttitudesCount > 0) { result = MaterialMessageBox.Show("Sunteti sigur ca vrei sa stergeti atitudinile selectate?", "Easy Survey - Delete Attitudes", MaterialMessageBox.MessageBoxButtons.YesNo, MaterialMessageBox.MessageBoxIcon.Warning); } if (result == MaterialMessageBox.MessageBoxResult.Yes) { using (AttitudeController attitudeController = new AttitudeController()) foreach (ListViewItem selectedItem in listView_AllAttitudes.SelectedItems) { long AttitudeID = Convert.ToInt64(selectedItem.Tag); Attitudes.Remove(Attitudes.Find(i => i.AttitudeID == AttitudeID)); attitudeController.Delete(AttitudeID); listView_AllAttitudes.Items.Remove(selectedItem); } } }
private void pic_Import_Click(object sender, EventArgs e) { openFileDialog_Import.InitialDirectory = SpecialDirectories.MyComputer; DialogResult Result = openFileDialog_Import.ShowDialog(); using (Database DB = new Database()) if (Result == DialogResult.OK) { try { string ImportDatabasePath = openFileDialog_Import.FileName; ImportDatabasePath = Path.GetFullPath(ImportDatabasePath); long ImportedResults = DB.Import(ImportDatabasePath); MaterialMessageBox.Show("Database has been imported " + ImportedResults + " results successfully!", "Easy Survey - Database Import", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Information); // Program.frm_MainForm.Close(); // base.Close(); } catch (Exception ex) { MaterialMessageBox.Show(ex.Message, "Easy Survey - Import Database", MaterialMessageBox.MessageBoxButtons.OK, MaterialMessageBox.MessageBoxIcon.Error); } } }
// 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"]; } } }
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); } } } } } }