Esempio n. 1
0
        public static IEnumerable <Graph.Edge> GetDirectParentRelationsOsoby(string ico)
        {
            string sql = @"select OsobaID, datumOd, datumDo, typVazby, pojmenovaniVazby, podil from osobavazby 
                        where vazbakico=@ico 
                    ";

            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");

            List <Graph.Edge> relations = new List <Graph.Edge>();
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, new IDataParameter[] {
                new SqlParameter("ico", ico)
            });
            //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)
            {
                var parents = ds.Tables[0].AsEnumerable()
                              .Select(dr => new AngazovanostData()
                {
                    subjId   = ((int)dr["osobaId"]).ToString(),
                    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)
                })
                              .ToArray();
                var ret = new List <Edge>();
                for (int i = 0; i < parents.Length; i++)
                {
                    AngazovanostData ang = parents[i];
                    var rel = AngazovanostDataToEdge(ang,
                                                     new Node()
                    {
                        Type = Node.NodeType.Person, Id = ang.subjId
                    },
                                                     new Node()
                    {
                        Type = Node.NodeType.Person, Id = ico
                    },
                                                     -1
                                                     );

                    ret.Add(rel);
                }
                return(Edge.GetLongestEdges(ret));
            }
            return(new Graph.Edge[] { });
        }
Esempio n. 2
0
        public static IEnumerable <Graph.Edge> GetParentRelations(string ico,
                                                                  IEnumerable <Graph.Edge> currRelations, int distance,
                                                                  DateTime datumOd, DateTime datumDo)
        {
            string sql = @"select ico, vazbakIco, datumOd, datumDo, typVazby, pojmenovaniVazby, podil from Firmavazby 
            where vazbakico=@ico 
            and dbo.IsSomehowInInterval(@datumOd, @datumDo, datumOd, datumDo) = 1
        ";

            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");

            List <Graph.Edge> relations = currRelations?.ToList() ?? new List <Graph.Edge>();
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, new IDataParameter[] {
                new SqlParameter("ico", ico),
                new SqlParameter("datumOd", datumOd),
                new SqlParameter("datumDo", datumDo),
            });
            //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)
            {
                var parentIcos = ds.Tables[0].AsEnumerable()
                                 .Select(dr => (string)dr["ico"])
                                 .Where(m => m != ico);


                foreach (var parentIco in parentIcos)
                {
                    var parentRels = vsechnyDcerineVazbyInternal(parentIco, 0, true, null,
                                                                 new ExcludeDataCol()
                    {
                        items = relations?.Select(m => new ExcludeData(m)).ToList()
                    }
                                                                 , datumOd: datumOd, datumDo: datumDo
                                                                 );
                    //move

                    //add edge with parent
                    var currEdge = new Edge()
                    {
                        From = new Node()
                        {
                        },
                        To = new Node()
                        {
                        },
                        RelFrom = datumOd,
                        RelTo   = datumDo,
                    };
                    currEdge.UpdateAktualnost();
                    relations.Add(currEdge);

                    if ((parentRels?.Count() ?? 0) > 0)
                    {
                        relations.AddRange(parentRels);
                    }
                }
                foreach (var parentIco in parentIcos)
                {
                    var parents = GetParentRelations(parentIco, relations, distance + 1, datumOd, datumDo);
                    relations.AddRange(parents);
                }
                return(relations);
            }
            return(new Graph.Edge[] { });
        }
Esempio n. 3
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, decimal minPodil, Relation.AktualnostType aktualnost)
        {
            if (excludeICO == null)
            {
                excludeICO = new ExcludeDataCol();
            }

            string cnnStr = Devmasters.Config.GetWebConfigValue("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.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 = AngazovanostDataToEdge(ang,
                                                     new Node()
                    {
                        Type = nodeType, Id = nodeId
                    },
                                                     new Node()
                    {
                        Type = ang.NodeType, Id = ang.subjId
                    },
                                                     level + 1
                                                     );


                    if (excludeICO.Contains(rel))
                    {
                        continue;//skip to the next
                    }
                    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, minPodil, aktualnost)
                        );
                }
                relations.AddRange(deeperRels);
            }

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