public PagePredefinedQuestionChoiceDto SavePageQuestionChoice(PagePredefinedQuestionChoiceDto choice, string mode) { PagePredefinedQuestionChoiceDto retval = null; DbCommand sp = null; DbConnection connection = null; IDataReader reader = null; try { connection = _dbLayer.GetConnection(); sp = connection.CreateCommand(); sp.CommandText = "update_page_predefined_choice"; sp.CommandType = CommandType.StoredProcedure; if (mode == "edit") _dbLayer.AddParameter(sp, "@element_id", ParameterDirection.Input, DbType.Int32, choice.ElementId); if (choice.PChoice != null) _dbLayer.AddParameter(sp, "@predefined_choice_id", ParameterDirection.Input, DbType.Int32, choice.PChoice.ChoiceId); _dbLayer.AddParameter(sp, "@page_predefined_question_FK", ParameterDirection.Input, DbType.Int32, choice.PagePredefinedQuestionId); _dbLayer.AddReturnParameter(sp); reader = sp.ExecuteReader(); if (reader.Read()) { bool alreadyRead = true; ; retval = ReadPagePredefinedQuestionChoice(reader, ref alreadyRead); } else { int err = _dbLayer.GetReturnValue(sp); Trace.WriteLine("PredefinedQuestionDao.SavePageQuestionChoice returned " + err); } } catch (DbException e) { Trace.WriteLine("PredefinedQuestionDao.SavePageQuestionChoice: " + 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; }
protected PagePredefinedQuestionChoiceDto ReadPagePredefinedQuestionChoice(IDataReader reader, ref bool alreadyRead) { PagePredefinedQuestionChoiceDto retval = new PagePredefinedQuestionChoiceDto(); retval.ElementId = reader.GetInt32(0); retval.PagePredefinedQuestionId = reader.GetInt32(1); retval.PChoice = GetPredefinedChoices(null, reader.GetInt32(2))[0]; alreadyRead = reader.Read(); return retval; }
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; }
public List<PagePredefinedQuestionChoiceDto> CreateNewPagePredefinedQuestionChoices() { if (_currentPagePredefinedChoices == null) _currentPagePredefinedChoices = new List<PagePredefinedQuestionChoiceDto>(); 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); return _currentPagePredefinedChoices; }
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; }
public static PagePredefinedQuestionChoiceDto SavePageQuestionChoice(PagePredefinedQuestionChoiceDto choice, String mode) { return FormRegistry.PredefinedQuestionDao.SavePageQuestionChoice(choice, mode); }
protected bool GetPagePredefinedQuestionChoices(ref List<PagePredefinedQuestionChoiceDto> list) { bool validated = true; try { if (Request.QueryString["content"] == "new") { for (int i = 0; i < listChoicesRepeater.Items.Count; i++) { RepeaterItem item = listChoicesRepeater.Items[i]; if (((CheckBox)item.FindControl("select_ckb")).Checked) { PagePredefinedQuestionChoiceDto choice = new PagePredefinedQuestionChoiceDto(); int choiceId = int.Parse(((HiddenField)item.FindControl("choice_id")).Value); choice.PChoice = PredefinedQuestionFacade.GetPredefinedChoiceByChoiceId(choiceId); list.Add(choice); } } } else { for (int i = 0; i < listChoicesRepeater.Items.Count; i++) { RepeaterItem item = listChoicesRepeater.Items[i]; if (((CheckBox)item.FindControl("select_ckb")).Checked) { int choiceId = int.Parse(((HiddenField)item.FindControl("choice_id")).Value); if ((listOfPageChoices != null && listOfPageChoices.Count > 0 && listOfPageChoices.Find(c => c.PChoice.ChoiceId == choiceId) == null) || listOfPageChoices == null) { PagePredefinedQuestionChoiceDto cTemp = new PagePredefinedQuestionChoiceDto(); cTemp.PChoice = PredefinedQuestionFacade.GetPredefinedChoiceByChoiceId(choiceId); list.Add(cTemp); } } else { int choiceId = int.Parse(((HiddenField)item.FindControl("choice_id")).Value); if (listOfPageChoices != null && listOfPageChoices.Count > 0) { PagePredefinedQuestionChoiceDto cChoice = listOfPageChoices.Find(c => c.PChoice.ChoiceId == choiceId); if (cChoice != null) list.Remove(cChoice); } } } } return validated; } catch (Exception) { validated = false; return validated; } }