예제 #1
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;
 }
예제 #2
0
 public static void AddTextAnswersToDataBase(text_answers text_Answers)
 {
     for (int i = 1; i <= 3; i++)
     {
         text_Answers.Answer += i;
         txtan.AddTextAnswer(text_Answers);
     }
 }
예제 #3
0
 public void DeleteTextAnswer(text_answers answer)
 {
     textAswersDAL.DeleteTextAnswer(answer);
 }
예제 #4
0
 //TextAnswerDAL
 public void AddTextAnswer(text_answers answer)
 {
     textAswersDAL.AddTextAnswer(answer);
 }
예제 #5
0
        /// <summary>
        /// Take all the answers from the textboxs in the fill survey panel and add them to the database
        /// </summary>
        private void sendSurvey()
        {
            int questionCount = 1;
            List <text_answers> tAnswersSending = new List <text_answers>();
            List <answers>      optAnswers      = new List <answers>();

            foreach (var question in questionsSending)
            {
                if (b.GetInputTypeName(question) == "text")
                {
                    text_answers tAnswer = new text_answers();
                    tAnswer.User_name   = SignUpForm.LoggedUser.User_name;
                    tAnswer.Question_id = question.Id;
                    TextBox answer = panelFillSurvey.Controls.Find(questionCount + "textBox", false).First() as TextBox;
                    tAnswer.Answer = answer.Text;
                    tAnswersSending.Add(tAnswer);
                }
                else if (b.GetInputTypeName(question) == "option")
                {
                    for (int i = 0; i < 3; i++)
                    {
                        answers optAnswer = new answers();
                        optAnswer.User_name = SignUpForm.LoggedUser.User_name;
                        CheckBox option = panelFillSurvey.Controls.Find(questionCount + "option" + (i + 1), false).First() as CheckBox;
                        if (option.Checked == true)
                        {
                            optAnswer.Question_option_id = b.GetOptionsChoices(question).ElementAt(i).Id;
                        }
                        optAnswers.Add(optAnswer);
                    }
                }
                questionCount++;
            }
            //If any of the textbox haven't got an answer a warning will be shown
            foreach (var text in tAnswersSending)
            {
                if (string.IsNullOrWhiteSpace(text.Answer))
                {
                    MessageBox.Show("Not all questions have an answer!", "Error");
                    return;
                }
            }
            //If any of the option choices haven't got an answer a warning will be shown
            foreach (var question in questionsSending)
            {
                if (b.GetInputTypeName(question) == "option")
                {
                    if (!HasAnswer(question, optAnswers))
                    {
                        MessageBox.Show("Not all questions have an answer!", "Error");
                        return;
                    }
                }
            }
            //Add all the answers to the database
            foreach (var text in tAnswersSending)
            {
                b.AddTextAnswer(text);
            }
            foreach (var option in optAnswers)
            {
                if (option.Question_option_id != 0)
                {
                    b.AddAnswer(option);
                }
            }
            MessageBox.Show("Survey succesfully sent!");
            ClearPanelFillSurvey();
        }
예제 #6
0
 public void DeleteTextAnswer(text_answers answer)
 {
     surveyDBcontext.text_answers.Attach(answer);
     surveyDBcontext.text_answers.Remove(answer);
     surveyDBcontext.SaveChanges();
 }
예제 #7
0
 public void AddTextAnswer(text_answers answer)
 {
     surveyDBcontext.text_answers.Add(answer);
     surveyDBcontext.SaveChanges();
 }