Ejemplo n.º 1
0
    public static Survey createSurvey(ImportingElement element, int id, string flag)
    {
        GRASPEntities db = new GRASPEntities();

        Survey survey = new Survey();

        survey.name = element.refListName;
        survey.owner_id = id;

        db.Survey.Add(survey);
        db.SaveChanges();

        if (flag == "select1")
        {
            foreach (string label in element.select1Labels)
            {
                int size = FormFieldExport.getSurveyList(survey.id);
                SurveyElement se = createSurveyElement(label, size);
                createSurveyAssociation(survey.id, se.id);
            }
        }
        if (flag == "survey")
        {
            foreach (string label in element.surveyValues)
            {
                int size = FormFieldExport.getSurveyList(survey.id);
                SurveyElement se = createSurveyElement(label, size);
                createSurveyAssociation(survey.id, se.id);
            }
        }

        return survey;
    }
Ejemplo n.º 2
0
    public static FormField createFormField(ImportingElement element, int id)
    {
        GRASPEntities db = new GRASPEntities();

        var formField = new FormField();

        if(element.fieldType != FormFieldType.SEPARATOR)
        {
            if(!element.isRepItem)
            {
                element = cutIndexFromName(element);
            }
            formField.type = element.fieldType.ToString();
            formField.label = element.label;
            formField.name = element.name;
            formField.required = element.bindReference.required ? (byte)1 : (byte)0;
            formField.bindingsPolicy = element.bindingsPolicy;
            formField.constraintPolicy = element.constraintPolicy;
            formField.isReadOnly = element.bindReference.readOnly ? (byte)1 : (byte)0;

            if(element.calculated != null)
            {
                formField.calculated = 1;
                formField.formula = element.calculated;
            }
            else formField.calculated = 0;
        }
        else
        {
            formField.type = element.fieldType.ToString();
            formField.label = element.label;
            formField.name = element.name;
            formField.required = 0;
        }
        if((element.fieldType == FormFieldType.DROP_DOWN_LIST) || (element.fieldType == FormFieldType.RADIO_BUTTON))
        {
            Survey s = Survey.createSurvey(element, id, "select1");
            formField.survey_id = s.id;
        }
        if(element.fieldType == FormFieldType.REPEATABLES_BASIC)
        {
            formField.type = element.fieldType.ToString();
            formField.label = element.label;
            formField.name = element.name;
            formField.required = 0;
            foreach(ImportingElement reps in element.repElements)
            {
                createFormField(reps, id);
            }
            formField.numberOfRep = element.numberOfReps;
        }
        if(element.fieldType == FormFieldType.REPEATABLES)
        {
            formField.type = element.fieldType.ToString();
            formField.label = element.label;
            formField.name = element.name;
            formField.required = 0;
            foreach(ImportingElement reps in element.repElements)
            {
                createFormField(reps, id);
            }
            Survey s = Survey.createSurvey(element, id, "survey");
            formField.survey_id = s.id;
        }

        formField.pushed = 0;
        formField.form_id = id;
        formField.FFCreateDate = DateTime.Now;
        db.FormField.Add(formField);
        db.SaveChanges();

        return formField;
    }
Ejemplo n.º 3
0
 private static ImportingElement cutIndexFromName(ImportingElement element)
 {
     for(int i = element.name.Length - 1; i >= 0; i--)
     {
         if(element.name[i] == '_')
         {
             try
             {
                 element.positionIndex = Convert.ToInt32(element.name.Substring(i + 1));
             }
             catch(Exception ex)
             {
                 break;
             }
             element.name = element.name.Substring(0, i);
             break;
         }
     }
     return element;
 }
    private void generateFormFieldAndBindings(ImportingElement elem)
    {
        foreach (ImportingElement el in elem.elementsToBindings.Keys)
        {
            foreach (ImportingBindingContainer bc in elem.elementsToBindings[el])
            {
                FormField.createBinding(el.generatedFormField, bc);
            }
        }

        foreach (ImportConstraintContainer constCont in elem.constraints)
        {
            FormField.createConstraints(elem.generatedFormField, constCont);
        }
        if (elem.fieldType == FormFieldType.REPEATABLES || elem.fieldType == FormFieldType.REPEATABLES_BASIC)
        {
            foreach (ImportingElement rep in elem.repElements)
            {
                generateFormFieldAndBindings(rep);
            }

        }
    }
 private List<ImportingElement> discoverSeparators(List<ImportingElement> elements)
 {
     List<ImportingElement> ret = new List<ImportingElement>();
     int i = 0;
     foreach (ImportingElement el in elements)
     {
         if (el.positionIndex == i)
             ret.Add(el);
         else
         {
             ImportingElement closeGroupElem = new ImportingElement();
             closeGroupElem.fieldType = FormFieldType.SEPARATOR;
             closeGroupElem.type = "separator";
             closeGroupElem.name = "section" + i;
             closeGroupElem.positionIndex = i;
             ret.Add(closeGroupElem);
             ret.Add(el);
             i++;
         }
         i++;
     }
     return ret;
 }
 private void checkSurvey(XmlElement g, ImportingElement newRepElem, string groupRef)
 {
     XmlNodeList surveyElements = g.GetElementsByTagName("group");
     for (int i = 0; i < surveyElements.Count; i++)
     {
         XmlElement el = (XmlElement)surveyElements.Item(i);
         if (el.Attributes.GetNamedItem("appearance") != null)
         {
             if (el.Attributes.GetNamedItem("appearance").Value == "field-list")
             {
                 if (el.GetElementsByTagName("label").Item(0).FirstChild != null)
                     newRepElem.surveyValues.Add(el.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString());
             }
         }
     }
     //cycle in the first repetition
     checkFirstRepetition(surveyElements, newRepElem, groupRef);
 }
    /// <summary>
    /// repeatable group tied with a survey
    /// </summary>
    /// <param name="g"></param>
    /// <param name="importingElemList"></param>
    private void checkRepeatableSurvey(XmlElement g, List<ImportingElement> importingElemList)
    {
        ImportingElement newRepElem = new ImportingElement();
        string groupRef = "";
        newRepElem.isRepContainer = true;
        if (g.GetElementsByTagName("label").Item(0).FirstChild != null)
            newRepElem.label = g.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
        else newRepElem.label = "";
        if (g.Attributes.GetNamedItem("ref") != null)
        {
            groupRef = g.Attributes.GetNamedItem("ref").Value.ToString();
            newRepElem.reference = groupRef;
            newRepElem.name = groupRef;
        }
        if (g.Attributes.GetNamedItem("reflist") != null)
            newRepElem.refListName = g.Attributes.GetNamedItem("reflist").Value.ToString();

        //retrieves a list of survey elements examining the repetitions
        checkSurvey(g, newRepElem, groupRef);
        Debug.WriteLine("Element in repeatable section: " + newRepElem.repElements.Count);
        newRepElem.type = "repeatables";
        newRepElem.fieldType = FormFieldType.REPEATABLES;
        Debug.WriteLine(newRepElem.repElements.Count);
        importingElemList.Add(newRepElem);
    }
 private void checkRepeatableBasic(XmlElement g, List<ImportingElement> importingElemList, XmlDocument form)
 {
     ImportingElement newRepElem = new ImportingElement();
     newRepElem.isRepContainer = true;
     if (g.GetElementsByTagName("label").Item(0).FirstChild != null)
         newRepElem.label = g.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
     else newRepElem.label = "";
     XmlElement repeat = (XmlElement)g.GetElementsByTagName("repeat").Item(0);
     string groupRef = "";
     if (repeat.Attributes.GetNamedItem("nodeset") != null)
     {
         newRepElem.reference = repeat.Attributes.GetNamedItem("nodeset").Value.ToString();
     }
     if (repeat.Attributes.GetNamedItem("jr:count") != null)
     {
         String jrCount = repeat.Attributes.GetNamedItem("jr:count").Value.ToString();
         jrCount = cutData(jrCount);
         if (form.GetElementsByTagName(jrCount) != null)
             newRepElem.numberOfReps = Convert.ToInt32(form.GetElementsByTagName(jrCount).Item(0).FirstChild.Value.ToString().Trim());
     }
     if (g.Attributes.GetNamedItem("ref") != null)
     {
         groupRef = g.Attributes.GetNamedItem("ref").Value.ToString();
         newRepElem.reference = groupRef;
         newRepElem.name = newRepElem.cutReferenceName(newRepElem.reference);
     }
     XmlNodeList repElements = repeat.GetElementsByTagName("group").Item(0).ChildNodes;
     for (int i = 0; i < repElements.Count; i++)
     {
         if (repElements.Item(i).Name == "input")
         {
             XmlElement node = (XmlElement)repElements.Item(i);
             Debug.WriteLine("Found an input node");
             ImportingElement importingElem = checkAttributesRefInput(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             newRepElem.repElements.Add(importingElem);
         }
         if (repElements.Item(i).Name == "select")
         {
             XmlElement node = (XmlElement)repElements.Item(i);
             Debug.WriteLine("Found a select node");
             ImportingElement importingElem = checkAttributesRefSelect(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             newRepElem.repElements.Add(importingElem);
         }
         if (repElements.Item(i).Name == "select1")
         {
             XmlElement node = (XmlElement)repElements.Item(i);
             Debug.WriteLine("Found a select1 node");
             ImportingElement importingElem = checkAttributesRefSelect1(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             if (importingElem.typeAttribute != "currency")
                 newRepElem.repElements.Add(importingElem);
         }
     }
     newRepElem.type = "repeatables";
     newRepElem.fieldType = FormFieldType.REPEATABLES_BASIC;
     Debug.WriteLine(newRepElem.repElements.Count);
     importingElemList.Add(newRepElem);
 }
 private void checkFirstRepetition(XmlNodeList surveyElements, ImportingElement newRepElem, string groupRef)
 {
     XmlNodeList firstRep = surveyElements.Item(0).ChildNodes;
     for (int j = 0; j < firstRep.Count; j++)
     {
         if (firstRep.Item(j).Name == "input")
         {
             XmlElement node = (XmlElement)firstRep.Item(j);
             Debug.WriteLine("Found an input node");
             ImportingElement importingElem = checkAttributesRefInput(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             newRepElem.repElements.Add(importingElem);
         }
         if (firstRep.Item(j).Name == "select")
         {
             XmlElement node = (XmlElement)firstRep.Item(j);
             Debug.WriteLine("Found a select node");
             ImportingElement importingElem = checkAttributesRefSelect(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             newRepElem.repElements.Add(importingElem);
         }
         if (firstRep.Item(j).Name == "select1")
         {
             XmlElement node = (XmlElement)firstRep.Item(j);
             Debug.WriteLine("Found a select1 node");
             ImportingElement importingElem = checkAttributesRefSelect1(node);
             if (node.Attributes.GetNamedItem("ref") != null)
             {
                 importingElem.reference = groupRef + "/" + node.Attributes.GetNamedItem("ref").Value.ToString();
                 importingElem.generateName();
             }
             importingElem.isRepItem = true;
             importingElem.repContainer = newRepElem;
             if (importingElem.typeAttribute != "currency")
                 newRepElem.repElements.Add(importingElem);
         }
     }
 }
    private ImportingElement checkAttributesRefSelect1(XmlElement node)
    {
        ImportingElement importingElem = new ImportingElement();

        if (node.Attributes.GetNamedItem("appearance") != null)
            importingElem.select1Appearance = node.Attributes.GetNamedItem("appearance").Value.ToString();
        if (node.GetElementsByTagName("label").Item(0).FirstChild != null)
            importingElem.label = node.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
        else importingElem.label = "";
        if (node.Attributes.GetNamedItem("ref") != null)
        {
            importingElem.reference = node.Attributes.GetNamedItem("ref").Value.ToString();
            importingElem.generateName();
        }
        if (node.Attributes.GetNamedItem("reflist") != null)
            importingElem.refListName = node.Attributes.GetNamedItem("reflist").Value.ToString();

        XmlNodeList itemList = node.GetElementsByTagName("item");
        Debug.WriteLine("Found " + itemList.Count + " items in select1 node");
        for (int i = 0; i < itemList.Count; i++)
        {
            XmlElement item = (XmlElement)itemList.Item(i);
            string labelValue = "";
            string itemValue = "";

            labelValue = item.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
            itemValue = item.GetElementsByTagName("value").Item(0).FirstChild.Value.ToString();
            if (labelValue != "Select" && itemValue == "0")
                importingElem.select1Labels.Add(labelValue);
        }
        importingElem.type = "select1";
        if (node.Attributes.GetNamedItem("type") != null)
            importingElem.typeAttribute = node.Attributes.GetNamedItem("type").Value.ToString();

        return importingElem;
    }
    private ImportingElement checkAttributesRefSelect(XmlElement node)
    {
        ImportingElement importingElem = new ImportingElement();

        XmlNodeList items = node.GetElementsByTagName("item");
        XmlElement uniqueItem = (XmlElement)items.Item(0);
        if (uniqueItem.GetElementsByTagName("label").Item(0).FirstChild != null)
            importingElem.label = uniqueItem.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
        else importingElem.label = "";
        if (node.Attributes.GetNamedItem("ref") != null)
        {
            importingElem.reference = node.Attributes.GetNamedItem("ref").Value.ToString();
            importingElem.generateName();
        }
        importingElem.type = "select";
        if (node.Attributes.GetNamedItem("type") != null)
            importingElem.typeAttribute = node.Attributes.GetNamedItem("type").Value.ToString();

        return importingElem;
    }
    private ImportingElement checkAttributesRefInput(XmlElement node)
    {
        ImportingElement importingElem = new ImportingElement();

        if (node.Attributes.GetNamedItem("ref") != null)
        {
            importingElem.reference = node.Attributes.GetNamedItem("ref").Value.ToString();
            importingElem.generateName();
        }
        importingElem.type = "input";
        if (node.Attributes.GetNamedItem("type") != null)
        {
            importingElem.typeAttribute = node.Attributes.GetNamedItem("type").Value.ToString();
        }
        else importingElem.typeAttribute = "";
        if (!importingElem.typeAttribute.Contains("label"))
        {
            if (node.GetElementsByTagName("label").Item(0).FirstChild != null)
                importingElem.label = node.GetElementsByTagName("label").Item(0).FirstChild.Value.ToString();
            else importingElem.label = "";

        }
        else if (node.Attributes.GetNamedItem("labelvalue") != null)
        {
            importingElem.label = node.Attributes.GetNamedItem("labelvalue").Value.ToString();
        }
        else importingElem.label = "";
        if (node.Attributes.GetNamedItem("calc") != null)
        {
            importingElem.calculated = node.Attributes.GetNamedItem("calc").Value.ToString();
        }

        return importingElem;
    }