private static Tuple <Firma.RelationSimpleEnum, string> AngazovanostDataToRelationSimple(AngazovanostData ang) { Firma.RelationSimpleEnum relRelationship = Firma.RelationSimpleEnum.Jiny; string descr = ang.descr; /* * 3 - prokura * 4 - člen dozorčí rady * 24 - spolecnik * 5 - Jediný akcionář * 1 - jednatel */ switch (ang.kod_ang) { case 1: relRelationship = Firma.RelationSimpleEnum.Statutarni_organ; if (string.IsNullOrEmpty(descr)) { descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName(); } break; case 3: relRelationship = Firma.RelationSimpleEnum.Statutarni_organ; if (string.IsNullOrEmpty(descr)) { 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(descr)) { descr = Firma.RelationSimpleEnum.Dozorci_rada.ToNiceDisplayName(); } break; case 33: case 34: case 35: relRelationship = Firma.RelationSimpleEnum.Zakladatel; if (string.IsNullOrEmpty(descr)) { 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(descr)) { descr = Firma.RelationSimpleEnum.Spolecnik.ToNiceDisplayName(); } break; case 100: relRelationship = Firma.RelationSimpleEnum.Souhrnny; if (string.IsNullOrEmpty(descr)) { 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 (ang.kod_ang < 0) { relRelationship = (Firma.RelationSimpleEnum)ang.kod_ang; } else { //rel.Relationship = Relation.RelationDescriptionEnum.Jednatel; relRelationship = Firma.RelationSimpleEnum.Jiny; if (string.IsNullOrEmpty(descr)) { descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName(); } } break; } return(new Tuple <Firma.RelationSimpleEnum, string>(relRelationship, descr)); }
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); }