Пример #1
0
        public static bool AddUpdateQuestion(string qid, string responsevalue, string responsetext, HttpSessionStateBase Session)
        {
            if (string.IsNullOrEmpty(responsetext))
            {
                responsetext = responsevalue;
            }
            List <QuestVal> QuestionValues = (List <QuestVal>)Session["QuestionResponses"];

            int foundindex   = -1;
            int currentcount = 0;

            if (QuestionValues != null)
            {
                foreach (QuestVal qresp in QuestionValues)
                {
                    if (qid == qresp.QuestionID)
                    {
                        foundindex = currentcount;
                        break;
                    }
                    currentcount++;
                }
            }
            else
            {
                QuestionValues = new List <QuestVal>();
            }
            if (foundindex >= 0)
            {
                QuestVal QVM = QuestionValues[foundindex];
                QVM.Response        = responsevalue;
                QVM.DisplayResponse = responsetext;
                QuestionValues.RemoveAt(foundindex);
                QuestionValues.Add(QVM);
                Session["QuestionResponses"] = QuestionValues;

                return(true);
            }

            try
            {
                ScreenViewer.API.Elements.QuestionController QC = new API.Elements.QuestionController();
                var actionResult             = QC.GetScriptQuestion(System.Convert.ToDecimal(qid));
                var response                 = actionResult as OkNegotiatedContentResult <Data.ScriptQuestion>;
                Data.ScriptQuestion SQ       = response.Content;
                QuestVal            newquest = new QuestVal();
                newquest.QuestionID      = SQ.ScriptQuestionID.ToString();
                newquest.QuestionText    = SQ.QuestionText;
                newquest.QuestKeyCodes   = SQ.KeyCodes;
                newquest.Response        = responsevalue;
                newquest.DisplayResponse = responsetext;
                QuestionValues.Add(newquest);
                Session["QuestionResponses"] = QuestionValues;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public ActionResult Grid_Create([DataSourceRequest] DataSourceRequest request, string id)
        {
            ScreenViewer.API.Elements.QuestionController QC = new API.Elements.QuestionController();
            var actionResult = QC.GetScriptQuestion(Convert.ToDecimal(id));

            ViewBag.OID = id.ToString();

            var response = actionResult as OkNegotiatedContentResult <Data.ScriptQuestion>;

            //Assert.IsNotNull(response);
            Data.ScriptQuestion theQuestion = response.Content;


            DataTable dt = SPutilities.GeneratePickDataCollection(theQuestion.DataObjectField, theQuestion.DOValueColumn, theQuestion.DODisplayColumns, HttpContext.Session);

            return(Json(dt.ToDataSourceResult(request)));
        }
        private List <SelectListItem> CreateLookupList(Data.ScriptQuestion theQuestion, HttpSessionStateBase theSession)
        {
            List <SelectListItem> lookupList = new List <SelectListItem>();

            ScreenViewer.API.Elements.QuestionController QC = new API.Elements.QuestionController();
            var actionResult = QC.GetScriptQuestionLookup(theQuestion.ScriptLookupID.Value);

            var response = actionResult as OkNegotiatedContentResult <Data.ScriptLookup>;

            foreach (var item in response.Content.ScriptLookupDetails)
            {
                lookupList.Add(new SelectListItem()
                {
                    Text = item.LookupText, Value = item.LookupValue
                });
            }

            return(lookupList);
        }
        //public ActionResult Display(decimal ID)
        //{
        //    ViewBag.QuestionID = ID;

        //    var pview = RenderQuestion(ID);
        //    ViewBag.PartialView = pview;
        //    //return RedirectToAction(RenderQuestion(ID));
        //    return RedirectToAction("RenderQuestion", new { ID = ID });

        //    //return View("_Question");

        //}
        //public ActionResult Display(decimal ID)
        //{
        //    return Display(ID, "false");
        //}
        //public ActionResult Display(decimal ID,bool criticalelement)
        //{
        //    ViewBag.QuestionID = ID;
        //    ViewBag.DisplayLabel = true;
        //    ScreenViewer.API.Elements.QuestionController QC = new API.Elements.QuestionController();
        //    var actionResult = QC.GetScriptQuestion(ID);



        //    var response = actionResult as OkNegotiatedContentResult<Data.ScriptQuestion>;
        //    //Assert.IsNotNull(response);
        //    Data.ScriptQuestion theQuestion = response.Content;
        //    ViewBag.QuestionDisplay = SPutilities.ReplaceObjectsandQuestions(HttpContext.Session, theQuestion.QuestionText,true);
        //    ViewBag.QuestionID = theQuestion.ScriptQuestionID;
        //    ViewBag.ControlName = "SPQuestion_" + theQuestion.ScriptQuestionID;
        //    if (criticalelement)
        //    {
        //        ViewBag.ControlName += "_C";
        //    }
        //    string cresp = SessionControl.SessionManager.GetQuestionResponse(ID.ToString(), HttpContext.Session);

        //    ViewBag.ReturnType = theQuestion.ResponseType;
        //    ViewBag.AnswerRequired = theQuestion.AnswerRequired.Value ? "required" : string.Empty;

        //    switch (theQuestion.QuestionType)
        //    {
        //        case FREE_TEXT:
        //            ViewBag.CurrentResponse = cresp;
        //            ViewBag.ValidatorRegex = null;
        //            if (theQuestion.ScriptValidatorID != null && theQuestion.ScriptValidatorID != 0)
        //            {
        //                var result = QC.GetScriptTextValidator(theQuestion.ScriptValidatorID.Value);
        //                var ValidatorResponse = result as OkNegotiatedContentResult<Data.ScriptValidator>;
        //                Data.ScriptValidator scriptTextValidator = ValidatorResponse.Content;
        //                ViewBag.ValidatorRegex = scriptTextValidator.ValidatorRegex;
        //                ViewBag.ValidatorDesc = scriptTextValidator.ValidatorDesc;
        //            }
        //            switch (theQuestion.ResponseType)
        //            {
        //                case "Date":
        //                case "DateTime":
        //                case "Time":
        //                    return PartialView("_DateTimeQuestion");
        //                 case "Number":

        //                    if (theQuestion.MinimumValue != null)
        //                    {
        //                        ViewBag.MinValue = theQuestion.MinimumValue;
        //                    }
        //                    if (theQuestion.MaximumValue != null)
        //                    {

        //                       ViewBag.MaxValue = theQuestion.MaximumValue;
        //                    }
        //                    return PartialView("_NumericQuestion");
        //                case "String":
        //                    ViewBag.MaxLength = theQuestion.MaxLength;
        //                    return PartialView("_TextQuestion");
        //            }
        //            break;
        //        case CONFIRM:
        //           ViewBag.CurrentResponse = cresp;
        //           ViewBag.Checked = cresp == "True" ? "Checked" : "";
        //            return PartialView("_ConfirmQuestion");
        //        case YES_NO:
        //            ViewBag.CurrentResponse = cresp;
        //            ViewBag.YesCheck = cresp == "Yes" ? "Checked" : "";
        //            ViewBag.NoCheck = cresp == "No" ? "Checked" : "";

        //            return PartialView("_YesNoQuestion");
        //        case PICK_ONE_ALT:
        //        case PICK_ONE:
        //            ViewBag.CurrentResponse = cresp == null ? null :cresp;
        //            if (!string.IsNullOrEmpty(theQuestion.DataObjectField))
        //            {


        //            }
        //            else
        //            {

        //                List<SelectListItem> pickList = CreateDOList(theQuestion.Choices);
        //                ViewBag.PickList = pickList;
        //                ViewBag.PickLength = pickList.Count;
        //                ViewBag.ControlID = "listquestion_" + theQuestion.ScriptQuestionID.ToString();

        //                return PartialView("_PickOneQuestion");
        //            }
        //            break;
        //        case PICK_MANY:
        //            ViewBag.CurrentResponse = cresp == null ? null : Regex.Split(cresp, ",").ToList();
        //            if (!string.IsNullOrEmpty(theQuestion.DataObjectField))
        //            {


        //            }
        //            else
        //            {
        //                List<SelectListItem> pickList = CreateDOList(theQuestion.Choices);
        //                ViewBag.PickList = pickList;
        //                ViewBag.PickLength = pickList.Count;
        //                ViewBag.ID = theQuestion.ScriptQuestionID.ToString();
        //                ViewBag.ControlID = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
        //                return PartialView("_PickManyQuestion");

        //            }
        //            break;
        //        default:
        //            break;


        //    }
        //    return Content("Blah Blah");
        //}
        public ScreenViewer.Models.Elements.QuestionLayout RenderQuestionParts(decimal ID, bool criticalelement, ControllerContext ContCont)
        {
            ScreenViewer.Models.Elements.QuestionLayout questionLayout = new Models.Elements.QuestionLayout();

            ViewBag.QuestionID   = ID;
            ViewBag.DisplayLabel = false;
            ScreenViewer.API.Elements.QuestionController QC = new API.Elements.QuestionController();
            var actionResult = QC.GetScriptQuestion(ID);



            var response = actionResult as OkNegotiatedContentResult <Data.ScriptQuestion>;

            //Assert.IsNotNull(response);
            Data.ScriptQuestion theQuestion = response.Content;
            ViewBag.QuestionDisplay = SPutilities.ReplaceObjectsandQuestions(ContCont.HttpContext.Session, theQuestion.QuestionText, true);
            ViewBag.QuestionID      = theQuestion.ScriptQuestionID;
            ViewBag.ControlName     = "SPQuestion_" + theQuestion.ScriptQuestionID;
            if (criticalelement)
            {
                ViewBag.ControlName += "_C";
            }
            string cresp = SessionControl.SessionManager.GetQuestionResponse(ID.ToString(), ContCont.HttpContext.Session);

            if (string.IsNullOrEmpty(cresp) && !string.IsNullOrEmpty(theQuestion.KeyCodes))
            {
                if (theQuestion.KeyCodes.StartsWith("DO."))
                {
                    string[] holdKeyCode = theQuestion.KeyCodes.Split('.');
                    string   dataObject  = holdKeyCode[1];
                    ScreenViewer.Models.DataObjects ScriptDataObject = (ScreenViewer.Models.DataObjects)SessionControl.SessionManager.GetDataObject(ContCont.HttpContext.Session, dataObject);

                    if (ScriptDataObject != null)
                    {
                        foreach (var detail in ScriptDataObject.Details)
                        {
                            if (detail.DetailName == holdKeyCode[2] && detail.DetailValue != null)
                            {
                                cresp = detail.DetailValue.ToString();
                            }
                        }
                    }
                }
            }

            ViewBag.ReturnType = theQuestion.ResponseType;

            try
            {
                ViewBag.AnswerRequired = ((bool)theQuestion.AnswerRequired) ? "required" : string.Empty;
            }
            catch
            {
                ViewBag.AnswerRequired = string.Empty;
            }
            questionLayout.QuestionLabelText = ViewBag.QuestionDisplay;//theQuestion.QuestionText;


            switch (theQuestion.QuestionType)
            {
            case FREE_TEXT:
                ViewBag.Type            = "text";
                ViewBag.CurrentResponse = cresp;
                ViewBag.ValidatorRegex  = null;

                if (theQuestion.QuestionDesc.Substring(theQuestion.QuestionDesc.Length - 1) == "$")
                {
                    ViewBag.Type = "password";
                }

                if (theQuestion.ScriptValidatorID != null && theQuestion.ScriptValidatorID != 0)
                {
                    var result            = QC.GetScriptTextValidator(theQuestion.ScriptValidatorID.Value);
                    var ValidatorResponse = result as OkNegotiatedContentResult <Data.ScriptValidator>;
                    Data.ScriptValidator scriptTextValidator = ValidatorResponse.Content;
                    ViewBag.ValidatorRegex = scriptTextValidator.ValidatorRegex;
                    ViewBag.ValidatorDesc  = scriptTextValidator.ValidatorDesc;
                }

                switch (theQuestion.ResponseType)
                {
                case "Date":
                case "DateTime":
                case "Time":
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_DateTimeQuestion.cshtml", theQuestion, ViewData);
                    break;

                case "Number":

                    if (theQuestion.MinimumValue != null)
                    {
                        ViewBag.MinValue = theQuestion.MinimumValue;
                    }
                    if (theQuestion.MaximumValue != null)
                    {
                        ViewBag.MaxValue = theQuestion.MaximumValue;
                    }
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_NumericQuestion.cshtml", theQuestion, ViewData);
                    break;

                case "String":
                    ViewBag.MaxLength = theQuestion.MaxLength;

                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_TextQuestion.cshtml", theQuestion, ViewData);
                    break;
                }
                break;

            case CONFIRM:
                ViewBag.CurrentResponse     = cresp;
                ViewBag.Checked             = cresp == "True" ? "Checked" : "";
                questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_ConfirmQuestion.cshtml", theQuestion, ViewData);
                break;


            case YES_NO:
                ViewBag.CurrentResponse = cresp;
                ViewBag.YesCheck        = cresp == "Yes" ? "Checked" : "";
                ViewBag.NoCheck         = cresp == "No" ? "Checked" : "";

                questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_YesNoQuestion.cshtml", theQuestion, ViewData);
                break;

            case PICK_ONE_ALT:
            case PICK_ONE:

                ViewBag.CurrentResponse = cresp == null ? null : cresp;
                ViewBag.QuestionType    = theQuestion.QuestionType;
                ViewBag.MaxLength       = theQuestion.MaxLength;
                if (!string.IsNullOrEmpty(theQuestion.DataObjectField))
                {
                    List <string> displayItems = Regex.Split(theQuestion.DODisplayColumns, "~").ToList();
                    if (displayItems.Count > 1)
                    {
                        DataTable listtable = CreateObjectSelectList(theQuestion, ContCont.HttpContext.Session);
                        ViewBag.ValueColumn         = theQuestion.DOValueColumn;
                        ViewBag.DataTable           = listtable;
                        ViewBag.ControlID           = "gridquestion_" + theQuestion.ScriptQuestionID.ToString();
                        ViewBag.OID                 = theQuestion.ScriptQuestionID.ToString();
                        questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_ObjectSelector.cshtml", theQuestion, ViewData);
                    }
                    else
                    {
                        List <SelectListItem> pickList = CreateDobList(theQuestion, ContCont.HttpContext.Session);
                        ViewBag.PickList            = pickList;
                        ViewBag.PickLength          = pickList.Count;
                        ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                        questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickOneQuestion.cshtml", theQuestion, ViewData);
                        break;
                    }
                }
                else if (theQuestion.ScriptLookupID != null && theQuestion.ScriptLookupID.Value != 0.0M)
                {
                    List <SelectListItem> pickList = CreateLookupList(theQuestion, ContCont.HttpContext.Session);
                    ViewBag.PickList            = pickList;
                    ViewBag.PickLength          = pickList.Count;
                    ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickOneQuestion.cshtml", theQuestion, ViewData);
                    break;
                }
                else
                {
                    List <SelectListItem> pickList = CreateDOList(theQuestion.Choices);
                    ViewBag.PickList            = pickList;
                    ViewBag.PickLength          = pickList.Count;
                    ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickOneQuestion.cshtml", theQuestion, ViewData);
                    break;
                }
                break;

            case PICK_MANY:
                ViewBag.CurrentResponse = cresp == null ? null : Regex.Split(cresp, ",").ToList();
                ViewBag.CurrentResponse = cresp == null ? null : Regex.Split(cresp, "~").ToList();
                ViewBag.MaxLength       = theQuestion.MaxLength;

                //string pmResponse = string.Empty;
                //List<string> holdList = cresp == null ? null : Regex.Split(cresp, ",").ToList();
                //if (holdList != null && holdList.Count > 0)
                //{
                //    foreach (var item in holdList)
                //    {
                //        pmResponse = string.Format("{0}'{1}',", pmResponse, item);
                //    }

                //    pmResponse = pmResponse.TrimEnd(',');
                //    ViewBag.CurrentResponse = System.Web.HttpUtility.JavaScriptStringEncode(pmResponse);
                //}
                //else
                //    ViewBag.CurrentResponse = pmResponse;

                List <string> displayItems2 = null;
                if (theQuestion.DODisplayColumns != null)
                {
                    displayItems2 = Regex.Split(theQuestion.DODisplayColumns, "~").ToList();
                }

                if (!string.IsNullOrEmpty(theQuestion.DataObjectField))
                {
                    if (displayItems2.Count > 1)
                    {
                        DataTable listtable = CreateObjectSelectList(theQuestion, ContCont.HttpContext.Session);
                        ViewBag.DataTable           = listtable;
                        ViewBag.ControlID           = "gridquestion_" + theQuestion.ScriptQuestionID.ToString();
                        questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_ObjectSelector.cshtml", theQuestion, ViewData);
                    }
                    else
                    {
                        List <SelectListItem> pickList = CreateDobList(theQuestion, ContCont.HttpContext.Session);
                        ViewBag.PickList            = pickList;
                        ViewBag.PickLength          = pickList.Count;
                        ViewBag.ID                  = theQuestion.ScriptQuestionID.ToString();
                        ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                        questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickManyQuestion.cshtml", theQuestion, ViewData);
                    }
                }
                else if (theQuestion.ScriptLookupID != null && theQuestion.ScriptLookupID.Value != 0.0M)
                {
                    List <SelectListItem> pickList = CreateLookupList(theQuestion, ContCont.HttpContext.Session);
                    ViewBag.PickList            = pickList;
                    ViewBag.PickLength          = pickList.Count;
                    ViewBag.ID                  = theQuestion.ScriptQuestionID.ToString();
                    ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickManyQuestion.cshtml", theQuestion, ViewData);
                }
                else
                {
                    List <SelectListItem> pickList = CreateDOList(theQuestion.Choices);
                    ViewBag.PickList            = pickList;
                    ViewBag.PickLength          = pickList.Count;
                    ViewBag.ID                  = theQuestion.ScriptQuestionID.ToString();
                    ViewBag.ControlID           = "listquestion_" + theQuestion.ScriptQuestionID.ToString();
                    questionLayout.QuestionHTML = RenderHelper.RenderViewToString(ContCont, "~/Views/Question/_PickManyQuestion.cshtml", theQuestion, ViewData);
                    break;
                }
                break;

            default:
                break;
            }
            return(questionLayout);
        }