예제 #1
0
    /// <summary>
    /// Get OOFormArray from json string.
    /// </summary>
    /// <param name="jsonString"></param>
    /// <returns></returns>
    public static OOFormArray GetFormByJsonString(string jsonString)
    {
        OOFormArray      form_array = new OOFormArray();
        List <Hashtable> table_list = OOLitJson.JsonMapper.ToObject <List <Hashtable> >(jsonString);

        form_array.InsertRow(0);
        form_array.InsertColumn(0);
        //int row = 0;
        foreach (Hashtable table in table_list)
        {
            form_array.InsertRow(form_array.mRowCount);
            foreach (string key_str in table.Keys)
            {
                if (form_array.GetColumn(key_str) == -1)
                {
                    if (form_array.mColumnDic.Count <= 1)
                    {
                        form_array.SetString(key_str, 0, 0);
                        form_array.AddColumnName(key_str, 0);
                    }
                    else
                    {
                        form_array.InsertColumn(form_array.mColumnCount);
                        form_array.SetString(key_str, form_array.mColumnCount - 1, 0);
                        form_array.AddColumnName(key_str, form_array.mColumnCount - 1);
                    }
                }
                form_array.SetString(table[key_str].ToString(), form_array.GetColumn(key_str), form_array.mRowCount - 1);
            }
        }
        return(form_array);
    }
예제 #2
0
    /// <summary>
    /// Get OOFormArray from xml string;
    /// </summary>
    /// <param name="xmlString"></param>
    /// <returns></returns>
    public static OOFormArray GetFormByXMLString(string xmlString)
    {
        //if string with BOM,remove it.
        if ((int)xmlString[0] == 65279)
        {
            xmlString = xmlString.Substring(1);
        }

        OOFormArray form_array = new OOFormArray();

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(xmlString);

        form_array.InsertRow(0);
        form_array.InsertColumn(0);
        XmlNode     node           = xmlDoc.FirstChild;
        XmlNodeList component_list = node.ChildNodes;

        foreach (XmlNode row_node in component_list)
        {
            form_array.InsertRow(form_array.mRowCount);
            foreach (XmlAttribute attr in row_node.Attributes)
            {
                if (form_array.GetColumn(attr.Name) == -1)
                {
                    if (form_array.mColumnDic.Count <= 1)
                    {
                        form_array.SetString(attr.Name, 0, 0);
                        form_array.AddColumnName(attr.Name, 0);
                    }
                    else
                    {
                        form_array.InsertColumn(form_array.mColumnCount);
                        form_array.SetString(attr.Name, form_array.mColumnCount - 1, 0);
                        form_array.AddColumnName(attr.Name, form_array.mColumnCount - 1);
                    }
                }
                form_array.SetString(attr.Value.ToString(), form_array.GetColumn(attr.Name), form_array.mRowCount - 1);
            }
        }
        return(form_array);
    }