Exemplo n.º 1
0
        //obce
        private static List <Autocomplete> LoadCities()
        {
            string sql     = $@"select Jmeno, ICO, KrajId 
                             from Firma 
                            where IsInRS = 1 
                              AND LEN(ico) = 8
                              AND Stav_subjektu = 1 
                              AND Typ={(int)Firma.TypSubjektuEnum.Obec};";
            var    results = DirectDB.GetList <string, string, string>(sql)
                             .AsParallel()
                             .SelectMany(f =>
            {
                var synonyms = new Autocomplete[2];
                synonyms[0]  = new Autocomplete()
                {
                    Id           = $"ico:{f.Item2}",
                    Text         = f.Item1,
                    Type         = "obec",
                    Description  = FixKraj(f.Item3),
                    Priority     = 2,
                    ImageElement = "<i class='fas fa-industry-alt'></i>"
                };

                synonyms[1]        = (Autocomplete)synonyms[0].MemberwiseClone();
                string synonymText = Regex.Replace(f.Item1,
                                                   @"^(Město|Městská část|Městys|Obec|Statutární město) ?",
                                                   "",
                                                   RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                synonyms[1].Text = synonymText;
                return(synonyms);
            }).ToList();

            return(results);
        }
Exemplo n.º 2
0
        //používá se v administraci eventů pro naše politiky
        public static IEnumerable <Autocomplete> GenerateAutocompleteFirmyOnly()
        {
            string sql     = "select distinct Jmeno, ICO from Firma where LEN(ico) = 8 AND Kod_PF > 110;";
            var    results = DirectDB.GetList <string, string>(sql)
                             .Select(f => new Autocomplete()
            {
                Id   = f.Item2,
                Text = f.Item1
            }).ToList();

            return(results);
        }
Exemplo n.º 3
0
        private static List <Autocomplete> LoadSynonyms()
        {
            string sql     = $@"select text, query, type, priority, imageElement, description from AutocompleteSynonyms where active=1;";
            var    results = DirectDB.GetList <string, string, string, int, string, string>(sql)
                             .AsParallel()
                             .Select(f => new Autocomplete()
            {
                Id           = $"{f.Item2}",
                Text         = f.Item1,
                Type         = f.Item3,
                Description  = FixKraj(f.Item6),
                Priority     = f.Item4,
                ImageElement = f.Item5
            }).ToList();

            return(results);
        }
Exemplo n.º 4
0
        public static Lib.Data.Smlouva Load(string Id, ElasticClient client = null)
        {
            try
            {
                ElasticClient c = client;
                if (client == null)
                {
                    c = Lib.ES.Manager.GetESClient();
                }

                var res = c
                          .Get <Lib.Data.Smlouva>(Id);
                if (res.Found)
                {
                    return(res.Source);
                }
                else
                {
                    if (client == null)
                    {
                        c = GetESClient_Sneplatne();
                    }
                    res = c.Get <Lib.Data.Smlouva>(Id);
                    if (res.Found)
                    {
                        return(res.Source);
                    }
                    else
                    {
                        ESLogger.Warning("Cannot load Smlouva Id " + Id, res.OriginalException);
                        DirectDB.NoResult("delete from SmlouvyIds where id = @id", new System.Data.SqlClient.SqlParameter("id", Id));
                    }

                    return(null);
                }
            }
            catch (Exception e)
            {
                ESLogger.Error("Cannot load Smlouva Id " + Id, e);
                return(null);
            }
        }
Exemplo n.º 5
0
        private static List <Autocomplete> LoadCompanies()
        {
            // Kod_PF < 110  - cokoliv co nejsou fyzické osoby, podnikatelé
            // Podnikatelé nejsou zařazeni, protože je jich poté moc a vznikají tam duplicity

            string sql     = "select Jmeno, ICO from Firma where IsInRS = 1 AND LEN(ico) = 8 AND Kod_PF > 110;";
            var    results = DirectDB.GetList <string, string>(sql)
                             .Select(f => Firma.FromIco(f.Item2))
                             .AsParallel()
                             .Select(f => new Autocomplete()
            {
                Id           = $"ico:{f.ICO}",
                Text         = f.Jmeno,
                Type         = f.JsemOVM() ? "úřad" : "firma",
                Description  = FixKraj(f.KrajId),
                ImageElement = "<i class='fas fa-industry-alt'></i>"
            }).ToList();

            return(results);
        }
Exemplo n.º 6
0
        //úřady
        private static List <Autocomplete> LoadAuthorities()
        {
            string sql     = $@"select Jmeno, ICO, KrajId 
                             from Firma 
                            where IsInRS = 1 
                              AND LEN(ico) = 8 
                              AND Kod_PF > 110
                              AND Typ={(int)Firma.TypSubjektuEnum.Ovm};";
            var    results = DirectDB.GetList <string, string, string>(sql)
                             .AsParallel()
                             .Select(f => new Autocomplete()
            {
                Id           = $"ico:{f.Item2}",
                Text         = f.Item1,
                Type         = "úřad",
                Description  = FixKraj(f.Item3),
                Priority     = 2,
                ImageElement = "<i class='fas fa-university'></i>"
            }).ToList();

            return(results);
        }
Exemplo n.º 7
0
        //firmy
        private static List <Autocomplete> LoadCompanies()
        {
            // Kod_PF < 110  - cokoliv co nejsou fyzické osoby, podnikatelé
            // Podnikatelé nejsou zařazeni, protože je jich poté moc a vznikají tam duplicity
            string sql     = $@"select Jmeno, ICO, KrajId 
                             from Firma 
                            where LEN(ico) = 8 
                              AND Kod_PF > 110
                              AND (Typ is null OR Typ={(int)Firma.TypSubjektuEnum.Soukromy});";
            var    results = DirectDB.GetList <string, string, string>(sql)
                             .AsParallel()
                             .Select(f => new Autocomplete()
            {
                Id           = $"ico:{f.Item2}",
                Text         = f.Item1,
                Type         = "firma",
                Description  = FixKraj(f.Item3),
                Priority     = 0,
                ImageElement = "<i class='fas fa-industry-alt'></i>"
            }).ToList();

            return(results);
        }
Exemplo n.º 8
0
        //public static Nest.IIndexResponse Save(Person p, ElasticClient client = null)
        //{
        //    p.PrepareBeforeSave();
        //    if (client == null)
        //        client = Lib.ES.Manager.GetESClient();
        //    var res = client
        //        .Index<Lib.Data.Person>(p);
        //    return res;
        //}

        public static Nest.IIndexResponse Save(Lib.Data.Smlouva item, ElasticClient client = null)
        {
            if (item == null)
            {
                return(new Nest.IndexResponse());
            }

            item.PrepareBeforeSave();
            ElasticClient c = client;

            if (c == null)
            {
                if (item.platnyZaznam)
                {
                    c = Lib.ES.Manager.GetESClient();
                }
                else
                {
                    c = Lib.ES.Manager.GetESClient_Sneplatne();
                }
            }
            var res = c
                      //.Update<Lib.Data.Smlouva>()
                      .Index <Lib.Data.Smlouva>(item, m => m.Id(item.Id));

            if (item.platnyZaznam == false && res.IsValid && client == null)
            {
                //zkontroluj zda neni v indexu s platnymi. pokud ano, smaz ho tam
                var cExist = GetESClient();
                var s      = Manager.Load(item.Id, cExist);
                if (s != null)
                {
                    Delete(item.Id, cExist);
                }
            }

            if (res.IsValid)
            {
                try
                {
                    DirectDB.NoResult("exec smlouvaId_save @id,@active, @created, @updated",
                                      new System.Data.SqlClient.SqlParameter("id", item.Id),
                                      new System.Data.SqlClient.SqlParameter("created", item.casZverejneni),
                                      new System.Data.SqlClient.SqlParameter("updated", item.LastUpdate),
                                      new System.Data.SqlClient.SqlParameter("active", item.znepristupnenaSmlouva() ? (int)0 : (int)1)
                                      );
                }
                catch (Exception e)
                {
                    ESLogger.Error("Manager Save", e);
                }



                if (!string.IsNullOrEmpty(item.Platce?.ico))
                {
                    DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                      new System.Data.SqlClient.SqlParameter("ico", item.Platce?.ico)
                                      );
                }
                if (!string.IsNullOrEmpty(item.VkladatelDoRejstriku?.ico))
                {
                    DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                      new System.Data.SqlClient.SqlParameter("ico", item.VkladatelDoRejstriku?.ico)
                                      );
                }
                foreach (var s in item.Prijemce ?? new Data.Smlouva.Subjekt[] { })
                {
                    if (!string.IsNullOrEmpty(s.ico))
                    {
                        DirectDB.NoResult("exec Firma_IsInRS_Save @ico",
                                          new System.Data.SqlClient.SqlParameter("ico", s.ico)
                                          );
                    }
                }
            }
            return(res);
        }