public void TestCreateUpdateDeletePagePredefinedChoicesAndQuestion() { CreateNewQuestionnaire(); CreateNewFormPage(); CreateNewPredefinedQuestion(); PagePredefinedQuestionDto ppQuestion = new PagePredefinedQuestionDto(); ppQuestion.PQuestion = _currentPredefinedQuestion; ppQuestion.PageId = _currentPage.PageId; ppQuestion.ElementType = PageElementType.CheckBoxesLong; ppQuestion.Required = true; ppQuestion.SortSequence = 2; ppQuestion.StatusActive = 0; PagePredefinedQuestionDto ccQuestion = FormRegistry.PredefinedQuestionDao.SavePageQuestion(ppQuestion, "new"); Assert.IsNotNull(ccQuestion, "Page predefined question wasn't created"); Assert.AreEqual(ppQuestion.ElementType, ccQuestion.ElementType, "Page predefined question has invalid element type"); Assert.IsNotNull(ccQuestion.PQuestion, "Page predefined question has no assign predefined question"); Assert.AreEqual(_currentPredefinedQuestion.QuestionId, ccQuestion.PQuestion.QuestionId, "Page predefined question has invalid predefined question id"); Assert.AreEqual(ppQuestion.Required, ccQuestion.Required, "Page predefined question has invalid required value"); Assert.AreEqual(ppQuestion.SortSequence, ccQuestion.SortSequence, "Page predefined question has invalid sort sequence value"); Assert.AreEqual(0, ccQuestion.StatusActive, "Page predefined question has invalid status active"); Assert.AreNotEqual(0, ccQuestion.PagePredefinedQuestionId, "Page predefined question has invalid question id"); PagePredefinedQuestionChoiceDto ppChoice = new PagePredefinedQuestionChoiceDto(); ppChoice.PagePredefinedQuestionId = ccQuestion.PagePredefinedQuestionId; if (_currentPredefinedChoices != null && _currentPredefinedChoices.Count > 0) ppChoice.PChoice = _currentPredefinedChoices[0]; else { CreateNewPredefinedChoices(); ppChoice.PChoice = _currentPredefinedChoices[0]; } PagePredefinedQuestionChoiceDto ccChoice = FormRegistry.PredefinedQuestionDao.SavePageQuestionChoice(ppChoice, "new"); Assert.IsNotNull(ccChoice, "Page predefined choice wasn't created"); Assert.AreNotEqual(0, ccChoice.ElementId, "Page predefined choice has invalid choice id"); Assert.AreEqual(ccQuestion.PagePredefinedQuestionId, ccChoice.PagePredefinedQuestionId, "Page predefined choice has invalid page predefined id"); Assert.IsNotNull(ccChoice.PChoice, "Page predefined choice has not assign any predefined choice"); Assert.AreEqual(_currentPredefinedChoices[0].ChoiceId, ccChoice.PChoice.ChoiceId, "Page predefined choice has assign incorrect predefined choice"); ccQuestion.StatusActive = 1; ccQuestion.SortSequence = 4; ccQuestion = FormRegistry.PredefinedQuestionDao.SavePageQuestion(ccQuestion, "edit"); Assert.IsNotNull(ccQuestion, "Page predefined question wasn't updated"); Assert.AreEqual(1, ccQuestion.StatusActive, "Status active of page predefined question wasn't updated correctly"); Assert.AreEqual(4, ccQuestion.SortSequence, "Sort sequence of page predefined question wasn't updated correctly"); FormRegistry.PredefinedQuestionDao.DeletePagePredefinedChoice(ccChoice.ElementId); Assert.AreEqual(0, FormRegistry.PredefinedQuestionDao.GetPagePredefinedQuestionChoices(null, ccChoice.ElementId).Count); ccChoice = null; FormRegistry.PredefinedQuestionDao.DeletePagePredefinedQuestion(ccQuestion.PagePredefinedQuestionId); Assert.AreEqual(0, FormRegistry.PredefinedQuestionDao.GetPagePredefinedQuestion(ccQuestion.PagePredefinedQuestionId, null, null).Count); ccQuestion = null; }
protected PagePredefinedQuestionDto ReadPagePredefinedQuestion(IDataReader reader) { PagePredefinedQuestionDto retval = new PagePredefinedQuestionDto(); retval.PagePredefinedQuestionId = reader.GetInt32(0); retval.PQuestion = GetQuestionById(reader.GetInt32(1)); retval.PageId = reader.GetInt32(2); retval.SortSequence = reader.GetInt16(3); retval.Required = reader.GetBoolean(4); retval.ElementType = TypeParser(reader.GetString(5)); if (GetInt16(reader, 6).HasValue) { retval.StatusActive = GetInt16(reader, 6).Value; } return retval; }
public PagePredefinedQuestionDto SavePageQuestion(PagePredefinedQuestionDto question, string mode) { PagePredefinedQuestionDto retval = null; DbCommand sp = null; DbConnection connection = null; IDataReader reader = null; try { connection = _dbLayer.GetConnection(); sp = connection.CreateCommand(); sp.CommandText = "update_page_predefined_question"; sp.CommandType = CommandType.StoredProcedure; if (mode == "edit") _dbLayer.AddParameter(sp, "@element_id", ParameterDirection.Input, DbType.Int32, question.PagePredefinedQuestionId); _dbLayer.AddParameter(sp, "@question_id", ParameterDirection.Input, DbType.Int32, question.PQuestion.QuestionId); _dbLayer.AddParameter(sp, "@page_id", ParameterDirection.Input, DbType.Int32, question.PageId); _dbLayer.AddParameter(sp, "@sort_sequence", ParameterDirection.Input, DbType.Int16, question.SortSequence); _dbLayer.AddParameter(sp, "@required", ParameterDirection.Input, DbType.Boolean, question.Required); _dbLayer.AddParameter(sp, "@element_type", ParameterDirection.Input, DbType.String, TypeParser(question.ElementType)); _dbLayer.AddParameter(sp, "@status_active", ParameterDirection.Input, DbType.Int16, question.StatusActive); _dbLayer.AddReturnParameter(sp); reader = sp.ExecuteReader(); if (reader.Read()) { retval = ReadPagePredefinedQuestion(reader); } else { int err = _dbLayer.GetReturnValue(sp); Trace.WriteLine("PredefinedQuestionDao.SavePageQuestion returned " + err); } } catch (DbException e) { Trace.WriteLine("PredefinedQuestionDao.SavePageQuestion: " + 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; }
public void Initialize(QuestionnaireDto quesitonnaire, PageDto page, PagePredefinedQuestionAssemblyDto pagePredefinedQuestionAssembly) { _pageElementType = pagePredefinedQuestionAssembly.Question.ElementType; _questionnaire = quesitonnaire; _page = page; _pageQuestion = pagePredefinedQuestionAssembly.Question; _pageQuestionChoices = pagePredefinedQuestionAssembly.Choices; _isValid = true; Load += new EventHandler(WucPageElementBase_Load); }
public PagePredefinedQuestionDto CreateNewPagePredefinedQuestion() { if (_currentPagePredefinedChoices == null) _currentPagePredefinedChoices = new List<PagePredefinedQuestionChoiceDto>(); if (_currentQuestionnaire == null) CreateNewQuestionnaire(); if (_currentPage == null) CreateNewFormPage(); if (_currentPredefinedQuestion == null) CreateNewPredefinedQuestion(); if (_currentPredefinedChoices == null && _currentPagePredefinedChoices.Count < 1) CreateNewPredefinedChoices(); PagePredefinedQuestionDto ppQuestion = new PagePredefinedQuestionDto(); ppQuestion.PQuestion = _currentPredefinedQuestion; ppQuestion.PageId = _currentPage.PageId; ppQuestion.ElementType = PageElementType.CheckBoxesLong; ppQuestion.Required = true; ppQuestion.SortSequence = 2; ppQuestion.StatusActive = 0; _currentPagePredefinedQuestion = FormRegistry.PredefinedQuestionDao.SavePageQuestion(ppQuestion, "new"); _createdPagePredefinedQuestions.Add(_currentPagePredefinedQuestion.PagePredefinedQuestionId); PagePredefinedQuestionChoiceDto ppChoice = new PagePredefinedQuestionChoiceDto(); ppChoice.PagePredefinedQuestionId = _currentPagePredefinedQuestion.PagePredefinedQuestionId; ppChoice.PChoice = _currentPredefinedChoices[0]; PagePredefinedQuestionChoiceDto ccChoice = FormRegistry.PredefinedQuestionDao.SavePageQuestionChoice(ppChoice, "new"); _currentPagePredefinedChoices.Add(ccChoice); _createdPagePredefinedQuestionChoices.Add(ccChoice.ElementId); _currentPagePredefinedQuestion.StatusActive = 1; _currentPagePredefinedQuestion = FormRegistry.PredefinedQuestionDao.SavePageQuestion(_currentPagePredefinedQuestion, "edit"); return _currentPagePredefinedQuestion; }
protected virtual void TearDown() { bool failed = false; foreach (int id in _createdMasterReports) { try { FormRegistry.MasterReportDao.DeleteMasterReport(id); } catch (Exception e) { Trace.WriteLine("Exception during master report deletion: " + e); failed = true; } } _createdMasterReports.Clear(); foreach (int pagePredefinedQuestionChoiceId in _createdPagePredefinedQuestionChoices) { try { FormRegistry.PredefinedQuestionDao.DeletePagePredefinedChoice(pagePredefinedQuestionChoiceId); } catch { failed = true; } } _createdPagePredefinedQuestionChoices.Clear(); foreach (int pagePredefinedQuestionId in _createdPagePredefinedQuestions) { try { FormRegistry.PredefinedQuestionDao.DeletePagePredefinedQuestion(pagePredefinedQuestionId); } catch { failed = true; } } _createdPagePredefinedQuestions.Clear(); foreach (int predefinedChoiceId in _createdPredefinedQuestionChoices) { try { FormRegistry.PredefinedQuestionDao.DeleteChoice(predefinedChoiceId); } catch { failed = true; } } _createdPredefinedQuestionChoices.Clear(); foreach (int predefinedQuestionId in _createdPredefinedQuestions) { try { FormRegistry.PredefinedQuestionDao.DeletePredefinedQuestion(predefinedQuestionId); } catch { failed = true; } } _createdPredefinedQuestions.Clear(); foreach (int questionnaireId in _createdQuestionnaires) { if (!FormRegistry.QuestionnaireDao.Delete(questionnaireId, TestUser)) { failed = true; } } _createdQuestionnaires.Clear(); foreach (string campaignCode in _createdCampaigns) { if (!FormRegistry.CampaignDao.Delete(campaignCode, _currentCampaign.CreatorEmailAddress)) { failed = true; } } _createdCampaigns.Clear(); _currentCampaign = null; _currentQuestionnaire = null; _currentPage = null; _currentPredefinedQuestion = null; _currentPredefinedChoices = null; _currentPagePredefinedQuestion = null; _currentPagePredefinedChoices = null; Assert.IsFalse(failed, "errors during deletion"); }
public static PagePredefinedQuestionDto SavePageQuestion(PagePredefinedQuestionDto question, String mode) { return FormRegistry.PredefinedQuestionDao.SavePageQuestion(question, mode); }
protected void PageLoad_New() { //label_sorts.Enabled = false; //sort_dropdown.Enabled = false; delete.Visible = false; delMsg.Visible = false; questionId = int.Parse(Session["predefined_question_id"].ToString()); questionType = Migration.Convert(Session["question_type"].ToString()); switch (questionType) { case PageElementType.CheckBoxesLong: question_definition.Text = "Checkboxes_longer_choices [many of many]"; break; case PageElementType.RadioButtonsLong: question_definition.Text = "Radiobuttons_longer_choices [one of many]"; break; case PageElementType.DropDown: question_definition.Text = "Dropdown [one of many]"; break; } pageQuestion = null; listOfPageChoices = null; }
protected void Save_Edit() { bool validated = true; validated = validated & GetPagePredefinedQuestion(); validated = validated & GetPagePredefinedQuestionChoices(ref listOfPageChoices); if (validated) { pageQuestion = PredefinedQuestionFacade.SavePageQuestion(pageQuestion, "edit"); List<PagePredefinedQuestionChoiceDto> listOfSavedPageChoices = PredefinedQuestionFacade.GetPagePredefinedQuestionChoicesByPagePredefinedQuestionId(pageQuestionId); //delete all unselected choices if (listOfSavedPageChoices != null && listOfSavedPageChoices.Count > 0) { foreach (PagePredefinedQuestionChoiceDto choice in listOfSavedPageChoices) { if (choice.PChoice != null && ((listOfPageChoices != null && listOfPageChoices.Find(c => c.PChoice != null && c.PChoice.ChoiceId == choice.PChoice.ChoiceId) == null) || listOfPageChoices == null)) { PredefinedQuestionFacade.DeletePagePredefinedQuestionChoice(choice.ElementId); } } } if (listOfPageChoices != null && listOfPageChoices.Count > 0) { //add all new items foreach (PagePredefinedQuestionChoiceDto choice in listOfPageChoices) { if (choice.PChoice != null && ((listOfSavedPageChoices != null && listOfSavedPageChoices.Find(c => c.PChoice != null && c.PChoice.ChoiceId == choice.PChoice.ChoiceId) == null) || (listOfSavedPageChoices == null))) { choice.PagePredefinedQuestionId = pageQuestion.PagePredefinedQuestionId; choice.ElementId = PredefinedQuestionFacade.SavePageQuestionChoice(choice, "new").ElementId; } } } Session["questionnaire_id"] = questionnaire_id; Response.Redirect("edit_formpage.aspx"); } }
protected void Save_New() { pageQuestion = new PagePredefinedQuestionDto(); listOfPageChoices = new List<PagePredefinedQuestionChoiceDto>(); bool validated = true; validated = validated & GetPagePredefinedQuestion(); validated = validated & GetPagePredefinedQuestionChoices(ref listOfPageChoices); if (validated) { int sSequence = pageQuestion.SortSequence; pageQuestion.SortSequence = sortSequenceForNewElement; pageQuestion = PredefinedQuestionFacade.SavePageQuestion(pageQuestion, "new"); foreach (PagePredefinedQuestionChoiceDto choice in listOfPageChoices) { choice.PagePredefinedQuestionId = pageQuestion.PagePredefinedQuestionId; choice.ElementId = PredefinedQuestionFacade.SavePageQuestionChoice(choice, "new").ElementId; } pageQuestion.StatusActive = 1; pageQuestion.SortSequence = sSequence; pageQuestion = PredefinedQuestionFacade.SavePageQuestion(pageQuestion, "edit"); Session["questionnaire_id"] = questionnaire_id; Response.Redirect("edit_formpage.aspx"); } }
protected void PageLoad_Edit() { label_sorts.Enabled = true; sort_dropdown.Enabled = true; delete.Visible = true; delMsg.Visible = true; delMsg.ForeColor = Color.Red; delMsg.Text = @"<b>*Deleting whole questions or single choices will delete some parts of existing customer responses too! Please refer to the </b><a href=""../userguide/faq.aspx#delete"" target=""_blank"">instructions</a><b> first before deleting questions/choices.</b>"; if (Session["page_predefined_question_id"] != null) { pageQuestionId = int.Parse(Session["page_predefined_question_id"].ToString()); } else if (Request.QueryString["id"] != null) { var a = Request.QueryString["id"]; pageQuestionId = int.Parse(Request.QueryString["id"]); } pageQuestion = PredefinedQuestionFacade.GetPagePredefinedQuestionByPagePredefinedQuestionId(pageQuestionId); questionId = pageQuestion.PQuestion.QuestionId; questionType = pageQuestion.ElementType; switch (pageQuestion.ElementType) { case PageElementType.CheckBoxesLong: question_definition.Text = "Checkboxes_longer_choices [many of many]"; break; case PageElementType.RadioButtonsLong: question_definition.Text = "Radiobuttons_longer_choices [one of many]"; break; case PageElementType.DropDown: question_definition.Text = "Dropdown [one of many]"; break; } }