Esempio n. 1
0
        private void MsgComboBox_Load(object sender, EventArgs e)
        {
            SurveyController surveyController = new SurveyController();

            Surveys = surveyController.GetAll();

            QuestionController questionController = new QuestionController();

            Questions = questionController.GetAll();

            foreach (Survey survey in Surveys)
            {
                cmb_Answer1.Items.Add(survey.SurveyName);
            }

            if (EditMode)
            {
                string SurveyName = surveyController.Get(SurveyID).SurveyName;
                cmb_Answer1.Text = SurveyName;

                string QuestionName = questionController.Get(QuestionID).Question1;
                cmb_Answer2.Text = QuestionName;
            }
        }
Esempio n. 2
0
        public long Import(string DatabaseImportPath)
        {
            // Copy data from Export Database to Current Database.
            using (Database DBRestore = new Database(DatabaseImportPath))
            {
                // Checking if there are same Users.
                List <UserModelDataTransferObject> RestoreUsers, CurrentUsers;
                using (UserController UserController = new UserController(DatabaseImportPath))
                    RestoreUsers = UserController.GetUsers().OrderBy(u => u.UserID).ToList();
                using (UserController UserController = new UserController())
                    CurrentUsers = UserController.GetUsers().OrderBy(u => u.UserID).ToList();
                if (CurrentUsers.Count != RestoreUsers.Count)
                {
                    throw new Exception("Selected database does not have the same Users.");
                }
                for (int UserIndex = 0; UserIndex <= RestoreUsers.Count - 1; ++UserIndex)
                {
                    if (CurrentUsers[UserIndex] != RestoreUsers[UserIndex])
                    {
                        throw new Exception("Selected database does not have the same Users.");
                    }
                }

                // Check if there are the same Questions
                List <Question> RestoreQuestions, CurrentQuestions;
                using (QuestionController QuestionControllerRestore = new QuestionController(DatabaseImportPath))
                    RestoreQuestions = QuestionControllerRestore.GetAll();
                using (QuestionController QuestionControllerCurrent = new QuestionController())
                    CurrentQuestions = QuestionControllerCurrent.GetAll();
                if (CurrentQuestions.Count != RestoreQuestions.Count)
                {
                    throw new Exception("Selected database does not have the same Questions.");
                }
                foreach (Question CurrentQuestion in CurrentQuestions)
                {
                    if (!RestoreQuestions.Any(q => q.QuestionID == CurrentQuestion.QuestionID &&
                                              q.Question1 == CurrentQuestion.Question1))
                    {
                        throw new Exception("Selected database does not have the same Questions.");
                    }
                }

                // Check if there are the same Surveys
                List <Survey> RestoreSurveys, CurrentSurveys;
                using (SurveyController SurveyControllerRestore = new SurveyController(DatabaseImportPath))
                    RestoreSurveys = SurveyControllerRestore.GetAll();
                using (SurveyController SurveyControllerCurrent = new SurveyController())
                    CurrentSurveys = SurveyControllerCurrent.GetAll();
                if (CurrentSurveys.Count != RestoreSurveys.Count)
                {
                    throw new Exception("Selected database does not have the same Surveys.");
                }
                foreach (Survey CurrentSurvey in CurrentSurveys)
                {
                    if (!RestoreSurveys.Any(s => s.SurveyID == CurrentSurvey.SurveyID &&
                                            s.SurveyName == CurrentSurvey.SurveyName))
                    {
                        throw new Exception("Selected database does not have the same Surveys.");
                    }
                }

                // Check if there are the same Survey Definitions
                List <SurveyDefinition> RestoreSurveyDefinitions, CurrentSurveyDefinitions;
                using (SurveyDefinitionController AttitudeDefinitionControllerRestore = new SurveyDefinitionController(DatabaseImportPath))
                    RestoreSurveyDefinitions = AttitudeDefinitionControllerRestore.Get();
                using (SurveyDefinitionController AttitudeDefinitionControllerCurrent = new SurveyDefinitionController())
                    CurrentSurveyDefinitions = AttitudeDefinitionControllerCurrent.Get();
                if (CurrentSurveyDefinitions.Count != RestoreSurveyDefinitions.Count)
                {
                    throw new Exception("Selected database does not have the same Survey Definitions.");
                }
                foreach (SurveyDefinition CurrentSurveyDefinition in CurrentSurveyDefinitions)
                {
                    if (!RestoreSurveyDefinitions.Any(sd => sd.SurveyDefinitionID == CurrentSurveyDefinition.SurveyDefinitionID &&
                                                      sd.QuestionID == CurrentSurveyDefinition.QuestionID &&
                                                      sd.SurveyID == CurrentSurveyDefinition.SurveyID))
                    {
                        throw new Exception("Selected database does not have the same Survey Definitions.");
                    }
                }

                // Check if there are the same Attitudes
                List <Attitude> RestoreAttitudes, CurrentAttitudes;
                using (AttitudeController AttitudeControllerRestore = new AttitudeController(DatabaseImportPath))
                    RestoreAttitudes = AttitudeControllerRestore.GetAttitudes();
                using (AttitudeController AttitudeControllerCurrent = new AttitudeController())
                    CurrentAttitudes = AttitudeControllerCurrent.GetAttitudes();
                if (CurrentAttitudes.Count != RestoreAttitudes.Count)
                {
                    throw new Exception("Selected database does not have the same Attitudes.");
                }
                foreach (Attitude CurrentAttitude in CurrentAttitudes)
                {
                    if (!RestoreAttitudes.Any(a => a.AttitudeID == CurrentAttitude.AttitudeID &&
                                              a.AttitudeName == CurrentAttitude.AttitudeName))
                    {
                        throw new Exception("Selected database does not have the same Attitudes.");
                    }
                }

                // Check if there are the same Attitudes Definitions
                List <AttitudeDefinition> RestoreAttitudeDefinitions, CurrentAttitudeDefinitions;
                using (AttitudeDefinitionController AttitudeDefinitionControllerRestore = new AttitudeDefinitionController(DatabaseImportPath))
                    RestoreAttitudeDefinitions = AttitudeDefinitionControllerRestore.Get();
                using (AttitudeDefinitionController AttitudeDefinitionControllerCurrent = new AttitudeDefinitionController())
                    CurrentAttitudeDefinitions = AttitudeDefinitionControllerCurrent.Get();
                if (CurrentAttitudeDefinitions.Count != RestoreAttitudeDefinitions.Count)
                {
                    throw new Exception("Selected database does not have the same Attitude Definitions.");
                }
                foreach (AttitudeDefinition CurrentAttitudeDefinition in CurrentAttitudeDefinitions)
                {
                    if (!RestoreAttitudeDefinitions.Any(ad => ad.AttitudeDefinitionID == CurrentAttitudeDefinition.AttitudeDefinitionID &&
                                                        ad.AttitudeID == CurrentAttitudeDefinition.AttitudeID &&
                                                        ad.QuestionID == CurrentAttitudeDefinition.QuestionID))
                    {
                        throw new Exception("Selected database does not have the same Attitude Definitions.");
                    }
                }


                // Actually import new data from Result Table
                long ImportedResultCount = 0;
                using (ResultController resultControllerRestore = new ResultController(DatabaseImportPath))
                    using (ResultController resultControllerCurrent = new ResultController())
                    {
                        List <Result> RestoreResults = resultControllerRestore.Get();
                        List <Result> CurrentResults = resultControllerCurrent.Get();

                        foreach (Result RestoreResult in RestoreResults)
                        {
                            if (!CurrentResults.Any(r => r.SurveyID == RestoreResult.SurveyID &&
                                                    r.Date == RestoreResult.Date &&
                                                    r.UserID == RestoreResult.UserID))
                            {
                                // Add to result table
                                long OldResultID = RestoreResult.ResultID;
                                resultControllerCurrent.Add(RestoreResult); // ID may change during adding.
                                long NewResultID = RestoreResult.ResultID;
                                ++ImportedResultCount;

                                // Get all Result definitions
                                using (ResultDefinitionController resultDefinitionControllerRestore = new ResultDefinitionController(DatabaseImportPath))
                                    using (ResultDefinitionController resultDefinitionControllerCurrent = new ResultDefinitionController())
                                    {
                                        List <ResultDefinition> RestoreResultDefinitions = resultDefinitionControllerRestore.Get(OldResultID);
                                        RestoreResultDefinitions.ForEach(rd => rd.ResultID = NewResultID); // Update with new ResultID
                                        resultDefinitionControllerCurrent.Add(RestoreResultDefinitions);
                                    }
                            }
                        }
                    }
                return(ImportedResultCount);
            }
        }
Esempio n. 3
0
 private List <Survey> GetSurveys()
 {
     using (SurveyController surveyController = new SurveyController())
         return(surveyController.GetAll());
 }