コード例 #1
0
        public ActionResult AddPersons(FormCollection form)
        {
            this.Server.ScriptTimeout = 600;

            List <string> newIds       = new List <string>();
            string        tabdelimited = form["data"];

            foreach (var line in tabdelimited.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] cols = line.Split(new string[] { "\t" }, StringSplitOptions.None);
                if (cols.Count() < 3)
                {
                    continue;
                }
                string jmeno = cols[0];
                string prijmeni = cols[1];
                string titulPred = "", titulPo = "";

                string narozeni = cols[2];


                if (cols.Count() > 3)
                {
                    titulPred = cols[3];
                }
                if (cols.Count() > 4)
                {
                    titulPo = cols[4];
                }
                //TODO


                HlidacStatu.Lib.Data.Osoba p = HlidacStatu.Lib.Data.Osoba.GetOrCreateNew(titulPred, titulPo, jmeno, prijmeni, narozeni, Osoba.StatusOsobyEnum.NeniPolitik,
                                                                                         this.User.Identity.Name);

                //Guid? foundId;
                //if (Osoba.GetByName(p.Jmeno, p.Prijmeni, p.Narozeni.Value) == null)
                //{
                //    if (cols.Count() > 5)
                //        p.Description = cols[5];
                //    if (cols.Count() > 6)
                //        p.PersonStatus = string.IsNullOrEmpty(cols[6]) ? 0 : int.Parse(cols[6]);
                //    if (cols.Count() > 7)
                //        p.Zdroj = cols[7];
                //    if (cols.Count() > 8)
                //        p.MoreInfoUrl = cols[8];


                //    var res = Person.Import(p, true);
                //    if (res.IsValid)
                //        newIds.Add(res.Id + " " + p.FullName());

                //}
            }
            return(View(newIds));
        }
コード例 #2
0
        public ActionResult OsobaSmazat(string nameId)
        {
            var auth = Framework.ApiAuth.IsApiAuth(this, "TeamMember");

            if (auth.Authentificated)
            {
                HlidacStatu.Lib.Data.Osoba o = HlidacStatu.Lib.Data.Osoba.GetByNameId(nameId);
                if (o == null)
                {
                    return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { valid = false, error = "Not found." }), "application/json"));
                }

                o.Delete(auth.ApiCall.User);
                return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(
                                   new { valid = true })
                               , "application/json"));
            }
            else
            {
                return(View("Error401"));
            }
        }
コード例 #3
0
        public ActionResult Politik(string id)
        {
            HlidacStatu.Lib.Data.Osoba model = HlidacStatu.Lib.Data.Osoby.GetByNameId.Get(id);

            return(View(model));
        }
コード例 #4
0
ファイル: Validators.cs プロジェクト: hosekp/HlidacStatu
        public static Lib.Data.Osoba JmenoInText(string text, bool preferAccurateResult = false)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            string normalizedText = Devmasters.TextUtil
                                    .ReplaceDuplicates(Regex.Replace(text, @"[,;\[\]:]", " "), ' ');
            // Zakomentováno 12.12.2019 - při nahrávání dotací byl problém se jménem Ĺudovit
            //fix errors Ĺ => Í,ĺ => í
            //normalizedText = normalizedText.Replace((char)314, (char)237).Replace((char)313, (char)205);

            //remove tituly
            var titulyPo   = Osoba.TitulyPo.Select(m => Devmasters.TextUtil.RemoveDiacritics(m).ToLower()).ToArray();
            var titulyPred = Osoba.TitulyPred.Select(m => Devmasters.TextUtil.RemoveDiacritics(m).ToLower()).ToArray();

            List <string> lWords = new List <string>();

            var titulPred = string.Empty;
            var titulPo   = string.Empty;

            foreach (var w in normalizedText
                     .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                     )
            {
                var    newW = w;
                string cw   = TextUtil.RemoveDiacritics(w).ToLower();
                for (int i = 0; i < titulyPo.Length; i++)
                {
                    var t = titulyPo[i];
                    if (cw == t)
                    {
                        newW    = "";
                        titulPo = titulPo + " " + Osoba.TitulyPo[i];
                        break;
                    }
                    else if (t.EndsWith(".") && cw == t.Substring(0, t.Length - 1))
                    {
                        newW    = "";
                        titulPo = titulPo + " " + Osoba.TitulyPo[i];
                        break;
                    }
                }
                for (int i = 0; i < titulyPred.Length; i++)
                {
                    var t = titulyPred[i];

                    if (cw == t)
                    {
                        newW      = "";
                        titulPred = titulPred + " " + Osoba.TitulyPred[i];
                        break;
                    }
                    else if (t.EndsWith(".") && cw == t.Substring(0, t.Length - 1))
                    {
                        newW      = "";
                        titulPred = titulPred + " " + Osoba.TitulyPred[i];
                        break;
                    }
                }
                titulPo   = titulPo.Trim();
                titulPred = titulPred.Trim();
                lWords.Add(newW);
            }

            //reset normalizedText after titulPred, titulPo
            normalizedText = lWords.Aggregate((f, s) => f + " " + s).Trim();
            normalizedText = Devmasters.TextUtil
                             .ReplaceDuplicates(normalizedText.Replace(".", ". "), ' ');
            normalizedText = Devmasters.TextUtil
                             .ReplaceDuplicates(normalizedText, " ");
            string[] wordsFromNormalizedText = normalizedText.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] words = wordsFromNormalizedText.Select(m => TextUtil.RemoveDiacritics(m).ToLower()).ToArray();


            int maxWords = 2;
            int minWords = 2;

            for (int firstWord = 0; firstWord < words.Length - 1; firstWord++)
            {
                for (int takeWords = Math.Min(maxWords, words.Count() - firstWord); takeWords >= minWords; takeWords--)
                {
                    var currWords = words.Skip(firstWord).Take(takeWords).ToArray();
                    var origWords = wordsFromNormalizedText.Skip(firstWord).Take(takeWords).ToArray();


                    CompareResult w0 = CompareName(currWords[0]);
                    CompareResult w1 = CompareName(currWords[1]);
                    if (w0 == w1 && w0 != CompareResult.NotFound && currWords[0] == currWords[1]) //stejne jmeno a prijmeni MUDr. Tomáš Tomáš, PH.D.
                    {
                        return new Osoba()
                               {
                                   Jmeno = origWords[0], Prijmeni = origWords[1], TitulPred = titulPred, TitulPo = titulPo
                               }
                    }
                    ;

                    if (
                        w0.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInJmeno) &&
                        !w0.HasAnyFlags(CompareResult.FoundInTopPrijmeni) &&
                        w0 != CompareResult.NotFound
                        &&
                        w1.HasAnyFlags(CompareResult.FoundInTopPrijmeni | CompareResult.FoundInPrijmeni) &&
                        !w1.HasAnyFlags(CompareResult.FoundInTopJmeno) &&
                        w1 != CompareResult.NotFound
                        )
                    {
                        return new Osoba()
                               {
                                   Jmeno = origWords[0], Prijmeni = origWords[1], TitulPred = titulPred, TitulPo = titulPo
                               }
                    }
                    ;
                    else if (
                        w1.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInJmeno) &&
                        !w1.HasAnyFlags(CompareResult.FoundInTopPrijmeni) &&
                        w1 != CompareResult.NotFound
                        &&
                        w0.HasAnyFlags(CompareResult.FoundInTopPrijmeni | CompareResult.FoundInPrijmeni) &&
                        !w0.HasAnyFlags(CompareResult.FoundInTopJmeno) &&
                        w0 != CompareResult.NotFound
                        )
                    {
                        return new Osoba()
                               {
                                   Jmeno = origWords[1], Prijmeni = origWords[0], TitulPred = titulPred, TitulPo = titulPo
                               }
                    }
                    ;

                    //situace ala
                    //w0 FoundInTopPrijmeni | FoundInTopJmeno
                    //w1  FoundInPrijmeni
                    if (
                        w0.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInTopPrijmeni) &&
                        !w1.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInJmeno) &&
                        w1 != CompareResult.NotFound
                        )
                    {
                        return new Osoba()
                               {
                                   Jmeno = origWords[0], Prijmeni = origWords[1], TitulPred = titulPred, TitulPo = titulPo
                               }
                    }
                    ;
                    if (
                        w1.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInTopPrijmeni) &&
                        !w0.HasAnyFlags(CompareResult.FoundInTopJmeno | CompareResult.FoundInJmeno) &&
                        w0 != CompareResult.NotFound
                        )
                    {
                        return new Osoba()
                               {
                                   Jmeno = origWords[1], Prijmeni = origWords[0], TitulPred = titulPred, TitulPo = titulPo
                               }
                    }
                    ;



                    if (preferAccurateResult)
                    {
                        return(null);
                    }

                    Osoba o = new Data.Osoba();
                    o.TitulPred = titulPred; o.TitulPo = titulPo;

                    if (w0.HasFlag(CompareResult.FoundInTopJmeno))
                    {
                        o.Jmeno = origWords[0];
                    }
                    if (string.IsNullOrEmpty(o.Jmeno) &&
                        origWords.Length > 1 &&
                        w1.HasFlag(CompareResult.FoundInTopJmeno)
                        )
                    {
                        o.Jmeno = origWords[1];
                    }
                    if (w1.HasFlag(CompareResult.FoundInTopPrijmeni) &&
                        origWords.Length > 1 &&
                        o.Jmeno != origWords[1]
                        )
                    {
                        o.Prijmeni = origWords[1];
                    }
                    if (string.IsNullOrEmpty(o.Prijmeni) &&
                        w0.HasFlag(CompareResult.FoundInTopPrijmeni) &&
                        o.Jmeno != origWords[0]
                        )
                    {
                        o.Prijmeni = origWords[0];
                    }

                    if (string.IsNullOrEmpty(o.Jmeno) &&
                        w0.HasFlag(CompareResult.FoundInJmeno) &&
                        o.Prijmeni != origWords[0]
                        )
                    {
                        o.Jmeno = origWords[0];
                    }
                    if (string.IsNullOrEmpty(o.Jmeno) &&
                        w1.HasFlag(CompareResult.FoundInJmeno) &&
                        origWords.Length > 1 &&
                        o.Prijmeni != origWords[1]
                        )
                    {
                        o.Jmeno = origWords[1];
                    }

                    if (string.IsNullOrEmpty(o.Prijmeni) &&
                        w1.HasFlag(CompareResult.FoundInPrijmeni) &&
                        origWords.Length > 1 &&
                        o.Jmeno != origWords[1]
                        )
                    {
                        o.Prijmeni = origWords[1];
                    }

                    if (string.IsNullOrEmpty(o.Prijmeni) &&
                        w0.HasFlag(CompareResult.FoundInPrijmeni) &&
                        o.Jmeno != origWords[0]
                        )
                    {
                        o.Prijmeni = origWords[0];
                    }
                    if (!string.IsNullOrEmpty(o.Jmeno) && !string.IsNullOrEmpty(o.Prijmeni))
                    {
                        return(o);
                    }


                    //if (w1.HasFlag(CompareResult.FoundInTopJmeno))
                }
            }
            return(null);
        }
コード例 #5
0
            public static IEnumerable <Osoba> GetPolitikByQueryFromFirmy(string jmeno, int maxNumOfResults = 50, IEnumerable <Firma> alreadyFoundFirmyIcos = null)
            {
                var res = new Osoba[] { };

                var firmy = alreadyFoundFirmyIcos;

                if (firmy == null)
                {
                    firmy = Firma.Search.SimpleSearch(jmeno, 0, maxNumOfResults * 10).Result;
                }

                if (firmy != null && firmy.Count() > 0)
                {
                    Dictionary <int, int> osoby = new Dictionary <int, int>();
                    bool skipRest = false;
                    foreach (var f in firmy)
                    {
                        if (skipRest)
                        {
                            break;
                        }

                        if (StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy.ContainsKey(f.ICO))
                        {
                            foreach (var osobaId in StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy[f.ICO])
                            {
                                if (osoby.ContainsKey(osobaId))
                                {
                                    osoby[osobaId]++;
                                }
                                else
                                {
                                    osoby.Add(osobaId, 1);
                                }

                                if (osoby.Count > maxNumOfResults)
                                {
                                    skipRest = true;
                                    break;
                                }
                            }
                        }

                        if (skipRest == false)
                        {
                            var fvazby = f.AktualniVazby(Relation.AktualnostType.Nedavny);
                            foreach (var fv in fvazby)
                            {
                                if (fv.To.Type == Graph.Node.NodeType.Company)
                                {
                                    int osobaId = Convert.ToInt32(fv.To.Id);
                                    if (osoby.ContainsKey(osobaId))
                                    {
                                        osoby[osobaId]++;
                                    }
                                    else
                                    {
                                        osoby.Add(osobaId, 1);
                                    }
                                }
                                if (osoby.Count > maxNumOfResults)
                                {
                                    skipRest = true;
                                    break;
                                }

                                if (skipRest == false && StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy.ContainsKey(fv.To.Id))
                                {
                                    foreach (var osobaId in StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy[fv.To.Id])
                                    {
                                        if (osoby.ContainsKey(osobaId))
                                        {
                                            osoby[osobaId]++;
                                        }
                                        else
                                        {
                                            osoby.Add(osobaId, 1);
                                        }
                                        if (osoby.Count > maxNumOfResults)
                                        {
                                            skipRest = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    res = osoby
                          .OrderByDescending(o => o.Value)
                          .Take(maxNumOfResults - res.Length)
                          .Select(m => Osoby.GetById.Get(m.Key))
                          .Where(m => m != null)
                          .Where(m => m.IsValid())   //not empty (nullObj from OsobaCache)
                          .ToArray();
                }
                return(res);
            }
コード例 #6
0
        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.GetUrl(), 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);
                }
            }
        }
コード例 #7
0
        private static MultiResult GeneralSearch(Elastic.Apm.Api.ITransaction apmtran, string query, int page = 1, int pageSize = 10, bool showBeta = false)
        {
            MultiResult res = new MultiResult()
            {
                Query = query
            };

            if (string.IsNullOrEmpty(query))
            {
                return(res);
            }

            if (!Lib.Searching.Tools.ValidateQuery(query))
            {
                res.Smlouvy         = new Searching.SmlouvaSearchResult();
                res.Smlouvy.Q       = query;
                res.Smlouvy.IsValid = false;

                return(res);
            }

            var totalsw = new Devmasters.Core.StopWatchEx();

            totalsw.Start();

            ParallelOptions po = new ParallelOptions();

            //po.MaxDegreeOfParallelism = 20;
            po.MaxDegreeOfParallelism = System.Diagnostics.Debugger.IsAttached ? 1 : po.MaxDegreeOfParallelism;

            Parallel.Invoke(po,
                            () =>
            {
                Elastic.Apm.Api.ISpan sp = null;
                try
                {
                    apmtran.CaptureSpan("Smlouvy", "search", () =>
                    {
                        res.Smlouvy = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch(query, 1, 20, Smlouva.Search.OrderResult.Relevance,
                                                                                       anyAggregation: new Nest.AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Sum("sumKc", m => m.Field(f => f.CalculatedPriceWithVATinCZK))
                                                                                       );
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Smlouvy query" + query, e);
                }
                finally
                {
                    sp?.End();
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();

                    res.Firmy = new GeneralResult <string>(Firma.Search.FindAllIco(query, 50));
                    sw.Stop();
                    res.Firmy.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Firmy query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    res.VZ = VZ.VerejnaZakazka.Searching.SimpleSearch(query, null, 1, 5, (int)Lib.Searching.VerejnaZakazkaSearchData.VZOrderResult.Relevance);
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Verejne zakazky query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    Devmasters.Core.StopWatchEx sw = new Devmasters.Core.StopWatchEx();
                    sw.Start();

                    if (!string.IsNullOrEmpty(query) && query.Length > 2)
                    {
                        res.Osoby = new GeneralResult <Osoba>(
                            HlidacStatu.Lib.Data.Osoba.GetPolitikByNameFtx(query, 100)
                            .OrderBy(m => m.Prijmeni)
                            .ThenBy(m => m.Jmeno)
                            );
                    }
                    else
                    {
                        res.Osoby = new GeneralResult <Osoba>(new Osoba[] { });
                    }
                    sw.Stop();
                    res.Osoby.ElapsedTime = sw.Elapsed;
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for Osoba query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    var iqu = new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = 5
                    };
                    res.Insolvence = iqu;
                    //if (showBeta)
                    res.Insolvence = Insolvence.Insolvence.SimpleSearch(new Searching.InsolvenceSearchResult {
                        Q = query, PageSize = 5
                    });
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                try
                {
                    if (showBeta)
                    {
                        var dotaceService = new Dotace.DotaceService();
                        var iqu           = new Searching.DotaceSearchResult {
                            Q = query, PageSize = 5
                        };
                        res.Dotace = iqu;
                        //if (showBeta)
                        res.Dotace = dotaceService.SimpleSearch(new Searching.DotaceSearchResult {
                            Q = query, PageSize = 5
                        });
                    }
                }
                catch (System.Exception e)
                {
                    Util.Consts.Logger.Error("MultiResult GeneralSearch for insolvence query" + query, e);
                }
            },
                            () =>
            {
                Elastic.Apm.Api.ISpan sp = null;
                try
                {
                    apmtran.CaptureSpan("Dataset GeneralSearch", "search", () =>
                    {
                        res.Datasets = Lib.Data.Search.DatasetMultiResult.GeneralSearch(query, null, 1, 5);
                        if (res.Datasets.Exceptions.Count > 0)
                        {
                            HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query,
                                                                 res.Datasets.GetExceptions());
                        }
                    });
                }
                catch (System.Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("MultiResult GeneralSearch for DatasetMulti query " + query, e);
                }
                finally
                {
                }
            }

                            );

            //TODO too slow, temporarily disabled
            if (false && res.HasFirmy && (res.Osoby == null || res.Osoby.Total < 5))
            {
                var sw = new Devmasters.Core.StopWatchEx();
                sw.Start();
                if (res.Osoby == null)
                {
                    res.Osoby = new GeneralResult <Osoba>(new Osoba[] { });
                }

                res.Osoby = new GeneralResult <Osoba>(res.Osoby.Result
                                                      .Concat(Osoba.GetPolitikByQueryFromFirmy(query, (int)(10 - (res.Osoby?.Total ?? 0)), res.Firmy.Result)
                                                              )
                                                      );
                res.OsobaFtx = true;
                sw.Stop();
                res.AddOsobyTime = sw.Elapsed;
            }

            totalsw.Stop();
            res.TotalSearchTime = totalsw.Elapsed;

            return(res);
        }
コード例 #8
0
        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);
                }
            }
        }
コード例 #9
0
        public Osoba MergeWith(Osoba duplicated, string user)
        {
            if (this.InternalId == duplicated.InternalId)
            {
                return(this);
            }

            OsobaEvent[]      dEvs  = duplicated.Events().ToArray();
            OsobaExternalId[] dEids = duplicated.ExternalIds().Where(m => m.ExternalSource != (int)OsobaExternalId.Source.HlidacSmluvGuid).ToArray();

            foreach (var dEv in dEvs)
            {
                bool exists = false;
                foreach (var ev in this.Events())
                {
                    exists = exists || OsobaEvent.Compare(ev, dEv);
                }
                if (!exists)
                {
                    this.AddOrUpdateEvent(dEv, user);
                }
            }

            List <OsobaExternalId> addExternalIds = new List <OsobaExternalId>();

            foreach (var dEid in dEids)
            {
                bool exists = false;
                foreach (var eid in this.ExternalIds())
                {
                    exists = exists || (eid.ExternalId == dEid.ExternalId && eid.ExternalSource == dEid.ExternalSource && eid.OsobaId == dEid.OsobaId);
                }
                if (!exists)
                {
                    addExternalIds.Add(dEid);
                }
            }

            if (string.IsNullOrEmpty(this.TitulPred) && !string.IsNullOrEmpty(duplicated.TitulPred))
            {
                this.TitulPred = duplicated.TitulPred;
            }
            if (string.IsNullOrEmpty(this.Jmeno) && !string.IsNullOrEmpty(duplicated.Jmeno))
            {
                this.Jmeno = duplicated.Jmeno;
            }
            if (string.IsNullOrEmpty(this.Prijmeni) && !string.IsNullOrEmpty(duplicated.Prijmeni))
            {
                this.Prijmeni = duplicated.Prijmeni;
            }
            if (string.IsNullOrEmpty(this.TitulPo) && !string.IsNullOrEmpty(duplicated.TitulPo))
            {
                this.TitulPo = duplicated.TitulPo;
            }
            if (string.IsNullOrEmpty(this.Pohlavi) && !string.IsNullOrEmpty(duplicated.Pohlavi))
            {
                this.Pohlavi = duplicated.Pohlavi;
            }
            if (string.IsNullOrEmpty(this.Ulice) && !string.IsNullOrEmpty(duplicated.Ulice))
            {
                this.Ulice = duplicated.Ulice;
            }
            if (string.IsNullOrEmpty(this.Mesto) && !string.IsNullOrEmpty(duplicated.Mesto))
            {
                this.Mesto = duplicated.Mesto;
            }
            if (string.IsNullOrEmpty(this.PSC) && !string.IsNullOrEmpty(duplicated.PSC))
            {
                this.PSC = duplicated.PSC;
            }
            if (string.IsNullOrEmpty(this.CountryCode) && !string.IsNullOrEmpty(duplicated.CountryCode))
            {
                this.CountryCode = duplicated.CountryCode;
            }
            if (string.IsNullOrEmpty(this.PuvodniPrijmeni) && !string.IsNullOrEmpty(duplicated.PuvodniPrijmeni))
            {
                this.PuvodniPrijmeni = duplicated.PuvodniPrijmeni;
            }

            if (!this.Narozeni.HasValue && duplicated.Narozeni.HasValue)
            {
                this.Narozeni = duplicated.Narozeni;
            }
            if (!this.Umrti.HasValue && duplicated.Umrti.HasValue)
            {
                this.Umrti = duplicated.Umrti;
            }
            if (!this.OnRadar && duplicated.OnRadar)
            {
                this.OnRadar = duplicated.OnRadar;
            }

            if (this.Status < duplicated.Status)
            {
                this.Status = duplicated.Status;
            }

            if (duplicated.InternalId != 0)
            {
                duplicated.Delete(user);
            }

            //obrazek
            if (this.HasPhoto() == false && duplicated.HasPhoto())
            {
                foreach (var fn in new string[] { "small.jpg", "source.txt", "original.uploaded.jpg", "small.uploaded.jpg" })
                {
                    var from = Lib.Init.OsobaFotky.GetFullPath(duplicated, fn);
                    var to   = Lib.Init.OsobaFotky.GetFullPath(this, fn);
                    if (System.IO.File.Exists(from))
                    {
                        System.IO.File.Copy(from, to);
                    }
                }
            }
            this.Save(addExternalIds.ToArray());


            return(this);
        }
コード例 #10
0
 public static RegistrSmluv CachedStatistics(Osoba os, Relation.AktualnostType aktualnost, int?obor)
 {
     return(_cache.Get((os, (int)aktualnost, obor)));
 }
コード例 #11
0
        public static List <Edge> GetChildrenRelations(string sql,
                                                       Node.NodeType nodeType, string nodeId, DateTime?datumOd, DateTime?datumDo,
                                                       IDataParameter[] parameters, int level, bool goDeep,
                                                       Edge parent, ExcludeDataCol excludeICO, Relation.AktualnostType aktualnost)
        {
            if (excludeICO == null)
            {
                excludeICO = new ExcludeDataCol();
            }

            string cnnStr = Devmasters.Core.Util.Config.GetConfigValue("CnnString");

            List <Edge> relations = new List <Edge>();

            if (level == 0 && parent == null)
            {
                //add root node / edge
                relations.Add(
                    new Edge()
                {
                    From = null,
                    Root = true,
                    To   = new Node()
                    {
                        Id = nodeId, Type = nodeType
                    },
                    RelFrom  = datumOd,
                    RelTo    = datumDo,
                    Distance = 0
                }
                    );
            }
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.Core.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, parameters);
            //string sqlFirma = "select top 1 stav_subjektu from firma where ico = @ico";

            var ds = db.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sqlCall, null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                List <AngazovanostData> rows = new List <AngazovanostData>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    AngazovanostData angaz = null;
                    var ico = (string)dr["VazbakIco"];
                    if (string.IsNullOrEmpty(ico))
                    {
                        if (dr.Table.Columns.Contains("vazbakOsobaId"))
                        {
                            var vazbakOsobaId = (int?)PersistLib.IsNull(dr["vazbakOsobaId"], null);
                            if (vazbakOsobaId != null)
                            {
                                Osoba o = Osoby.GetById.Get(vazbakOsobaId.Value);
                                angaz = new AngazovanostData()
                                {
                                    subjId   = vazbakOsobaId.Value.ToString(),
                                    NodeType = Node.NodeType.Person,
                                    fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                                    toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                                    kod_ang  = Convert.ToInt32(dr["typVazby"]),
                                    descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                                    podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                                };
                            }
                        }
                    }
                    else
                    {
                        angaz = new AngazovanostData()
                        {
                            subjId   = ico,
                            subjname = "",
                            NodeType = Node.NodeType.Company,
                            fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                            toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                            kod_ang  = Convert.ToInt32(dr["typVazby"]),
                            descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                            podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                        };
                    }
                    rows.Add(angaz);
                }

                List <AngazovanostData> filteredRels = new List <AngazovanostData>();
                //delete vazby ve stejnem obdobi
                if (rows.Count > 0)
                {
                    //per ico
                    foreach (var gIco in rows.Select(m => m.subjId).Distinct())
                    {
                        var relsForIco = rows.Where(m => m.subjId == gIco);
                        //find longest, or separate relation
                        foreach (var r in relsForIco)
                        {
                            if (relsForIco
                                .Any(rr =>
                                     rr != r &&
                                     rr.fromDate < r.fromDate &&
                                     (rr.toDate > r.toDate || rr.toDate.HasValue == false)
                                     )
                                )
                            {
                                //skip
                            }
                            else
                            {
                                filteredRels.Add(r);
                            }
                        }
                    }
                }

                foreach (AngazovanostData ang in filteredRels.OrderBy(m => m.kod_ang))
                {
                    if (ang.kod_ang == 100) //souhrny (casove) vztah, zkontroluj, zda uz tam neni jiny vztah se stejnym rozsahem doby
                    {
                        if (
                            relations.Any(
                                r => r.To.Id == ang.subjId &&
                                r.To.Type == ang.NodeType &&
                                r.RelFrom == ang.fromDate &&
                                r.RelTo == ang.toDate
                                )
                            )
                        {
                            continue;
                        }
                    }
                    var rel = new Edge();

                    rel.From = new Node()
                    {
                        Type = nodeType, Id = nodeId
                    };
                    rel.To = new Node()
                    {
                        Type = ang.NodeType, Id = ang.subjId
                    };
                    rel.Distance = level + 1;

                    rel.RelFrom = (DateTime?)PersistLib.IsNull(ang.fromDate, null);
                    if (rel.RelFrom < minDate)
                    {
                        rel.RelFrom = null;
                    }

                    rel.RelTo = (DateTime?)PersistLib.IsNull(ang.toDate, null);
                    if (rel.RelTo < minDate)
                    {
                        rel.RelTo = null;
                    }
                    int kod_ang = ang.kod_ang;

                    /*
                     *     3  - prokura
                     *     4  - člen dozorčí rady
                     *     24 - spolecnik
                     *     5  - Jediný akcionář
                     *     1 - jednatel
                     *
                     */
                    rel.Descr = ang.descr;
                    Firma.RelationSimpleEnum relRelationship = Firma.RelationSimpleEnum.Jiny;
                    switch (kod_ang)
                    {
                    case 1:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                        }
                        break;

                    case 3:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Prokura.ToNiceDisplayName();
                        }
                        break;

                    case 4:
                    case 7:
                    case 2:
                    case 18:
                    case 25:
                    case 26:
                    case 28:
                    case 31:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Dozorci_rada.ToNiceDisplayName();
                        }
                        break;

                    case 33:
                    case 34:
                    case 35:
                        relRelationship = Firma.RelationSimpleEnum.Zakladatel;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Dozorci_rada.ToNiceDisplayName();
                        }
                        break;

                    case 5:
                    case 9:
                    case 10:
                    case 15:
                    case 19:
                    case 24:
                        relRelationship = Firma.RelationSimpleEnum.Spolecnik;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Spolecnik.ToNiceDisplayName();
                        }
                        break;

                    case 100:
                        relRelationship = Firma.RelationSimpleEnum.Souhrnny;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                        }
                        break;

                    case 23:    //
                    case 29:    //
                    case 11:    //
                    case 12:    //
                    case 13:    //
                    case 16:    //
                    case 17:    //
                    case 37:    //
                    case 40:    //
                    case 41:    //
                    case 42:    //
                    case 99:
                        relRelationship = Firma.RelationSimpleEnum.Jiny;
                        break;

                    default:

                        if (kod_ang < 0)
                        {
                            relRelationship = (Firma.RelationSimpleEnum)kod_ang;
                        }
                        else
                        {
                            //rel.Relationship = Relation.RelationDescriptionEnum.Jednatel;
                            relRelationship = Firma.RelationSimpleEnum.Jiny;
                            if (string.IsNullOrEmpty(rel.Descr))
                            {
                                rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                            }
                        }
                        break;
                    }

                    if (excludeICO.Contains(rel))
                    {
                        continue;//skip to the next
                    }
                    if (string.IsNullOrEmpty(rel.Descr))
                    {
                        rel.Descr = relRelationship.ToNiceDisplayName();
                    }

                    rel.UpdateAktualnost();

                    if (rel.Aktualnost >= aktualnost)
                    {
                        relations.Add(rel);
                    }
                }
            }

            if (goDeep && relations.Count > 0)
            {
                level++;
                List <Edge> deeperRels  = new List <Edge>();
                List <Edge> excludeMore = new List <Edge>();
                if (parent != null)
                {
                    excludeMore = relations.ToList();
                }

                ////navazej na ten, ktery je nejdelsi
                //var parentRels = relations.GroupBy(x => new { x.To.Id }, (key, rels) =>
                //{
                //    DateTime? fromDate = rels.Any(m => m.FromDate == null) ? (DateTime?)null : rels.Min(m => m.FromDate);
                //    DateTime? toDate = rels.Any(m => m.ToDate == null) ? (DateTime?)null : rels.Max(m => m.ToDate);
                //    Relation bestRelation = Relation.GetLongestRelation(rels);

                //    return new
                //    {
                //        SubjIco = key.To.Id,
                //        FromDate = fromDate,
                //        ToDate = toDate,
                //        BestRelation = bestRelation,
                //    };

                //});



                foreach (var rel in relations.Where(m => m.Root == false))
                {
                    //old
                    deeperRels.AddRange(

                        vsechnyDcerineVazbyInternal(rel.To.Id, level, goDeep, rel,
                                                    excludeICO.AddItem(new ExcludeData(rel)),
                                                    rel.RelFrom, rel.RelTo, aktualnost)
                        );
                }
                relations.AddRange(deeperRels);
            }

            if (level == 0)
            {
                //remove inactive companies from last branches
                //TODO
            }
            return(relations);
        }