Beispiel #1
0
        private static string PrintFlatRelations(Graph.Edge parent, int level, IEnumerable <Graph.Edge> relations, TiskEnum typ,
                                                 List <string> renderedIds, bool withStats = true, string highlightSubjId = null)
        {
            int    space     = 2;
            string horizLine = "--"; //new string('\u2500',2);
            string vertLine  = "|";  //new string('\u2502',1);
            string cross     = "+";  //new string('\u251C', 1);

            if (renderedIds == null)
            {
                renderedIds = new List <string>();
            }

            var rels = relations
                       .Where(m =>
                              (
                                  (parent != null && m.From?.UniqId == parent.To?.UniqId)
                                  ||
                                  (parent == null && !relations.Any(r => r.To?.UniqId == m.From?.UniqId)) //do root urovne pridej vazby, ktere jsou sirotci bez parenta
                              )
                              )
                       .Distinct()
                       .GroupBy(k => new { id = k.To.UniqId, type = k.To.Type }, (k, v) =>
            {
                Graph.Edge withChildren = v.Where(r => relations.Any(m => m.From?.UniqId == r.To?.UniqId)).FirstOrDefault();
                if (withChildren == null)
                {
                    withChildren = v.First();
                }

                return(withChildren);
            })
                       .OrderBy(m => m.To.PrintName(typ == TiskEnum.Html))
                       .ToArray();

            if (rels.Count() == 0)
            {
                return(string.Empty);
            }

            StringBuilder     sb       = new StringBuilder(512);
            List <Graph.Edge> deepRels = new List <Graph.Edge>();

            switch (typ)
            {
            case TiskEnum.Text:
                break;

            case TiskEnum.Html:
            case TiskEnum.Checkbox:
                sb.AppendLine("<ul>");
                break;

            case TiskEnum.Json:
                break;
            }
            for (int i = 0; i < rels.Count(); i++)
            {
                var rel = rels[i];
                if (renderedIds.Contains(rel.To.UniqId))
                {
                    continue;
                }

                var last = i == (rels.Count() - 1);
                Analysis.SubjectStatistic stat = null;
                if (withStats && rel.To.Type == Graph.Node.NodeType.Company)
                {
                    stat = new Analysis.SubjectStatistic(rel.To.Id);
                }
                string subjId   = rel.To.Type == Graph.Node.NodeType.Company ? rel.To.Id : "Osoba";
                string subjName = rel.To.PrintName();
                renderedIds.Add(rel.To.UniqId);
                switch (typ)
                {
                case TiskEnum.Text:
                    sb.AppendLine(string.Concat(Enumerable.Repeat(vertLine + new string(' ', space), level + 1)));
                    sb.Append(
                        string.Concat(
                            Enumerable.Repeat(
                                vertLine + new string(' ', space)
                                , (level))
                            )
                        );
                    if (rel.To.Highlighted)
                    {
                        subjName = string.Format("!!{0}!!", subjName);
                    }

                    sb.AppendFormat("{0}{1}:{2} {3}\n",
                                    cross + horizLine + " ",
                                    subjId,
                                    subjName,
                                    rel.Doba()
                                    );
                    sb.Append(PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats));
                    break;

                case TiskEnum.Html:
                    if (withStats && stat != null)
                    {
                        sb.AppendFormat("<li class='{3} {6}'><a href='/subjekt/{0}'>{0}:{1}</a>{7}; {4}, celkem {5}.   {2}</li>",
                                        subjId,
                                        subjName,
                                        PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats),
                                        last ? "" : "connect",
                                        PluralForm.Get((int)stat.BasicStatPerYear.Summary.Pocet, "{0} smlouva;{0} smlouvy;{0} smluv"),
                                        Smlouva.NicePrice(stat.BasicStatPerYear.Summary.CelkemCena, html: true, shortFormat: true),
                                        "aktualnost" + ((int)rel.Aktualnost).ToString(),
                                        (rel.Aktualnost < AktualnostType.Aktualni) ? rel.Doba("/{0}/") : string.Empty
                                        );
                    }
                    else
                    {
                        sb.AppendFormat("<li class='{3} {4}'><a href='/subjekt/{0}'><span class=''>{0}:{1}</span></a>{5}.  {2}</li>",
                                        subjId,
                                        subjName,
                                        PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats),
                                        last ? "" : "connect",
                                        "aktualnost" + ((int)rel.Aktualnost).ToString(),
                                        (rel.Aktualnost < AktualnostType.Aktualni) ? rel.Doba("/{0}/") : string.Empty,
                                        (!string.IsNullOrEmpty(highlightSubjId) && subjId == highlightSubjId) ? "highlighted" : ""
                                        );
                    }

                    break;

                case TiskEnum.Checkbox:
                    sb.AppendFormat(@"<li class=""{0} {1}""><input type=""checkbox"" name=""ico"" value=""{2}"" /> <span><b>{2}</b> {3}</span>{4}</li>"
                                    , (last ? "" : "connect"),
                                    ("aktualnost" + ((int)rel.Aktualnost).ToString()),
                                    subjId, subjName,
                                    PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats)
                                    );

                    break;

                case TiskEnum.Json:
                    break;
                }
            }
            switch (typ)
            {
            case TiskEnum.Text:
                break;

            case TiskEnum.Html:
            case TiskEnum.Checkbox:
                sb.AppendLine("</ul>");
                break;

            case TiskEnum.Json:
                break;
            }

            return(sb.ToString());
        }
        public string RenderText(string delimeter = "\n")
        {
            StringBuilder sb = new StringBuilder();

            switch ((Types)this.Type)
            {
            case Types.Sponzor:
                return(Title + " v " + this.RenderDatum() + (AddInfoNum.HasValue ? ", " + Smlouva.NicePrice(AddInfoNum) : ""));

            case Types.SponzorZuctu:
                return("");    // Title + " v " + this.RenderDatum() + (AddInfoNum.HasValue ? ", " + Smlouva.NicePrice(AddInfoNum) : "") + " (z transp.účtu)";

            case Types.OsobniVztah:
                if (!string.IsNullOrEmpty(AddInfo) && Devmasters.Core.TextUtil.IsNumeric(AddInfo))
                {
                    Osoba o = Osoby.GetById.Get(Convert.ToInt32(AddInfo));
                    if (o != null)
                    {
                        return(this.Title + " s " + o.FullName());
                    }
                    else
                    {
                        return(this.Title + " " + Description);
                    }
                }
                else
                {
                    return(this.Title + " " + Description);
                }

            case Types.Popis:
            default:
                if (!string.IsNullOrEmpty(this.Title) && !string.IsNullOrEmpty(this.Description))
                {
                    return(this.Title + delimeter + this.Description);
                }
                else if (!string.IsNullOrEmpty(this.Title))
                {
                    return(this.Title);
                }
                else if (!string.IsNullOrEmpty(this.Description))
                {
                    return(this.Description);
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
        public string RenderHtml(string delimeter = ", ")
        {
            string zdroj = "";

            if (!string.IsNullOrEmpty(this.Zdroj))
            {
                if (this.Zdroj.ToLower().StartsWith("http"))
                {
                    zdroj = string.Format(" <a target='_blank' href='{0}'>{1}</a>", this.Zdroj, "<span class='text-muted' title='Jedná se o peněžní nebo nepeněžní dar' alt='Jedná se o peněžní nebo nepeněžní dar'>(<span class='glyphicon glyphicon-link' aria-hidden='true'></span> zdroj</span>)");
                }
                else
                {
                    zdroj = string.Format(" ({0})", this.Zdroj);
                }
            }
            StringBuilder sb = new StringBuilder();

            switch ((Types)this.Type)
            {
            case Types.Sponzor:
                return(Title + " v " + this.RenderDatum() + (AddInfoNum.HasValue ? ", " + Smlouva.NicePrice(AddInfoNum) : "") + zdroj);

            case Types.SponzorZuctu:
                return("");    // Title + " v " + this.RenderDatum() + (AddInfoNum.HasValue ? ", " + Smlouva.NicePrice(AddInfoNum) : "") + " (z transp.účtu)" + zdroj;

            case Types.OsobniVztah:
                if (!string.IsNullOrEmpty(AddInfo) && Devmasters.Core.TextUtil.IsNumeric(AddInfo))
                {
                    Osoba o = Osoby.GetById.Get(Convert.ToInt32(AddInfo));
                    if (o != null)
                    {
                        return(this.Title + " s " + string.Format("<a href=\"{0}\">{1}</a>", o.GetUrlOnWebsite(), o.FullName()) + zdroj);
                    }
                    else
                    {
                        return(this.Title + " " + Description + zdroj);
                    }
                }
                else
                {
                    return(this.Title + " " + Description + zdroj);
                }

            case Types.Popis:
            default:
                if (!string.IsNullOrEmpty(this.Title) && !string.IsNullOrEmpty(this.Description))
                {
                    return(this.Title + delimeter + this.Description + zdroj);
                }
                else if (!string.IsNullOrEmpty(this.Title))
                {
                    return(this.Title + zdroj);
                }
                else if (!string.IsNullOrEmpty(this.Description))
                {
                    return(this.Description + zdroj);
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
        public string RenderText(string delimeter = "\n")
        {
            StringBuilder sb = new StringBuilder();

            switch ((Types)this.Type)
            {
            case Types.ClenStrany:
                sb.AppendFormat("Člen strany {1} {0} ", this.RenderDatum(), this.AddInfo);
                return(sb.ToString());

            case Types.Poslanec:
                sb.AppendFormat("Poslanec {0} ", this.RenderDatum());
                if (!string.IsNullOrEmpty(this.AddInfo))
                {
                    sb.Append(" za " + AddInfo);
                }
                return(sb.ToString());

            case Types.Senator:
                sb.AppendFormat("Senator {0} ", this.RenderDatum());
                if (!string.IsNullOrEmpty(this.AddInfo))
                {
                    sb.Append(" za " + AddInfo);
                }
                return(sb.ToString());

            case Types.Sponzor:
                return(Title + " v " + this.RenderDatum() + (AddInfoNum.HasValue ? ", hodnota daru " + Smlouva.NicePrice(AddInfoNum)  : ""));

            case Types.OsobniVztah:
            case Types.Pribuzny:
                if (!string.IsNullOrEmpty(AddInfo) && Devmasters.Core.TextUtil.IsNumeric(AddInfo))
                {
                    Osoba o = Osoby.GetById.Get(Convert.ToInt32(AddInfo));
                    if (o != null)
                    {
                        return(this.Title + " s " + o.FullName());
                    }
                    else
                    {
                        return(this.Title + " " + Description);
                    }
                }
                else
                {
                    return(this.Title + " " + Description);
                }

            case Types.Popis:
            default:
                if (!string.IsNullOrEmpty(this.Title) && !string.IsNullOrEmpty(this.Description))
                {
                    return(this.Title + delimeter + this.Description);
                }
                else if (!string.IsNullOrEmpty(this.Title))
                {
                    return(this.Title);
                }
                else if (!string.IsNullOrEmpty(this.Description))
                {
                    return(this.Description);
                }
                else
                {
                    return(string.Empty);
                }
            }
        }