public void TestCreateUpdateDeletePredefinedChoiceAndQuestion()
        {
            PredefinedQuestionDto pQuestion = new PredefinedQuestionDto();
            pQuestion.InternalId = "TestQuestion" + Guid.NewGuid();
            pQuestion.QuestionText = "Question text";

            PredefinedQuestionDto cQuestion = null;

            PredefinedChoiceDto pChoice = new PredefinedChoiceDto();
            pChoice.ChoiceLabel = "TestChoice";
            pChoice.SortSequence = -1;
            pChoice.FixedValue = "c1";

            PredefinedChoiceDto cChoice = null;


            cQuestion = FormRegistry.PredefinedQuestionDao.SaveQuestion(pQuestion, "new");
            Assert.IsNotNull(cQuestion, "Predefined question wasn't created");
            Assert.AreEqual(pQuestion.InternalId, cQuestion.InternalId, "Predefined question has invalid internal id");
            Assert.AreEqual(pQuestion.QuestionText, cQuestion.QuestionText, "Predefined question has invalid question text");
            Assert.AreEqual(0, cQuestion.StatusActive, "Predefined question has invalid status active");
            Assert.AreNotEqual(0, cQuestion.QuestionId, "Predefined question has invalid question id");
            
            pChoice.PredefinedQuestionDto = cQuestion;
            cChoice = FormRegistry.PredefinedQuestionDao.SaveChoice(pChoice, "new");
            Assert.IsNotNull(cChoice, "Predefined choice wasn't created");
            Assert.AreNotEqual(0, cChoice.ChoiceId, "Predefined choice has invalid choice id");
            Assert.AreEqual(pChoice.ChoiceLabel, cChoice.ChoiceLabel, "Predefined choice has invalid choice label");
            Assert.AreEqual(pChoice.FixedValue, cChoice.FixedValue, "Predefined choice has invalid fixed value");
            Assert.IsNotNull(cChoice.PredefinedQuestionDto, "Predefined choice is not assign to any predefined question");
            Assert.AreEqual(cQuestion.QuestionId, cChoice.PredefinedQuestionDto.QuestionId, "Predefined choice has invalid predefined questio id");
            Assert.AreEqual(pChoice.SortSequence, cChoice.SortSequence, "Predefined choice has invalid sort sequence");

            cQuestion.StatusActive = 1;
            cQuestion.QuestionText = "Question text = changed";
            cQuestion = FormRegistry.PredefinedQuestionDao.SaveQuestion(cQuestion, "edit");
            Assert.IsNotNull(cQuestion, "Predefined question wasn't updated");
            Assert.AreEqual(1, cQuestion.StatusActive, "Status active of predefined question wasn't updated correctly");
            Assert.AreEqual("Question text = changed", cQuestion.QuestionText, "Question text of predefined question wasn't updated correctly");
            cChoice.PredefinedQuestionDto = cQuestion;

            cChoice.ChoiceLabel = "TestChoice - Changed";
            cChoice = FormRegistry.PredefinedQuestionDao.SaveChoice(cChoice, "edit");
            Assert.IsNotNull(cChoice, "Predefined choice wasn't updated");
            Assert.AreEqual("TestChoice - Changed", cChoice.ChoiceLabel, "Choice label of predefined choice wasn't updated correctly");


            FormRegistry.PredefinedQuestionDao.DeleteChoice(cChoice.ChoiceId);
            Assert.AreEqual(0, FormRegistry.PredefinedQuestionDao.GetPredefinedChoices(null, cChoice.ChoiceId).Count);
            cChoice = null;

            FormRegistry.PredefinedQuestionDao.DeletePredefinedQuestion(cQuestion.QuestionId);
            Assert.IsNull(FormRegistry.PredefinedQuestionDao.GetQuestionById(cQuestion.QuestionId));
            cQuestion = null;
        }
Esempio n. 2
0
        public PredefinedChoiceDto SaveChoice(PredefinedChoiceDto pChoiceDto, string mode)
        {
            PredefinedChoiceDto retval = null;
            DbCommand sp = null;
            DbConnection connection = null;
            IDataReader reader = null;
            try
            {
                connection = _dbLayer.GetConnection();
                sp = connection.CreateCommand();

                sp.CommandText = "update_predefined_choice";
                sp.CommandType = CommandType.StoredProcedure;
                if (mode == "edit")
                    _dbLayer.AddParameter(sp, "@choice_id", ParameterDirection.Input, DbType.Int32, pChoiceDto.ChoiceId);
                if (pChoiceDto.PredefinedQuestionDto != null)
                    _dbLayer.AddParameter(sp, "@predefined_question_FK", ParameterDirection.Input, DbType.Int32, pChoiceDto.PredefinedQuestionDto.QuestionId);
                _dbLayer.AddParameter(sp, "@sort_sequence", ParameterDirection.Input, DbType.Int32, pChoiceDto.SortSequence);
                _dbLayer.AddParameter(sp, "@choice_label", ParameterDirection.Input, DbType.String, pChoiceDto.ChoiceLabel);
                _dbLayer.AddParameter(sp, "@fixed_value", ParameterDirection.Input, DbType.String, pChoiceDto.FixedValue);
                _dbLayer.AddParameter(sp, "@other_text", ParameterDirection.Input, DbType.String, pChoiceDto.OtherText);
                _dbLayer.AddParameter(sp, "@error_message", ParameterDirection.Input, DbType.String, pChoiceDto.ErrorMessage);
                _dbLayer.AddReturnParameter(sp);
                reader = sp.ExecuteReader();
                if (reader.Read())
                {
                    bool alreadyRead = true; ;
                    retval = ReadPredefineChoice(reader, ref alreadyRead);
                }
                else
                {
                    int err = _dbLayer.GetReturnValue(sp);
                    Trace.WriteLine("PredefinedQuestionDao.SaveChoice("+pChoiceDto + ", "+mode+ ") returned " + err);
                }
            }
            catch (DbException e)
            {
                Trace.WriteLine("PredefinedQuestionDao.SaveChoice(" + pChoiceDto + ", " + mode + "): " + e.Message);
                retval = null;
            }
            finally
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();
                if (sp != null)
                    sp.Dispose();
                if (connection != null)
                {
                    _dbLayer.ReturnConnection(connection);
                }
                else
                {
                    _dbLayer.ReturnConnection(connection, true);
                }
            }
            return retval;
        }
Esempio n. 3
0
 protected PredefinedChoiceDto ReadPredefineChoice(IDataReader reader, ref bool alreadyRead)
 {
     PredefinedChoiceDto retval = new PredefinedChoiceDto();
     retval.ChoiceId = reader.GetInt32(0);
     retval.PredefinedQuestionDto = GetQuestionById(reader.GetInt32(1));
     retval.SortSequence = reader.GetInt32(2);
     retval.ChoiceLabel = reader.GetString(3);
     retval.FixedValue = reader.GetString(4);
     retval.OtherText = GetString(reader, 5);
     retval.ErrorMessage = GetString(reader, 6);
     alreadyRead = reader.Read();
     return retval;
 }
Esempio n. 4
0
        public PredefinedQuestionDto CreateNewPredefinedQuestion()
        {
            if (_currentPredefinedChoices == null)
                _currentPredefinedChoices = new List<PredefinedChoiceDto>();

            PredefinedQuestionDto pQuestion = new PredefinedQuestionDto();
            pQuestion.InternalId = "TestInternalId" + Guid.NewGuid();
            pQuestion.QuestionText = "TestQuestionText";
            _currentPredefinedQuestion = FormRegistry.PredefinedQuestionDao.SaveQuestion(pQuestion, "new");
            _createdPredefinedQuestions.Add(_currentPredefinedQuestion.QuestionId);            

            PredefinedChoiceDto pChoice = new PredefinedChoiceDto();
            pChoice.ChoiceLabel = "TestChoiceLabel";
            pChoice.PredefinedQuestionDto = _currentPredefinedQuestion;
            pChoice.FixedValue = "c1";
            pChoice.SortSequence = -1;
            pChoice = FormRegistry.PredefinedQuestionDao.SaveChoice(pChoice, "new");
            _createdPredefinedQuestionChoices.Add(pChoice.ChoiceId);
            _currentPredefinedChoices.Add(pChoice);

            PredefinedChoiceDto pChoiceOther = new PredefinedChoiceDto();
            pChoiceOther.ChoiceLabel = "TestChoiceLabelOther";
            pChoiceOther.OtherText = "TestOtherText";
            pChoiceOther.ErrorMessage = "TestErrorMessage";
            pChoiceOther.PredefinedQuestionDto = _currentPredefinedQuestion;
            pChoiceOther.FixedValue = "c2";
            pChoiceOther.SortSequence = 999;
            pChoiceOther = FormRegistry.PredefinedQuestionDao.SaveChoice(pChoiceOther, "new");
            _createdPredefinedQuestionChoices.Add(pChoiceOther.ChoiceId);
            _currentPredefinedChoices.Add(pChoiceOther);

            _currentPredefinedQuestion.StatusActive = 1;
            _currentPredefinedQuestion = FormRegistry.PredefinedQuestionDao.SaveQuestion(_currentPredefinedQuestion, "edit");
            foreach (PredefinedChoiceDto choice in _currentPredefinedChoices)
                choice.PredefinedQuestionDto = _currentPredefinedQuestion;

            return _currentPredefinedQuestion;
        }
 public static PredefinedChoiceDto SaveChoice(PredefinedChoiceDto pChoiceDto, string mode)
 {
     return FormRegistry.PredefinedQuestionDao.SaveChoice(pChoiceDto, mode);
 }
Esempio n. 6
0
        public List<PredefinedChoiceDto> CreateNewPredefinedChoices()
        {
            if(_currentPredefinedChoices == null)
                _currentPredefinedChoices = new List<PredefinedChoiceDto>();

            PredefinedChoiceDto pChoice = new PredefinedChoiceDto();
            pChoice.ChoiceLabel = "TestChoiceLabel";
            pChoice.PredefinedQuestionDto = _currentPredefinedQuestion;
            pChoice.FixedValue = "c1";
            pChoice.SortSequence = -1;
            pChoice = FormRegistry.PredefinedQuestionDao.SaveChoice(pChoice, "new");
            _createdPredefinedQuestionChoices.Add(pChoice.ChoiceId);
            _currentPredefinedChoices.Add(pChoice);

            PredefinedChoiceDto pChoiceOther = new PredefinedChoiceDto();
            pChoiceOther.ChoiceLabel = "TestChoiceLabelOther";
            pChoiceOther.OtherText = "TestOtherText";
            pChoiceOther.ErrorMessage = "TestErrorMessage";
            pChoiceOther.PredefinedQuestionDto = _currentPredefinedQuestion;
            pChoiceOther.FixedValue = "c2";
            pChoiceOther.SortSequence = 999;
            pChoiceOther = FormRegistry.PredefinedQuestionDao.SaveChoice(pChoiceOther, "new");
            _createdPredefinedQuestionChoices.Add(pChoiceOther.ChoiceId);
            _currentPredefinedChoices.Add(pChoiceOther);

            return _currentPredefinedChoices;
        }
Esempio n. 7
0
 protected void ParseBulkToListChoices()
 {
     incorrect_bulk_lbl.Text = String.Empty;
     if (!String.IsNullOrEmpty(bulk_txt.Text))
     {
         string[] listOfChoices = bulk_txt.Text.Split(Environment.NewLine.ToCharArray());
         foreach (String choice in listOfChoices)
         {
             if (choice.Trim() != String.Empty)
             {
                 string[] choiceTable = choice.Split('\t');
                 //one line should be one choice 
                 if (choiceTable.Length != 3)
                 {
                     incorrect_bulk_lbl.Text += "Row with content '" + choice + "' can not be processed due to invalid row format. <br/>";
                     incorrectBulkPanel.Visible = true;
                 }
                 else
                 {
                     bool rowCorrect = true;
                     if (String.IsNullOrEmpty(choiceTable[0]))
                     {
                         incorrect_bulk_lbl.Text += "Row with content '" + choice + "' can not be processed due to invalid choice label format. <br/>";
                         incorrectBulkPanel.Visible = true;
                         rowCorrect = false;
                     }
                     int ordering;
                     if (String.IsNullOrEmpty(choiceTable[1]) || !int.TryParse(choiceTable[1], out ordering))
                     {
                         incorrect_bulk_lbl.Text += "Row with content '" + choice + "' can not be processed due to invalid ordering format. <br/>";
                         incorrectBulkPanel.Visible = true;
                         rowCorrect = false;
                     }
                     else if (ordering < -1 || (ordering > 800 && ordering != 999))
                     {
                         incorrect_bulk_lbl.Text += "Row with content '" + choice + "' can not be processed due to invalid ordering number. <br/>";
                         incorrectBulkPanel.Visible = true;
                         rowCorrect = false;
                     }
                     if (String.IsNullOrEmpty(choiceTable[2]))
                     {
                         incorrect_bulk_lbl.Text += "Row with content '" + choice + "' can not be processed due to invalid fixed value format. <br/>";
                         incorrectBulkPanel.Visible = true;
                         rowCorrect = false;
                     }
                     if (rowCorrect)
                     {
                         PredefinedChoiceDto pcDto = new PredefinedChoiceDto();
                         pcDto.ChoiceLabel = choiceTable[0];
                         pcDto.SortSequence = int.Parse(choiceTable[1]);
                         pcDto.FixedValue = choiceTable[2];
                         listOfPredefinedChoices.Add(pcDto);                                
                     }
                 }
             }
         }
     }
     else
     {
         incorrect_bulk_lbl.Text += "Empty row can not be processed due to invalid format";
         incorrectBulkPanel.Visible = true;
     }
     LoadListOfChoices();
     if (!incorrectBulkPanel.Visible)
     {
         bulk_txt.Text = String.Empty;
     }
 }
Esempio n. 8
0
 protected void AddChoice_Click(object sender, EventArgs e)
 {
     InitializeErrorsPanels();
     if (ValidateAddChoice(label_add_txt.Text, 
         fixed_value_add_txt.Text, 
         ordering_add_dropdown.SelectedIndex, 
         ordering_add_dropdown.SelectedValue,
         individual_order_add_txt.Text))
     {
         PredefinedChoiceDto pcDto = new PredefinedChoiceDto();
         pcDto.ChoiceLabel = label_add_txt.Text;
         pcDto.SortSequence = ParseOrderingIntoSortSequence(ordering_add_dropdown, individual_order_add_txt.Text);
         pcDto.FixedValue = fixed_value_add_txt.Text;
         listOfPredefinedChoices.Add(pcDto);
         LoadListOfChoices();
         ResetAddChoice();
     }
 }
Esempio n. 9
0
 /// <summary>
 /// The function bind data from other controls into other choice in listOfChoices
 /// </summary>
 protected Boolean GetOther()
 {
     bool validated = true;
     if (!String.IsNullOrEmpty(other_txt.Text) &&
         !String.IsNullOrEmpty(other_extratext_txt.Text) &&
         !String.IsNullOrEmpty(other_fixed_value_txt.Text) &&
         !String.IsNullOrEmpty(error_message_txt.Text))
     {
         PredefinedChoiceDto theSameFixedValueChoice = null;
         if(listOfPredefinedChoices != null && listOfPredefinedChoices.Count > 0)
             theSameFixedValueChoice = listOfPredefinedChoices.Find(c =>c.FixedValue == other_fixed_value_txt.Text);
         //if other choice already exists
         if (theSameFixedValueChoice != null)
         {
             noUniqueOtherFixedValuePanel.Visible = true;
             validated = false;
         }
         else
         {
             if (predefinedOtherChoice == null)
                 predefinedOtherChoice = new PredefinedChoiceDto();
             predefinedOtherChoice.ChoiceLabel = other_txt.Text;
             predefinedOtherChoice.OtherText = other_extratext_txt.Text;
             predefinedOtherChoice.FixedValue = other_fixed_value_txt.Text;
             predefinedOtherChoice.ErrorMessage = error_message_txt.Text;
             predefinedOtherChoice.SortSequence = 999;
         }
     }
     else if (String.IsNullOrEmpty(other_txt.Text) &&
         String.IsNullOrEmpty(other_extratext_txt.Text) &&
         String.IsNullOrEmpty(other_fixed_value_txt.Text) &&
         String.IsNullOrEmpty(error_message_txt.Text))
     {
         predefinedOtherChoice = null;
     }
     return validated;
 }        
Esempio n. 10
0
        protected void Page_Load_Edit()
        {
            page_utilities.Set_titles(this.Page, "Edit Pre-Defined Question");
            if (!IsPostBack)
            {
                predefinedOtherChoice = new PredefinedChoiceDto();
                predefinedQuestionDto = PredefinedQuestionFacade.GetPredefinedQuestionByQuestionId(int.Parse(Session["question_id"].ToString()));
                List<PredefinedChoiceDto> listOfAllChoices = PredefinedQuestionFacade.GetPredefinedChoicesByPredefinedQuestionId(int.Parse(Session["question_id"].ToString()));
                listOfPredefinedChoices = new List<PredefinedChoiceDto>();
                foreach (PredefinedChoiceDto choice in listOfAllChoices)
                {
                    if (choice.SortSequence == 999 && !String.IsNullOrEmpty(choice.OtherText) && !String.IsNullOrEmpty(choice.ErrorMessage))
                        predefinedOtherChoice = choice;
                    else
                        listOfPredefinedChoices.Add(choice);
                }
                delMsg.Text = @"*Deleting an existing predefined question is only possible if that question is not used on any form!";

                LoadQuestion();
                LoadListOfChoices();
                LoadOtherChoice();
            }
        }        
Esempio n. 11
0
 protected void Page_Load_New()
 {
     page_utilities.Set_titles(this.Page, "Create Pre-Defined Question");
     delete_question.Visible = false;            
     if (!IsPostBack)
     {
         noChoicePanel.Visible = false;
         incorrectChoicePanel.Visible = false;
         incorrectQuestionTextPanel.Visible = false;
         
         predefinedQuestionDto = new PredefinedQuestionDto();
         listOfPredefinedChoices = new List<PredefinedChoiceDto>();
         predefinedOtherChoice = new PredefinedChoiceDto();
     }
 }