예제 #1
0
        /// <summary>
        /// Gets (creates) template xml by version ckey
        /// </summary>
        /// <param name="templateVersion">template version data</param>
        /// <param name="templateItems">template item data</param>
        /// <param name="templateProcedures">template procedure data</param>
        /// <returns>template for version ckey</returns>
        private template BuildTemplateObjectTree(DataTable templateVersion, DataTable templateItems, DataTable templateProcedures)
        {
            template aTemplate = null;
            Dictionary <Decimal, object> objectList = new Dictionary <Decimal, object>();

            if (templateVersion.Rows.Count == 0)
            {
                return(null);
            }
            aTemplate = MapTemplate(templateVersion.Rows[0]);
            // unmapped procedure until clarifications are completed
            //if (templateProcedures != null)
            //{
            //    foreach (DataRow dr in templateProcedures.Rows)
            //    {
            //        aTemplate.templateheader.procedures = aTemplate.templateheader.procedures.AddItem(MapProcedure(dr));
            //    }
            //}
            ////if (!objectList.ContainsKey(aTemplate.templateid))
            objectList.Add(aTemplate.templateid, aTemplate);
            if (templateItems.Rows.Count == 0)
            {
                return(aTemplate);
            }

            foreach (DataRow dr in templateItems.Rows)
            {
                object   o;
                ItemType?rowTypePrevious = null;
                var      rowType         = ItemMapper.MapItemType(Convert.ToInt32(dr["ItemTypeKey"]));
                // fixed to make all notes under question fixed list notes, rlm: in case TE modeler uses a Note instead of ComboNote
                // this is required to fix issues with ordering of all items under a question such as the WilmsTmrResx.xml template
                if (rowType == ItemType.NOTE && Convert.ToInt32(dr["IsParentQuestion"]) == 1)
                {
                    //if (rowTypePrevious==ItemType.ANSWER || rowTypePrevious == ItemType.ANSWERFILLIN || rowTypePrevious == ItemType.FIXEDLISTNOTE || rowTypePrevious==null)
                    rowType = ItemType.FIXEDLISTNOTE;
                }
                switch (rowType)
                {
                case ItemType.HEADER:
                    headergroup h = MapHeaderGroup(dr);
                    //// if (!objectList.ContainsKey(h.headergroupid))
                    objectList.Add(h.headergroupid, h);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddHeaderToItem(o, h);
                    }
                    break;

                case ItemType.NOTE:
                    note n = MapNote(dr);
                    //rlm: If the note is not already in the objectList, then add it
                    //if (!objectList.ContainsKey(n.noteid))
                    objectList.Add(n.noteid, n);
                    if (n.noteid == 36816.1000043M)
                    {
                    }
                    //rlm: If the Note's Parent item is already in the objectList, then connect the note to its Parent item
                    //rlm: If the Parent item is not present, then the note is not attached to the Parent
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddNoteToItem(o, n);
                    }
                    break;

                case ItemType.FIXEDLISTNOTE:
                    fixedlistnote note = MapFixedListNote(dr);
                    //if (!objectList.ContainsKey(note.noteid))
                    objectList.Add(note.noteid, note);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddFixedListNoteToItem(o, note);
                    }
                    break;

                case ItemType.QUESTIONSINGLE:
                    question q = MapQuestion(dr, ItemType.QUESTIONSINGLE);
                    //if (!objectList.ContainsKey(q.questionid))
                    objectList.Add(q.questionid, q);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddQuestionToItem(o, q);
                    }
                    break;

                case ItemType.QUESTIONMULTIPLE:
                    question q2 = MapQuestion(dr, ItemType.QUESTIONMULTIPLE);
                    //if (!objectList.ContainsKey(q2.questionid))
                    objectList.Add(q2.questionid, q2);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddQuestionToItem(o, q2);
                    }
                    break;

                case ItemType.QUESTIONFILLIN:
                    question q3 = MapQuestion(dr, ItemType.QUESTIONFILLIN);
                    //if (!objectList.ContainsKey(q3.questionid))
                    objectList.Add(q3.questionid, q3);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddQuestionToItem(o, q3);
                    }
                    break;

                case ItemType.ANSWER:
                    fixedlistitem item = MapAnswer(dr);
                    //if (!objectList.ContainsKey(item.answerid))
                    objectList.Add(item.answerid, item);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddAnswerToItem(o, item);
                    }
                    break;

                case ItemType.ANSWERFILLIN:
                    fixedlistfillinanswer a = MapAnswerFillin(dr);
                    //if (!objectList.ContainsKey(a.answerid))
                    objectList.Add(a.answerid, a);
                    if (objectList.ContainsKey(Convert.ToDecimal(dr["ParentItemCkey"])))
                    {
                        o = objectList[Convert.ToDecimal(dr["ParentItemCkey"])];
                        _srTmpTreeBuilder.AddAnswerToItem(o, a);
                    }
                    break;
                }
                //rowTypePrevious = rowType;
            }
            return(aTemplate);
        }