コード例 #1
0
ファイル: MainForm.cs プロジェクト: CRiSTi107/EasySurvey
        private void toolStripMenuItem_AddAttitudeDefinitions_Click(object sender, EventArgs e)
        {
            MaterialMessageComboBox.MessageBoxResult result = MaterialMessageComboBox.MessageBoxResult.None;

            long AttitudeID = Convert.ToInt64(txt_EditAttitudeDetailsName.Tag);

            if (AttitudeID != -1)
            {
                result = MaterialMessageComboBox.Show("Select survey and question.", "Easy Survey - Add New Attitude Definition", MaterialMessageComboBox.MessageBoxButtons.OKCancel, AttitudeID);
            }

            if (result == MaterialMessageComboBox.MessageBoxResult.OK)
            {
                //long NewSurveyID = MaterialMessageComboBox.Answer1;
                long NewQuestionID = MaterialMessageComboBox.Answer2;

                using (QuestionController questionController = new QuestionController())
                    using (AttitudeDefinitionController attitudeDefinitionController = new AttitudeDefinitionController())
                    {
                        string QuestionName = questionController.Get(NewQuestionID).Question1;
                        if (attitudeDefinitionController.AddRelation(AttitudeID, NewQuestionID))
                        {
                            listView_EditAttitudeDefinition.Items.Add(new ListViewItem()
                            {
                                Text = QuestionName, Tag = NewQuestionID
                            });
                        }
                    }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: CRiSTi107/EasySurvey
        private void toolStripMenuItem_EditAttitudeDefinitions_Click(object sender, EventArgs e)
        {
            int SelectedAttitudeDefinitionCount = listView_EditAttitudeDefinition.SelectedItems.Count;

            MaterialMessageComboBox.MessageBoxResult result = MaterialMessageComboBox.MessageBoxResult.None;

            if (SelectedAttitudeDefinitionCount == 0)
            {
                return;
            }

            int CurrentAttitudeDefinition = 0;

            using (SurveyController surveyController = new SurveyController())
                using (QuestionController questionController = new QuestionController())
                {
                    long AttitudeID = Convert.ToInt64(txt_EditAttitudeDetailsName.Tag);
                    long SurveyID   = -1;
                    long QuestionID = -1;

                    foreach (ListViewItem SelectedAttitudeDefinition in listView_EditAttitudeDefinition.SelectedItems)
                    {
                        QuestionID = Convert.ToInt64(SelectedAttitudeDefinition.Tag);
                        SurveyID   = surveyController.GetByQuestion(QuestionID).SurveyID;

                        result = MaterialMessageComboBox.MessageBoxResult.None;
                        result = MaterialMessageComboBox.Show("Editeaza definitia atitudinii:", "Easy Survey - Edit Attitude Definition (" + ++CurrentAttitudeDefinition + "/" + SelectedAttitudeDefinitionCount + ")", MaterialMessageComboBox.MessageBoxButtons.OKCancel, AttitudeID, SurveyID, QuestionID);

                        if (result == MaterialMessageComboBox.MessageBoxResult.OK)
                        {
                            AttitudeDefinitionController attitudeDefinitionController = new AttitudeDefinitionController();

                            long NewSurveyID   = MaterialMessageComboBox.Answer1;
                            long NewQuestionID = MaterialMessageComboBox.Answer2;

                            attitudeDefinitionController.Update(AttitudeID, QuestionID, NewQuestionID);

                            string NewQuestionName = questionController.Get(NewQuestionID).Question1;

                            int AttitudeDefinitionIndex = listView_EditAttitudeDefinition.Items.IndexOf(SelectedAttitudeDefinition);
                            listView_EditAttitudeDefinition.Items[AttitudeDefinitionIndex].Text = NewQuestionName;
                            listView_EditAttitudeDefinition.Items[AttitudeDefinitionIndex].Tag  = NewQuestionID;
                        }
                        else if (result == MaterialMessageComboBox.MessageBoxResult.None)
                        {
                            break;
                        }
                    }
                }
        }
コード例 #3
0
ファイル: MsgComboBox.cs プロジェクト: CRiSTi107/EasySurvey
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (IsValidatedAnswer1 && IsValidatedAnswer2)
            {
                AttitudeDefinitionController attitudeDefinitionController = new AttitudeDefinitionController();

                long SelectedSurveyID   = MaterialMessageComboBox.Answer1;
                long SelectedQuestionID = MaterialMessageComboBox.Answer2;

                if (AddMode)
                {
                    if (attitudeDefinitionController.Exists(AttitudeID, SelectedQuestionID))
                    {
                        SetStatus("This Question already exists in this Attitude Definition.");
                    }
                    else
                    {
                        MaterialMessageComboBox._Result = MaterialMessageComboBox.MessageBoxResult.OK;
                        base.Close();
                    }
                }
                else if (EditMode)
                {
                    if (SelectedSurveyID != SurveyID || SelectedQuestionID != QuestionID) // Modified
                    {
                        if (attitudeDefinitionController.Exists(AttitudeID, SelectedQuestionID))
                        {
                            SetStatus("This Question already exists in this Attitude Definition.");
                            return;
                        }
                    }

                    MaterialMessageComboBox._Result = MaterialMessageComboBox.MessageBoxResult.OK;
                    base.Close();
                }
            }
            else
            {
                SetStatus("Please select the Survey and Question properly.");
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: CRiSTi107/EasySurvey
        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);
                    }
            }
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: CRiSTi107/EasySurvey
        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);
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: CRiSTi107/EasySurvey
        private void cmb_SelectUserReport_SelectedIndexChanged(object sender, EventArgs e)
        {
            string Username      = cmb_SelectUserReport.Text;
            int    SelectedIndex = cmb_SelectUserReport.SelectedIndex;

            listView_UserReports.Items.Clear();
            listView_AttitudeReports.Items.Clear();

            if (Username == "*" || SelectedIndex == -1)
            {
                return;
            }

            UserModelDataTransferObject SelectedUser;

            using (UserController userController = new UserController())
                SelectedUser = userController.GetUserByName(Username);
            long UserID = SelectedUser.UserID;

            List <Result> UserResults;

            using (ResultController resultController = new ResultController())
                UserResults = resultController.GetForUser(UserID);

            UserResults = UserResults.OrderBy(r => r.SurveyID).ThenByDescending(r => r.Date).ToList();

            SurveyController surveyController = new SurveyController();

            foreach (Result result in UserResults)
            {
                string SurveyName = surveyController.Get(result.SurveyID).SurveyName;
                listView_UserReports.Items.Add(new ListViewItem(listView_UserReports.Groups["default"])
                {
                    Text = result.ToString(), Tag = result.ResultID
                });
            }

            //Get list of lastest User Reports
            List <long>   UsedSurveyID    = new List <long>();
            List <Result> LastUserReports = new List <Result>();

            foreach (Result result in UserResults)
            {
                if (!UsedSurveyID.Contains(result.SurveyID))
                {
                    UsedSurveyID.Add(result.SurveyID);
                    LastUserReports.Add(result);
                }
            }
            UsedSurveyID = null;

            //Calculate Attitude Score
            using (AttitudeController attitudeController = new AttitudeController())
                using (AttitudeDefinitionController attitudeDefinitionController = new AttitudeDefinitionController())
                    using (ResultDefinitionController resultDefinitionController = new ResultDefinitionController())
                    {
                        List <Attitude> attitudes = attitudeController.GetAttitudes();

                        listView_AttitudeReports.Items.Clear();

                        foreach (Attitude attitude in attitudes)
                        {
                            long AttitudeSum = 0;
                            bool Found       = false;

                            List <AttitudeDefinition> attitudeDefinitions = attitudeDefinitionController.GetRelation(attitude.AttitudeID);
                            foreach (AttitudeDefinition attitudeDefinition in attitudeDefinitions)
                            {
                                long QuestionID = attitudeDefinition.QuestionID;


                                foreach (Result result in LastUserReports)
                                {
                                    List <ResultDefinition> resultDefinitions = resultDefinitionController.Get(result.ResultID);
                                    Found = false;
                                    foreach (ResultDefinition resultDefinition in resultDefinitions)
                                    {
                                        if (resultDefinition.QuestionID == QuestionID)
                                        {
                                            AttitudeSum += resultDefinition.ResultAnswer;
                                            Found        = true;
                                            break;
                                        }
                                    }
                                    if (Found)
                                    {
                                        break;
                                    }
                                }

                                string SurveyName = surveyController.GetByQuestion(QuestionID).SurveyName;

                                if (!Found)
                                {
                                    listView_AttitudeReports.Items.Add(
                                        new ListViewItem(listView_AttitudeReports.Groups["default"])
                                    {
                                        ForeColor = Color.Red,
                                        Text      = attitude.AttitudeName + " - requires '" + SurveyName + "'",
                                        Tag       = attitude.AttitudeID
                                    });
                                    break;
                                }
                            }

                            if (Found)
                            {
                                listView_AttitudeReports.Items.Add(
                                    new ListViewItem(listView_AttitudeReports.Groups["default"])
                                {
                                    Text = attitude.AttitudeName + " - " + AttitudeSum,
                                    Tag  = attitude.AttitudeID
                                });
                            }
                        }
                    }
        }