Пример #1
0
        /// <summary>
        /// Check if a survey has any answers to it
        /// </summary>
        private bool HasAnswers(surveys survey)
        {
            var  questions        = b.GetQuestionsBySurveyCode(survey.Survey_code);
            bool hasTextAnswers   = true;
            bool hasOptionAnswers = true;

            foreach (var question in questions)
            {
                if (b.GetInputTypeName(question) == "text")
                {
                    if (b.GetTextAnswers(question).Count == 0)
                    {
                        hasTextAnswers = false;
                    }
                }
                else
                {
                    List <option_choices> options = b.GetOptionsChoices(question);
                    if (options.ElementAt(0).answers.Count == 0 && options.ElementAt(1).answers.Count == 0 && options.ElementAt(2).answers.Count == 0)
                    {
                        hasOptionAnswers = false;
                    }
                }
            }
            if (hasTextAnswers && hasOptionAnswers)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public void TestInit()
 {
     surveydb           = Database.GetConnection();
     surveyDal          = new SurveyDAL();
     userDAL            = new UserDAL();
     questionDAL        = new QuestionDAL();
     user               = new users();
     user.User_name     = userName;
     user.User_password = password;
     HelperDAL.AddUser(user);
     survey      = new surveys();
     survey.Name = surveyName;
     //survey.users = user;
     survey.User_name   = userName;
     SurveyCode         = HelperDAL.GenerateRandomSurveyCode();
     survey.Survey_code = SurveyCode;
     HelperDAL.AddSurvey(survey);
     question = new questions();
     question.Question_name = questionName;
     question.Surveys_id    = survey.Id;
     question.Input_type_id = 2;
     this.questionDAL.AddQuestion(question);
     this.optionChoicesDAL                 = new OptionChoicesDAL();
     this.optionChoice                     = new option_choices();
     this.optionChoice.Question_id         = question.Id;
     this.optionChoice.Option_choices_name = OptionChoiceName;
 }
Пример #3
0
 /// <summary>
 /// Create an instance of a survey
 /// </summary>
 private void CreateSurvey()
 {
     survey             = new surveys();
     survey.Name        = textBoxSurveyTitle.Text;
     survey.Survey_code = b.GenerateRandomSurveyCode();
     survey.User_name   = SignUpForm.LoggedUser.User_name;
 }
Пример #4
0
        public void DeleteSurvey(string surveyCode)
        {
            surveys          survey    = surveyDAL.GetSurveyBySurveyCode(surveyCode);
            List <questions> questions = questionDAL.GetQuestionsBySurveyId(survey.Id).ToList();

            foreach (var question in questions)
            {
                if (inputTypeDAL.GetInputTypeName(question) == "text")
                {
                    List <text_answers> texts = textAswersDAL.GetTextAnswers(question);
                    foreach (var text in texts)
                    {
                        textAswersDAL.DeleteTextAnswer(text);
                    }
                    questionDAL.DeleteQuestion(question);
                }
                else
                {
                    List <option_choices> options = optionChoiceDAL.GetOptionsChoices(question);
                    foreach (var option in options)
                    {
                        List <answers> answers = answerDAL.GetAnswers(option.Id);
                        foreach (var answer in answers)
                        {
                            answerDAL.DeleteAnswer(answer);
                        }
                        optionChoiceDAL.DeleteOptionChoice(option);
                    }
                    questionDAL.DeleteQuestion(question);
                }
            }
            surveyDAL.DeleteSurvey(survey);
        }
Пример #5
0
 public void TestInit()
 {
     surveydb           = Database.GetConnection();
     surveyDal          = new SurveyDAL();
     userDAL            = new UserDAL();
     questionDAL        = new QuestionDAL();
     user               = new users();
     user.User_name     = userName;
     user.User_password = password;
     HelperDAL.AddUser(user);
     survey      = new surveys();
     survey.Name = surveyName;
     //survey.users = user;
     survey.User_name   = userName;
     SurveyCode         = HelperDAL.GenerateRandomSurveyCode();
     survey.Survey_code = SurveyCode;
     HelperDAL.AddSurvey(survey);
     question = new questions();
     question.Question_name = questionName;
     question.Surveys_id    = survey.Id;
     question.Input_type_id = 1;
     this.questionDAL.AddQuestion(question);
     this.textAnswerDAL          = new TextAnswerDAL();
     this.textAnswer             = new text_answers();
     this.textAnswer.User_name   = userName;
     this.textAnswer.Question_id = question.Id;
     this.textAnswer.Answer      = TextAnswerText;
 }
Пример #6
0
 public static void AddTestSurveysToDataBase(surveys survey)
 {
     for (int i = 1; i <= 3; i++)
     {
         survey.Name += i;
         surveyDal.AddSurvey(survey);
     }
 }
Пример #7
0
      public void DeletedSuccessfullySurvey()
      {
          this.surveyDal.AddSurvey(survey);
          this.surveyDal.DeleteSurvey(survey);
          surveys testSurvey = this.surveyDal.GetSurveyBySurveyCode(SurveyCode);

          this.userDAL.DeleteUserByName(userName);
          Assert.AreEqual(testSurvey, null, "Survey isn't deleted.");
      }
Пример #8
0
      public void ShouldReturnSirveyByCode()
      {
          this.surveyDal.AddSurvey(survey);
          surveys surveyFromDataBase = this.surveyDal.GetSurveyBySurveyCode(SurveyCode);

          this.surveyDal.DeleteSurvey(survey);
          HelperDAL.DeleteUser(userName);
          Assert.IsNotNull(surveyFromDataBase);
          Assert.That(survey, Is.EqualTo(surveyFromDataBase));
      }
Пример #9
0
      public void SurveyNameShouldBeDifferent()
      {
          this.surveyDal.AddSurvey(survey);
          string newSurveyName = "NewName";

          this.surveyDal.UpdateSurvey(survey, newSurveyName);
          surveys survey2 = this.surveyDal.GetSurveyBySurveyCode(SurveyCode);

          this.surveyDal.DeleteSurvey(survey);
          HelperDAL.DeleteUser(userName);
          Assert.AreSame(newSurveyName, survey2.Name);
      }
Пример #10
0
        private void button2_Click(object sender, EventArgs e)
        {
            // users user = new users();
            // user.User_name = textBox1.Text;
            // user.User_password = textBox2.Text;
            // b.AddUser(user);
            surveys survey = new surveys();

            survey.Name        = "text8";
            survey.User_name   = textBox1.Text;
            survey.Survey_code = "kji";
            b.AddSurvey(survey);
        }
Пример #11
0
 public void TestInit()
 {
     surveydb           = Database.GetConnection();
     surveyDal          = new SurveyDAL();
     userDAL            = new UserDAL();
     user               = new users();
     user.User_name     = userName;
     user.User_password = password;
     survey             = new surveys();
     survey.Name        = surveyName;
     survey.users       = user;
     SurveyCode         = HelperDAL.GenerateRandomSurveyCode();
     survey.Survey_code = SurveyCode;
 }
Пример #12
0
 /// <summary>
 /// Generate a survey with a given survey code
 /// </summary>
 private void buttonConfirmSurveyCode_Click(object sender, EventArgs e)
 {
     //If a survey with the given survey code doesn't exist, a warning will be shown
     if (b.GetSurveyBySurveyCode(textBoxSurveyCode.Text) == null)
     {
         MessageBox.Show("A survey with that code doesn't exist.");
     }
     //Else generate all the questions from the given survey
     else
     {
         surveys currSurvey = b.GetSurveyBySurveyCode(textBoxSurveyCode.Text);
         questionsSending = b.GetQuestionsBySurveyCode(textBoxSurveyCode.Text);
         panelFillSurvey.Controls.Clear();
         GenerateQuestions(questionsSending, currSurvey);
     }
 }
Пример #13
0
        /// <summary>
        /// Clear the create survey panel and reset its original components to their original locations
        /// </summary>
        public void ClearPanelCreateSurvey()
        {
            panelCreateSurvey.Visible = false;
            textBoxSurveyTitle.Text   = "";
            panelCreateSurvey.Controls.Clear();
            panelCreateSurvey.Controls.Add(textBoxSurveyTitle);
            panelCreateSurvey.Controls.Add(labelSurveyTitle);
            panelCreateSurvey.Controls.Add(buttonText);
            panelCreateSurvey.Controls.Add(buttonOptionChoice);
            panelCreateSurvey.Controls.Add(buttonCreateSurvey);

            labelSurveyTitle.Location   = new Point(70, 8);
            textBoxSurveyTitle.Location = new Point(70, 34);
            buttonText.Location         = new Point(170, 68);
            buttonOptionChoice.Location = new Point(407, 68);
            buttonCreateSurvey.Location = new Point(70, 139);

            question_text_counter   = 0;
            question_option_counter = 0;

            survey = null;
        }
Пример #14
0
 public void DeleteSurvey(surveys survey)
 {
     surveyDBcontext.surveys.Attach(survey);
     surveyDBcontext.surveys.Remove(survey);
     surveyDBcontext.SaveChanges();
 }
Пример #15
0
 public void AddSurvey(surveys survey)
 {
     surveyDBcontext.surveys.Add(survey);
     surveyDBcontext.SaveChanges();
 }
Пример #16
0
 public static void DeleteSurvey(surveys survey)
 {
     surveyDal.DeleteSurvey(survey);
 }
Пример #17
0
 //SurveyDAL
 public void AddSurvey(surveys survey)
 {
     surveyDAL.AddSurvey(survey);
 }
Пример #18
0
        public void UpdateSurveyName(string surveyCode, string newSurveyName)
        {
            surveys survey = surveyDAL.GetSurveyBySurveyCode(surveyCode);

            surveyDAL.UpdateSurvey(survey, newSurveyName);
        }
Пример #19
0
 public static void AddSurvey(surveys survey)
 {
     surveyDal.AddSurvey(survey);
 }
Пример #20
0
        /// <summary>
        /// Creates the survey with all its questions and gives you the opportunity to edit them
        /// </summary>
        private void EditSurvey(surveys survey)
        {
            panelEditSurvey.AutoScrollMinSize = new Size(0, 300);
            ShowPanel(panelEditSurvey);
            List <questions> oldQuestions = b.GetQuestionsBySurveyCode(survey.Survey_code);

            //Cancel the edit and go back to the my surveys panel
            Button buttonGoBack = CreateButton(new Point(680, 20), new Size(32, 32), "");

            buttonGoBack.BackgroundImage = Image.FromFile(@"icons\return_32px.png");
            buttonGoBack.Click          += (s, ee) =>
            {
                ShowPanel(panelMySurveys);
                buttonMySurveys.PerformClick();
            };
            panelEditSurvey.Controls.Add(buttonGoBack);

            Label title = CreateLabel(new Point(5, 30), "Title");

            panelEditSurvey.Controls.Add(title);

            TextBox titleTextBox = CreateTextBox("titleTextBox", new Point(60, 30), new Size(600, 30), 50);

            titleTextBox.Multiline = true;
            titleTextBox.Text      = survey.Name;
            panelEditSurvey.Controls.Add(titleTextBox);

            int YCounter = 0;
            int i;

            for (i = 0; i < oldQuestions.Count; i++)
            {
                Label questionNumber = CreateLabel(new Point(5, 70 + YCounter * 120 + i * 50), (i + 1) + ".");
                panelEditSurvey.Controls.Add(questionNumber);

                TextBox questionText = CreateTextBox(i + 1 + "textBox", new Point(40, 70 + YCounter * 120 + i * 50), new Size(600, 30), 80);
                questionText.Multiline = true;
                questionText.Text      = oldQuestions.ElementAt(i).Question_name;
                panelEditSurvey.Controls.Add(questionText);

                if (b.GetInputTypeName(oldQuestions.ElementAt(i)) == "option")
                {
                    for (int j = 1; j < 4; j++)
                    {
                        TextBox option = CreateTextBox(j + "option" + i, new Point(60, 70 + YCounter * 120 + j * 40 + i * 50), new Size(600, 30), 80);
                        option.Multiline = true;
                        var choices = b.GetOptionsChoices(oldQuestions.ElementAt(i));
                        var text    = choices.ElementAt(j - 1);
                        option.Text = text.Option_choices_name;
                        panelEditSurvey.Controls.Add(option);
                    }
                    YCounter++;
                }
            }
            //Confirms the edit and update the questions in the database
            //Also it deletes all the current answers to the questions in the survey
            Button buttonConfirmEdit = CreateButton(new Point(110, 70 + YCounter * 120 + i * 50), new Size(200, 30), "Confirm Edit");

            buttonConfirmEdit.BackColor = System.Drawing.Color.FromArgb(238, 26, 74);
            buttonConfirmEdit.Click    += (s, ee) =>
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to edit this survey? Note that it will delete all it's current answers.", "Editting survey", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    for (int j = 0; j < oldQuestions.Count; j++)
                    {
                        if (b.GetInputTypeName(oldQuestions.ElementAt(j)) == "option")
                        {
                            for (int z = 1; z < 4; z++)
                            {
                                TextBox newOption = panelEditSurvey.Controls.Find(z + "option" + j, false).First() as TextBox;
                                b.UpdateOptionChoiceName(oldQuestions.ElementAt(j).option_choices.ElementAt(z - 1), newOption.Text);
                            }
                        }
                        TextBox newName = panelEditSurvey.Controls.Find(j + 1 + "textBox", false).First() as TextBox;
                        b.UpdateQuestionName(oldQuestions.ElementAt(j), newName.Text);
                        if (b.GetInputTypeName(oldQuestions.ElementAt(j)) == "text")
                        {
                            foreach (var answer in b.GetTextAnswers(oldQuestions.ElementAt(j)))
                            {
                                b.DeleteTextAnswer(answer);
                            }
                        }
                        else
                        {
                            foreach (var option in b.GetOptionsChoices(oldQuestions.ElementAt(j)))
                            {
                                foreach (var answer in b.GetAnswers(option.Id))
                                {
                                    b.DeleteAnswer(answer);
                                }
                            }
                        }
                    }
                    TextBox newTitle = panelEditSurvey.Controls.Find("titleTextBox", false).First() as TextBox;
                    b.UpdateSurveyName(survey.Survey_code, newTitle.Text);
                    MessageBox.Show("Survey edited succesfully!", "Success!");
                    buttonHome.PerformClick();
                }
            };
            panelEditSurvey.Controls.Add(buttonConfirmEdit);
        }
Пример #21
0
        /// <summary>
        /// Create a list of all users' surveys and shows their survey code, title and username
        /// It also gives the option fill them
        /// </summary>
        private void buttonCheckEverySurvey_Click(object sender, EventArgs e)
        {
            panelEverySurvey.AutoScrollMinSize = new Size(0, 300);
            ShowPanel(panelEverySurvey);
            timerFillSurveyPanel.Start();

            var allSurveys = b.GetAllSurveys();

            //If there are no surveys created yet, only a label will be shown saying that there are no surveys created
            if (allSurveys.Count == 0)
            {
                Label label = CreateLabel(new Point(150, 50), "There is currently no surveys created!");
                panelEverySurvey.Controls.Add(label);
                return;
            }
            for (int i = 0; i < allSurveys.Count; i++)
            {
                Label label = CreateLabel(new Point(20, 50 + i * 50), i + 1 + ".   " + allSurveys.ElementAt(i).Name);
                if (label.Text.Length > 19)
                {
                    label.Text = label.Text.Substring(0, 18) + "...";
                }
                panelEverySurvey.Controls.Add(label);

                Label userName = CreateLabel(new Point(200, 50 + i * 50), allSurveys.ElementAt(i).users.User_name);
                if (userName.Text.Length > 16)
                {
                    userName.Text = userName.Text.Substring(0, 15) + "...";
                }
                panelEverySurvey.Controls.Add(userName);

                //Button that will open the fill survey panel and generate the questions for the selected survey
                Button buttonFillSurvey = CreateButton(new Point(350, 50 + i * 50), new Size(150, 30), "Fill Survey");
                buttonFillSurvey.Name      = allSurveys.ElementAt(i).Survey_code;
                buttonFillSurvey.BackColor = System.Drawing.Color.FromArgb(238, 26, 74);
                buttonFillSurvey.Click    += (s, ee) =>
                {
                    surveys currSurvey = b.GetSurveyBySurveyCode(buttonFillSurvey.Name);
                    questionsSending = b.GetQuestionsBySurveyCode(buttonFillSurvey.Name);

                    panelFillSurvey.Controls.Clear();
                    panelFillSurvey.AutoScrollMinSize = new Size(0, 300);
                    ShowPanel(panelFillSurvey);
                    GenerateQuestions(questionsSending, currSurvey);
                };
                panelEverySurvey.Controls.Add(buttonFillSurvey);

                TextBox surveyCodeTextBox = CreateTextBox("", new Point(540, 55 + i * 50), new Size(120, 20), 300);
                surveyCodeTextBox.Text        = allSurveys.ElementAt(i).Survey_code;
                surveyCodeTextBox.ReadOnly    = true;
                surveyCodeTextBox.BorderStyle = 0;
                surveyCodeTextBox.BackColor   = this.BackColor;
                panelEverySurvey.Controls.Add(surveyCodeTextBox);
            }

            Label surveyCode = CreateLabel(new Point(540, 10), "Survey Code");

            surveyCode.Font = new Font("Century", 12, FontStyle.Bold);
            panelEverySurvey.Controls.Add(surveyCode);

            Label user = CreateLabel(new Point(200, 10), "User");

            user.Font = new Font("Century", 12, FontStyle.Bold);
            panelEverySurvey.Controls.Add(user);
        }
Пример #22
0
 public void UpdateSurvey(surveys survey, string newSurveyName)
 {
     survey.Name = newSurveyName;
     surveyDBcontext.SaveChanges();
 }
Пример #23
0
        /// <summary>
        /// Opens the check answers panel and shows all the answers for each question
        /// </summary>
        private void checkAnswers(surveys survey)
        {
            panelCheckAnswers.AutoScrollMinSize = new Size(0, 300);
            ShowPanel(panelCheckAnswers);
            List <questions> questions = b.GetQuestionsBySurveyCode(survey.Survey_code);

            //Button to go back to the my surveys panel
            Button buttonGoBack = CreateButton(new Point(600, 40), new Size(32, 32), "");

            buttonGoBack.BackgroundImage = Image.FromFile(@"icons\return_32px.png");
            buttonGoBack.Click          += (s, ee) =>
            {
                ShowPanel(panelMySurveys);
                buttonMySurveys.PerformClick();
            };
            panelCheckAnswers.Controls.Add(buttonGoBack);

            //If the survey hasn't got any answers yet, only a label will be shown telling the user that they are no answers to that survey
            if (!HasAnswers(survey))
            {
                Label label = CreateLabel(new Point(100, 50), "You don't have any answers to this survey!");
                label.Font = new Font("Century", 15, FontStyle.Bold);
                panelCheckAnswers.Controls.Add(label);
                return;
            }

            int Ycounter = 0;

            for (int i = 0; i < questions.Count; i++)
            {
                Label questionTitle = CreateLabel(new Point(20, 40 + Ycounter * 120 + i * 150), (i + 1) + "." + questions.ElementAt(i).Question_name);
                questionTitle.Font = new Font("Century", 12, FontStyle.Bold);

                //If the question is an option choice type, a bar chart will be shown with all the options and their answers
                if (b.GetInputTypeName(questions.ElementAt(i)) == "option")
                {
                    Chart answerChart = new Chart();
                    answerChart.SetBounds(20, 60 + Ycounter * 120 + i * 150, 500, 200);
                    answerChart.Series.Add(questions.ElementAt(i).Question_name);
                    answerChart.Series[questions.ElementAt(i).Question_name].Color = System.Drawing.Color.FromArgb(238, 26, 74);
                    List <option_choices> options = b.GetOptionsChoices(questions.ElementAt(i));
                    answerChart.ChartAreas.Add(new ChartArea());
                    answerChart.ChartAreas.First().AxisX.LabelStyle.Font = new Font("Century", 10);
                    answerChart.ChartAreas.First().AxisX.LabelStyle.ForeColor = System.Drawing.Color.FromArgb(238, 26, 74);
                    answerChart.ChartAreas.First().AxisY.LabelStyle.Font = new Font("Century", 10);
                    answerChart.ChartAreas.First().AxisY.LabelStyle.ForeColor = System.Drawing.Color.FromArgb(238, 26, 74);
                    foreach (var option in options)
                    {
                        answerChart.Series[questions.ElementAt(i).Question_name].Points.AddXY(option.Option_choices_name, b.GetAnswers(option.Id).Count);
                    }
                    panelCheckAnswers.Controls.Add(answerChart);
                    Ycounter++;
                }
                //If the question is a text answer type, a list of all the answers will be shown
                else
                {
                    List <text_answers> texts   = b.GetTextAnswers(questions.ElementAt(i));
                    ListBox             listBox = new ListBox();
                    listBox.SetBounds(30, 60 + Ycounter * 120 + i * 150, 550, 130);
                    listBox.Font                = new Font("Century", 12);
                    listBox.ForeColor           = System.Drawing.Color.FromArgb(238, 26, 74);
                    listBox.BorderStyle         = BorderStyle.None;
                    listBox.HorizontalScrollbar = true;
                    for (int j = 0; j < texts.Count; j++)
                    {
                        listBox.Items.Add(texts.ElementAt(j).Answer);
                    }
                    panelCheckAnswers.Controls.Add(listBox);
                }
                panelCheckAnswers.Controls.Add(questionTitle);
            }
        }
Пример #24
0
        /// <summary>
        /// Generate all the questions from a given survey
        /// </summary>
        private void GenerateQuestions(List <questions> questions, surveys currSurvey)
        {
            TextBox title = CreateTextBox("", new Point(20, 10), new Size(550, 20), 200);

            title.Text        = currSurvey.Name;
            title.ReadOnly    = true;
            title.BorderStyle = 0;
            title.BackColor   = this.BackColor;
            panelFillSurvey.Controls.Add(title);

            for (int i = 0; i < questions.Count; i++)
            {
                Label label1 = CreateLabel(new Point(20, 40 + i * 80), (i + 1) + "." + questions.ElementAt(i).Question_name);
                panelFillSurvey.Controls.Add(label1);

                if (b.GetInputTypeName(questions.ElementAt(i)) == "text")
                {
                    TextBox txt1 = CreateTextBox(i + 1 + "textBox", new Point(20, 60 + i * 80), new Size(600, 50), 500);
                    txt1.Multiline = true;
                    panelFillSurvey.Controls.Add(txt1);
                }
                else if (b.GetInputTypeName(questions.ElementAt(i)) == "option")
                {
                    List <option_choices> questionChoices = b.GetOptionsChoices(questions.ElementAt(i));
                    CheckBox box;
                    for (int j = 1; j < 4; j++)
                    {
                        box           = new CheckBox();
                        box.Text      = questionChoices.ElementAt(j - 1).Option_choices_name;
                        box.AutoSize  = true;
                        box.Name      = i + 1 + "option" + j;
                        box.Font      = new Font("Century", 12);
                        box.ForeColor = System.Drawing.Color.FromArgb(238, 26, 74);
                        box.Location  = new Point(30, 40 + i * 80 + j * 20);
                        panelFillSurvey.Controls.Add(box);
                    }
                }
            }
            //Button to send the answers to the database
            Button buttonSendSurvey = CreateButton(new Point(20, 50 + questions.Count * 80), new Size(200, 50), "Send Survey");

            buttonSendSurvey.BackColor = System.Drawing.Color.FromArgb(238, 26, 74);
            buttonSendSurvey.Click    += (sender, e) =>
            {
                sendSurvey();
            };
            panelFillSurvey.Controls.Add(buttonSendSurvey);
            //Button to cancel filling the survey
            Button buttonCancel = CreateButton(new Point(600, 10), new Size(32, 32), "");

            buttonCancel.BackgroundImage = Image.FromFile(@"icons\cancel_25px.png");
            buttonCancel.Click          += (s, ee) =>
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to exit filling this survey?", "Canceling", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    ClearPanelFillSurvey();
                }
            };
            panelFillSurvey.Controls.Add(buttonCancel);
        }