Ejemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.tabControl.TabPages.Clear();

            foreach (DocConceptRoot docRoot in this.m_view.ConceptRoots)
            {
                foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                {
                    if (docConcept.Definition != null && docConcept.Definition.Uuid == DocTemplateDefinition.guidTemplateMapping)
                    {
                        TabPage tabPage = new TabPage();
                        tabPage.Text = docRoot.Name;
                        tabPage.Tag  = docConcept;
                        this.tabControl.TabPages.Add(tabPage);

                        ListView listView = new ListView();
                        tabPage.Controls.Add(listView);
                        listView.Dock          = DockStyle.Fill;
                        listView.View          = View.Details;
                        listView.FullRowSelect = true;

                        ColumnHeader colHeaderIndex = new ColumnHeader();
                        colHeaderIndex.Text  = "Index";
                        colHeaderIndex.Width = 100;
                        listView.Columns.Add(colHeaderIndex);

                        List <CvtValuePath> colmaps = new List <CvtValuePath>();

                        foreach (DocTemplateItem docItem in docConcept.Items)
                        {
                            string       expr    = docItem.GetParameterValue("Reference");
                            CvtValuePath valpath = CvtValuePath.Parse(expr, this.m_mapEntity);
                            colmaps.Add(valpath);

                            ColumnHeader columnHeader = new ColumnHeader();
                            columnHeader.Text  = docItem.GetParameterValue("Name");
                            columnHeader.Tag   = docItem;
                            columnHeader.Width = 100;
                            listView.Columns.Add(columnHeader);
                        }

                        // load instance data
                        foreach (object instance in this.m_instances.Values)
                        {
                            string eachname = instance.GetType().Name;
                            if (docRoot.ApplicableEntity != null && docRoot.ApplicableEntity.IsInstanceOfType(instance))
                            {
                                ListViewItem lvi = new ListViewItem();
                                lvi.Text = (listView.Items.Count + 1).ToString();
                                listView.Items.Add(lvi);

                                int iCol = 0;
                                foreach (DocTemplateItem docItem in docConcept.Items)
                                {
                                    CvtValuePath valpath = colmaps[iCol];
                                    iCol++;

                                    object value = valpath.GetValue((SEntity)instance, null);

                                    if (value == instance)
                                    {
                                        value = e.GetType().Name;
                                    }
                                    else if (value is SEntity)
                                    {
                                        // use name
                                        FieldInfo fieldValue = value.GetType().GetField("Name");
                                        if (fieldValue != null)
                                        {
                                            value = fieldValue.GetValue(value);
                                        }
                                    }
                                    else if (value is System.Collections.IList)
                                    {
                                        System.Collections.IList list   = (System.Collections.IList)value;
                                        StringBuilder            sbList = new StringBuilder();
                                        foreach (object elem in list)
                                        {
                                            FieldInfo fieldName = elem.GetType().GetField("Name");
                                            if (fieldName != null)
                                            {
                                                object elemname = fieldName.GetValue(elem);
                                                if (elemname != null)
                                                {
                                                    FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                    if (fieldValue != null)
                                                    {
                                                        object elemval = fieldValue.GetValue(elemname);
                                                        sbList.Append(elemval.ToString());
                                                    }
                                                }
                                            }
                                            sbList.Append("; <br/>");
                                        }
                                        value = sbList.ToString();
                                    }
                                    else if (value is Type)
                                    {
                                        value = ((Type)value).Name;
                                    }

#if false
                                    if (!String.IsNullOrEmpty(format))
                                    {
                                        if (format.Equals("Required") && value == null)
                                        {
                                            includerow = false;
                                        }
                                    }
#endif
                                    string text = String.Empty;
                                    if (value != null)
                                    {
                                        FieldInfo fieldValue = value.GetType().GetField("Value");
                                        if (fieldValue != null)
                                        {
                                            value = fieldValue.GetValue(value);
                                        }

#if false
                                        if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                        {
                                            includerow = false;
                                        }
#endif
                                        if (value is Double)
                                        {
                                            text = ((Double)value).ToString("N3");
                                        }
                                        else if (value is List <Int64> )
                                        {
                                            // latitude or longitude
                                            List <Int64> intlist = (List <Int64>)value;
                                            if (intlist.Count >= 3)
                                            {
                                                text = intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"";
                                            }
                                        }
                                        else if (value != null)
                                        {
                                            text = value.ToString();
                                        }
                                    }

                                    lvi.SubItems.Add(text);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public string FormatData(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <long, SEntity> instances, SEntity root, bool markup)
        {
            //Guid guidMapping = Guid.Parse("");//...

            StringBuilder sb = new StringBuilder();

            foreach (DocModelView docView in docPublication.Views)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    // look for specific concept root dealing with mappings
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (docConcept.Definition != null && docConcept.Definition.Name.Equals("External Data Constraints") && docConcept.Items.Count > 0)//...
                        {
                            bool included = true;

                            if (docExchange != null)
                            {
                                included = false;
                                // if exhcnage specified, check for inclusion
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange && docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory)
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            // check if there are any instances to populate table
                            if (included)
                            {
                                included = false;
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        included = true;
                                        break;
                                    }
                                }
                            }

                            if (included)
                            {
                                string table = docConcept.Items[0].GetParameterValue("Table");
                                string query = docConcept.Items[0].GetParameterValue("Reference");

                                sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
                                sb.AppendLine("<table class=\"gridtable\">");

                                List <string>       colstyles = new List <string>();
                                List <string>       colformat = new List <string>();
                                List <CvtValuePath> colmaps   = new List <CvtValuePath>();

                                // generate header row
                                sb.AppendLine("<tr>");
                                foreach (DocTemplateItem docItem in docConcept.Items)
                                {
                                    string name = docItem.GetParameterValue("Name");
                                    string disp = "#" + docItem.GetColor().ToArgb().ToString("X8"); //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                                    string expr = docItem.GetParameterValue("Reference");
                                    string form = docItem.GetParameterValue("Format");

                                    string style = "";
                                    if (!String.IsNullOrEmpty(disp))
                                    {
                                        style = " style=\"background-color:" + disp + ";\"";
                                    }
                                    colstyles.Add(style);

                                    string format = "";
                                    if (!String.IsNullOrEmpty(form))
                                    {
                                        format = form;
                                    }
                                    colformat.Add(format);

                                    string       desc    = "";
                                    CvtValuePath valpath = CvtValuePath.Parse(expr, map); //todo: move out of loop
                                    colmaps.Add(valpath);
                                    if (valpath != null)
                                    {
                                        desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                                    }

                                    sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                                    sb.Append(name);
                                    sb.Append("</a></th>");
                                }
                                ;
                                sb.AppendLine("</tr>");

                                // generate data rows
                                foreach (SEntity e in instances.Values)
                                {
                                    string eachname = e.GetType().Name;
                                    if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                                    {
                                        bool          includerow = true;
                                        StringBuilder sbRow      = new StringBuilder();

                                        sbRow.Append("<tr>");
                                        int iCol = 0;
                                        foreach (DocTemplateItem docItem in docConcept.Items)
                                        {
                                            sbRow.Append("<td" + colstyles[iCol]);
                                            CvtValuePath valpath = colmaps[iCol];
                                            string       format  = colformat[iCol];

                                            iCol++;

                                            if (valpath != null)
                                            {
                                                string nn = docItem.GetParameterValue("Name");

                                                object value = valpath.GetValue(e, null);

                                                if (value == e)
                                                {
                                                    value = e.GetType().Name;
                                                }
                                                else if (value is SEntity)
                                                {
                                                    // use name
                                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }
                                                }
                                                else if (value is System.Collections.IList)
                                                {
                                                    System.Collections.IList list   = (System.Collections.IList)value;
                                                    StringBuilder            sbList = new StringBuilder();
                                                    foreach (object elem in list)
                                                    {
                                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                                        if (fieldName != null)
                                                        {
                                                            object elemname = fieldName.GetValue(elem);
                                                            if (elemname != null)
                                                            {
                                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                                if (fieldValue != null)
                                                                {
                                                                    object elemval = fieldValue.GetValue(elemname);
                                                                    sbList.Append(elemval.ToString());
                                                                }
                                                            }
                                                        }
                                                        sbList.Append("; <br/>");
                                                    }
                                                    value = sbList.ToString();
                                                }
                                                else if (value is Type)
                                                {
                                                    value = ((Type)value).Name;
                                                }

                                                if (!String.IsNullOrEmpty(format))
                                                {
                                                    if (format.Equals("Required") && value == null)
                                                    {
                                                        includerow = false;
                                                    }
                                                }

                                                if (value != null)
                                                {
                                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                                    if (fieldValue != null)
                                                    {
                                                        value = fieldValue.GetValue(value);
                                                    }

                                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                                    {
                                                        includerow = false;
                                                    }

                                                    if (value is Double)
                                                    {
                                                        sbRow.Append(" align=\"right\">");

                                                        sbRow.Append(((Double)value).ToString("N3"));
                                                    }
                                                    else if (value is List <Int64> )
                                                    {
                                                        sbRow.Append(">");

                                                        // latitude or longitude
                                                        List <Int64> intlist = (List <Int64>)value;
                                                        if (intlist.Count >= 3)
                                                        {
                                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                                        }
                                                    }
                                                    else if (value != null)
                                                    {
                                                        sbRow.Append(">");
                                                        sbRow.Append(value.ToString()); // todo: html-encode
                                                    }
                                                }
                                                else
                                                {
                                                    sbRow.Append(">");
                                                    sbRow.Append("&nbsp;");
                                                }
                                            }
                                            else
                                            {
                                                sbRow.Append(">");
                                            }

                                            sbRow.Append("</td>");
                                        }
                                        sbRow.AppendLine("</tr>");

                                        if (includerow)
                                        {
                                            sb.Append(sbRow.ToString());
                                        }
                                    }
                                }

                                sb.AppendLine("</table>");
                                sb.AppendLine("<br/>");
                            }
                        }
                    }
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public string FormatDataConcept(DocProject docProject, DocPublication docPublication, DocExchangeDefinition docExchange, Dictionary <string, DocObject> map, Dictionary <string, Type> typemap, Dictionary <long, SEntity> instances, SEntity root, bool markup, DocModelView docView, DocConceptRoot docRoot, DocTemplateUsage docConcept)
        {
            StringBuilder sb = new StringBuilder();

            string table = docConcept.Items[0].GetParameterValue("Table");
            string query = docConcept.Items[0].GetParameterValue("Reference");

            sb.AppendLine("<h4>" + docConcept.Name + "</h4>");
            sb.AppendLine("<table class=\"gridtable\">");

            List <string>       colstyles = new List <string>();
            List <string>       colformat = new List <string>();
            List <CvtValuePath> colmaps   = new List <CvtValuePath>();

            // generate header row
            sb.AppendLine("<tr>");
            foreach (DocTemplateItem docItem in docConcept.Items)
            {
                string name = docItem.GetParameterValue("Name");
                string disp = "#" + docItem.GetColor().ToArgb().ToString("X8");                 //docItem.GetParameterValue("Color");docItem.GetParameterValue("Color");
                string expr = docItem.GetParameterValue("Reference");
                string form = docItem.GetParameterValue("Format");

                string style = "";
                if (!String.IsNullOrEmpty(disp))
                {
                    style = " style=\"background-color:" + disp + ";\"";
                }
                colstyles.Add(style);

                string format = "";
                if (!String.IsNullOrEmpty(form))
                {
                    format = form;
                }
                colformat.Add(format);

                string       desc    = "";
                CvtValuePath valpath = CvtValuePath.Parse(expr, map);
                colmaps.Add(valpath);
                if (valpath != null)
                {
                    desc = /*valpath.GetDescription(map) + "&#10;&#10;" + */ valpath.ToString().Replace("\\", "&#10;");
                }

                sb.Append("<th><a href=\"../../schema/views/" + DocumentationISO.MakeLinkName(docView) + "/" + DocumentationISO.MakeLinkName(docExchange) + ".htm#" + DocumentationISO.MakeLinkName(docConcept) + "\" title=\"" + desc + "\">");
                sb.Append(name);
                sb.Append("</a></th>");
            }
            ;
            sb.AppendLine("</tr>");

            // generate data rows
            List <DocModelRule> trace = new List <DocModelRule>();

            foreach (SEntity e in instances.Values)
            {
                string eachname = e.GetType().Name;
                if (docRoot.ApplicableEntity.IsInstanceOfType(e))
                {
                    bool includerow = true;

                    // if root has more complex rules, check them
                    if (docRoot.ApplicableTemplate != null && docRoot.ApplicableItems.Count > 0)
                    {
                        includerow = false;

                        // must check1
                        foreach (DocTemplateItem docItem in docRoot.ApplicableItems)
                        {
                            foreach (DocModelRule rule in docRoot.ApplicableTemplate.Rules)
                            {
                                try
                                {
                                    trace.Clear();
                                    bool?result = rule.Validate(e, docItem, typemap, trace, e, null, null);
                                    if (result == true && docRoot.ApplicableOperator == DocTemplateOperator.Or)
                                    {
                                        includerow = true;
                                        break;
                                    }
                                }
                                catch
                                {
                                    docRoot.ToString();
                                }
                            }

                            // don't yet support AND or other operators

                            if (includerow)
                            {
                                break;
                            }
                        }
                    }


                    if (includerow)
                    {
                        StringBuilder sbRow = new StringBuilder();

                        sbRow.Append("<tr>");
                        int iCol = 0;
                        foreach (DocTemplateItem docItem in docConcept.Items)
                        {
                            sbRow.Append("<td" + colstyles[iCol]);
                            CvtValuePath valpath = colmaps[iCol];
                            string       format  = colformat[iCol];

                            iCol++;

                            if (valpath != null)
                            {
                                string nn = docItem.GetParameterValue("Name");

                                object value = valpath.GetValue(e, null);

                                if (value == e)
                                {
                                    value = e.GetType().Name;
                                }
                                else if (value is SEntity)
                                {
                                    // use name
                                    FieldInfo fieldValue = value.GetType().GetField("Name");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }
                                }
                                else if (value is System.Collections.IList)
                                {
                                    System.Collections.IList list   = (System.Collections.IList)value;
                                    StringBuilder            sbList = new StringBuilder();
                                    foreach (object elem in list)
                                    {
                                        FieldInfo fieldName = elem.GetType().GetField("Name");
                                        if (fieldName != null)
                                        {
                                            object elemname = fieldName.GetValue(elem);
                                            if (elemname != null)
                                            {
                                                FieldInfo fieldValue = elemname.GetType().GetField("Value");
                                                if (fieldValue != null)
                                                {
                                                    object elemval = fieldValue.GetValue(elemname);
                                                    sbList.Append(elemval.ToString());
                                                }
                                            }
                                        }
                                        sbList.Append("; <br/>");
                                    }
                                    value = sbList.ToString();
                                }
                                else if (value is Type)
                                {
                                    value = ((Type)value).Name;
                                }

                                if (!String.IsNullOrEmpty(format))
                                {
                                    if (format.Equals("Required") && value == null)
                                    {
                                        includerow = false;
                                    }
                                }

                                if (value != null)
                                {
                                    FieldInfo fieldValue = value.GetType().GetField("Value");
                                    if (fieldValue != null)
                                    {
                                        value = fieldValue.GetValue(value);
                                    }

                                    if (format != null && format.Equals("True") && (value == null || !value.ToString().Equals("True")))
                                    {
                                        includerow = false;
                                    }

                                    if (value is Double)
                                    {
                                        sbRow.Append(" align=\"right\">");

                                        sbRow.Append(((Double)value).ToString("N3"));
                                    }
                                    else if (value is List <Int64> )
                                    {
                                        sbRow.Append(">");

                                        // latitude or longitude
                                        List <Int64> intlist = (List <Int64>)value;
                                        if (intlist.Count >= 3)
                                        {
                                            sbRow.Append(intlist[0] + "° " + intlist[1] + "' " + intlist[2] + "\"");
                                        }
                                    }
                                    else if (value != null)
                                    {
                                        sbRow.Append(">");
                                        sbRow.Append(value.ToString());                                         // todo: html-encode
                                    }
                                }
                                else
                                {
                                    sbRow.Append(">");
                                    sbRow.Append("&nbsp;");
                                }
                            }
                            else
                            {
                                sbRow.Append(">");
                            }

                            sbRow.Append("</td>");
                        }
                        sbRow.AppendLine("</tr>");

                        if (includerow)
                        {
                            sb.Append(sbRow.ToString());
                        }
                    }
                }
            }

            sb.AppendLine("</table>");
            sb.AppendLine("<br/>");

            return(sb.ToString());
        }