Пример #1
0
        public virtual void attachChoice(QuestionDef q)
        {
            if (q.DynamicChoices != null)
            {
                //can't attach dynamic choices because they aren't guaranteed to exist yet
                return;
            }

            SelectChoice choice = null;

            if (index != -1 && index < q.NumChoices)
            {
                choice = q.getChoice(index);
            }
            else if (xmlValue != null && xmlValue.Length > 0)
            {
                choice = q.getChoiceForValue(xmlValue);
            }

            if (choice != null)
            {
                attachChoice(choice);
            }
            else
            {
                throw new XPathTypeMismatchException("value " + xmlValue + " could not be loaded into question " + q.TextID + ".  Check to see if value " + xmlValue + " is a valid option for question " + q.TextID + ".");
            }
        }
Пример #2
0
        private static Selection getSelection(System.String choiceValue, QuestionDef q)
        {
            Selection s;

            if (q == null || q.DynamicChoices != null)
            {
                s = new Selection(choiceValue);
            }
            else
            {
                SelectChoice choice = q.getChoiceForValue(choiceValue);
                s = (choice != null?choice.selection():null);
            }

            return(s);
        }
Пример #3
0
        /// <summary> Attempts to save the answer at the specified FormIndex into the
        /// datamodel.
        ///
        /// </summary>
        /// <param name="index">
        /// </param>
        /// <param name="data">
        /// </param>
        /// <returns> OK if save was successful, error if a constraint was violated.
        /// </returns>
        public virtual int answerQuestion(FormIndex index, IAnswerData data)
        {
            QuestionDef q = model.getQuestionPrompt(index).Question;

            if (model.getEvent(index) != FormEntryController.EVENT_QUESTION)
            {
                throw new System.SystemException("Non-Question object at the form index.");
            }
            TreeElement element         = model.getTreeElement(index);
            bool        complexQuestion = q.Complex;

            bool hasConstraints = false;

            if (element.Required && data == null)
            {
                return(ANSWER_REQUIRED_BUT_EMPTY);
            }
            else if (!complexQuestion && !model.Form.evaluateConstraint(index.Reference, data))
            {
                return(ANSWER_CONSTRAINT_VIOLATED);
            }
            else if (!complexQuestion)
            {
                commitAnswer(element, index, data);
                return(ANSWER_OK);
            }
            else if (complexQuestion && hasConstraints)
            {
                //TODO: itemsets: don't currently evaluate constraints for itemset/copy -- haven't figured out how handle it yet
                throw new System.SystemException("Itemsets do not currently evaluate constraints. Your constraint will not work, please remove it before proceeding.");
            }
            else
            {
                try
                {
                    model.Form.copyItemsetAnswer(q, element, data);
                }
                catch (InvalidReferenceException ire)
                {
                    SupportClass.WriteStackTrace(ire, Console.Error);
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    throw new System.SystemException("Invalid reference while copying itemset answer: " + ire.Message);
                }
                return(ANSWER_OK);
            }
        }
Пример #4
0
        private void  InitBlock()
        {
            return(mTreeElement.getBindAttributes());

            QuestionDef q = Question;

            ItemsetBinding itemset = q.DynamicChoices;

            if (itemset != null)
            {
                if (!dynamicChoicesPopulated)
                {
                    form.populateDynamicChoices(itemset, mTreeElement.Ref);
                    dynamicChoicesPopulated = true;
                }
                return(itemset.getChoices());
            }
            else
            {
                //static choices
                return(q.getChoices());
            }
        }
Пример #5
0
        public static IAnswerData getAnswerData(System.String text, int dataType, QuestionDef q)
        {
            System.String trimmedText = text.Trim();
            if (trimmedText.Length == 0)
            {
                trimmedText = null;
            }

            switch (dataType)
            {
            case Constants.DATATYPE_NULL:
            case Constants.DATATYPE_UNSUPPORTED:
            case Constants.DATATYPE_TEXT:
            case Constants.DATATYPE_BARCODE:
            case Constants.DATATYPE_BINARY:

                return(new StringData(text));


            case Constants.DATATYPE_INTEGER:

                try
                {
                    return(trimmedText == null?null:new IntegerData(System.Int32.Parse(trimmedText)));
                }
                catch (System.FormatException nfe)
                {
                    return(null);
                }
                goto case Constants.DATATYPE_LONG;


            case Constants.DATATYPE_LONG:

                try
                {
                    return(trimmedText == null?null:new LongData(System.Int64.Parse(trimmedText)));
                }
                catch (System.FormatException nfe)
                {
                    return(null);
                }
                goto case Constants.DATATYPE_DECIMAL;


            case Constants.DATATYPE_DECIMAL:

                try
                {
                    return(trimmedText == null?null:new DecimalData(System.Double.Parse(trimmedText)));
                }
                catch (System.FormatException nfe)
                {
                    return(null);
                }
                goto case Constants.DATATYPE_CHOICE;


            case Constants.DATATYPE_CHOICE:

                System.Collections.ArrayList selections = getSelections(text, q);
                return(selections.Count == 0?null:new SelectOneData((Selection)selections[0]));


            case Constants.DATATYPE_CHOICE_LIST:

                return(new SelectMultiData(getSelections(text, q)));


            case Constants.DATATYPE_DATE_TIME:

                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                System.DateTime dt = (trimmedText == null?null:DateUtils.parseDateTime(trimmedText));
                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                return(dt == null?null:new DateTimeData(ref dt));


            case Constants.DATATYPE_DATE:

                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                System.DateTime d = (trimmedText == null?null:DateUtils.parseDate(trimmedText));
                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                return(d == null?null:new DateData(ref d));


            case Constants.DATATYPE_TIME:

                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                System.DateTime t = (trimmedText == null?null:DateUtils.parseTime(trimmedText));
                //UPGRADE_TODO: The 'System.DateTime' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                return(t == null?null:new TimeData(ref t));


            case Constants.DATATYPE_BOOLEAN:

                if (trimmedText == null)
                {
                    return(null);
                }
                else
                {
                    if (trimmedText.Equals("1"))
                    {
                        return(new BooleanData(true));
                    }
                    if (trimmedText.Equals("0"))
                    {
                        return(new BooleanData(false));
                    }
                    return(trimmedText.Equals("t")?new BooleanData(true):new BooleanData(false));
                }
                goto case Constants.DATATYPE_GEOPOINT;


            case Constants.DATATYPE_GEOPOINT:
                if (trimmedText == null)
                {
                    return(new GeoPointData());
                }

                try
                {
                    UncastData uncast = new UncastData(trimmedText);
                    // silly...
                    GeoPointData gp = new GeoPointData();
                    return(gp.cast(uncast));
                }
                catch (System.Exception e)
                {
                    return(null);
                }
                goto case Constants.DATATYPE_GEOSHAPE;


            case Constants.DATATYPE_GEOSHAPE:
                if (trimmedText == null)
                {
                    return(new GeoShapeData());
                }

                try
                {
                    UncastData uncast = new UncastData(trimmedText);
                    // silly...
                    GeoShapeData gs = new GeoShapeData();
                    return(gs.cast(uncast));
                }
                catch (System.Exception e)
                {
                    return(null);
                }
                goto case Constants.DATATYPE_GEOTRACE;


            case Constants.DATATYPE_GEOTRACE:
                if (trimmedText == null)
                {
                    return(new GeoTraceData());
                }

                try
                {
                    UncastData uncast = new UncastData(trimmedText);
                    // silly...
                    GeoTraceData gl = new GeoTraceData();
                    return(gl.cast(uncast));
                }
                catch (System.Exception e)
                {
                    return(null);
                }
                goto default;


            default:
                return(new UncastData(trimmedText));
            }
        }
Пример #6
0
        private static System.Collections.ArrayList getSelections(System.String text, QuestionDef q)
        {
            System.Collections.ArrayList v = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            System.Collections.ArrayList choices = DateUtils.split(text, XFormAnswerDataSerializer.DELIMITER, true);
            for (int i = 0; i < choices.Count; i++)
            {
                Selection s = getSelection((System.String)choices[i], q);
                if (s != null)
                {
                    v.Add(s);
                }
            }

            return(v);
        }