Exemple #1
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());
        }