Пример #1
0
        public static ControlConstructScheme CreateControlConstructScheme(XElement controlConstructSchemeElem, StudyUnit studyUnit)
        {
            string id = (string)controlConstructSchemeElem.Attribute(ATTR_ID);
            if (id == null)
            {
                return null;
            }
            ControlConstructScheme controlConstructSchemeModel = new ControlConstructScheme();
            controlConstructSchemeModel.Title = (string)controlConstructSchemeElem.Element(d + TAG_CONTROL_CONSTRUCT_SCHEME_NAME);
            IEnumerable<XElement> questionConstructElems = controlConstructSchemeElem.Elements(d + TAG_QUESTION_CONSTRUCT);
            foreach (XElement questionConstructElem in questionConstructElems)
            {
                string questionConstructId = (string)questionConstructElem.Attribute(ATTR_ID);
                if (questionConstructId == null)
                {
                    continue;
                }
                string questionId = ReadReferenceID(questionConstructElem, d + TAG_QUESTION_REFERENCE);
                if (questionId == null)
                {
                    continue;
                }
                string no = (string)questionConstructElem.Element(r + TAG_LABEL);
                if (no == null)
                {
                    continue;
                }
                if (studyUnit.FindQuestion(questionId) != null)
                {
                    QuestionConstruct questionConstruct = new QuestionConstruct();
                    questionConstruct.Id = questionConstructId;
                    questionConstruct.No = no;
                    questionConstruct.QuestionId = questionId;
                    controlConstructSchemeModel.QuestionConstructs.Add(questionConstruct);

                }
                else if (studyUnit.FindQuestionGroup(questionId) != null)
                {
                    QuestionGroupConstruct questionGroupConstruct = new QuestionGroupConstruct();
                    questionGroupConstruct.Id = questionConstructId;
                    questionGroupConstruct.No = no;
                    questionGroupConstruct.QuestionGroupId = questionId;
                    controlConstructSchemeModel.QuestionGroupConstructs.Add(questionGroupConstruct);
                }

            }

            IEnumerable<XElement> statementItemElems = controlConstructSchemeElem.Elements(d + TAG_STATEMENT_ITEM);
            foreach (XElement statementItemElem in statementItemElems)
            {
                string statementId = (string)statementItemElem.Attribute(ATTR_ID);
                if (statementId == null)
                {
                    continue;
                }
                string no = (string)statementItemElem.Attribute(r + TAG_LABEL);
                if (no == null)
                {
                    continue;
                }
                Statement statement = new Statement();
                statement.Id = statementId;
                statement.No = no;
                XElement textElem = statementItemElem.Descendants(d + TAG_TEXT).FirstOrDefault();
                if (textElem != null)
                {
                    statement.Text = textElem.Value;
                }
                controlConstructSchemeModel.Statements.Add(statement);
            }

            IEnumerable<XElement> ifThenElseElems = controlConstructSchemeElem.Elements(d + TAG_IF_THEN_ELSE);
            foreach (XElement ifThenElseElem in ifThenElseElems)
            {
                string ifThenElseId = (string)ifThenElseElem.Attribute(ATTR_ID);
                if (ifThenElseId == null)
                {
                    continue;
                }
                XElement ifConditionElem = ifThenElseElem.Element(d + TAG_IF_CONDITION);
                if (ifConditionElem == null)
                {
                    continue;
                }
                string thenConstructId = ReadReferenceID(ifThenElseElem, d + TAG_THEN_CONSTRUCT_REFERENCE);
                if (thenConstructId == null)
                {
                    continue;
                }

                IfThenElse ifThenElse = new IfThenElse();
                ifThenElse.Id = ifThenElseId;
                ifThenElse.No = ControlConstructScheme.IFTHENELSE_NO;
                ifThenElse.IfCondition.Code = (string)ifConditionElem.Element(r + TAG_CODE);
                ifThenElse.IfCondition.QuestionId = ReadReferenceID(ifConditionElem, r + TAG_SOURCE_QUESTION_REFERENCE);
                ifThenElse.ThenConstructId = thenConstructId;
                controlConstructSchemeModel.IfThenElses.Add(ifThenElse);

                IEnumerable<XElement> elseIfElems = ifThenElseElem.Elements(d + TAG_ELSE_IF);
                foreach (XElement elseIfElem in elseIfElems)
                {
                    XElement ifConditionElem2 = elseIfElem.Element(d + TAG_IF_CONDITION);
                    if (ifConditionElem2 == null)
                    {
                        continue;
                    }
                    string thenConstructId2 = ReadReferenceID(elseIfElem, d + TAG_THEN_CONSTRUCT_REFERENCE);
                    if (thenConstructId2 == null)
                    {
                        continue;
                    }
                    ElseIf elseIf = new ElseIf();
                    elseIf.IfCondition.Code = (string)ifConditionElem2.Element(r + TAG_CODE);
                    elseIf.IfCondition.QuestionId = ReadReferenceID(ifConditionElem2, r + TAG_SOURCE_QUESTION_REFERENCE);
                    elseIf.ThenConstructId = thenConstructId2;
                    ifThenElse.ElseIfs.Add(elseIf);
                }
            }

            XElement sequenceElem = controlConstructSchemeElem.Element(d + TAG_SEQUENCE);
            if (sequenceElem != null)
            {
                controlConstructSchemeModel.Sequence.Id = (string)sequenceElem.Attribute(ATTR_ID);
                IEnumerable<XElement> controlConstructReferenceElems = sequenceElem.Elements(d + TAG_CONTROL_CONSTRUCT_REFERENCE);
                foreach (XElement controlConstructReferenceElem in controlConstructReferenceElems)
                {
                    string controlConstructId = (string)controlConstructReferenceElem.Element(r + TAG_ID);
                    if (controlConstructId != null)
                    {
                        controlConstructSchemeModel.Sequence.ControlConstructIds.Add(controlConstructId);
                    }
                }
            }
            return controlConstructSchemeModel;
        }
Пример #2
0
 private static ElseIf CreateElseIf(BranchVM branch)
 {
     ElseIf elseIf = new ElseIf();
     elseIf.IfCondition = CreateIfCondition(branch.ValidCondGroups);
     elseIf.ThenConstructId = branch.ThenConstruct.Id;
     return elseIf;
 }