private static void PersistOrgTree(OrgTreeItem item, OrgTreeItem rootItem, List <OrgTreeItem> pathItems) { item.selected = true; item.expanded = true; string orgtreeJson = new JavaScriptSerializer().Serialize(rootItem); // update item where sourcestr70 = item.duns and set varchar item.selected = false; item.expanded = item.items.Count > 0; //if (null != parentItem && item.items.Count == 0) if (item.items.Count == 0) { for (int i = pathItems.Count - 1; i > 0; i--) { OrgTreeItem checkItem = pathItems[i]; OrgTreeItem parentItem = pathItems[i - 1]; if (parentItem.items.Last().duns.Equals(checkItem.duns)) { parentItem.expanded = false; pathItems.RemoveAt(i); } else { pathItems.RemoveAt(i); break; } } //pathItems.Clear(); } for (int i = 0; i < item.items.Count; i++) { Console.WriteLine(i); pathItems.Add(item.items[i]); PersistOrgTree(item.items[i], rootItem, pathItems); //if (item.items.Count == i) //{ // PersistOrgTree(item.items[i], rootItem, pathItems); //} //else //{ // PersistOrgTree(item.items[i], rootItem, pathItems); //} } }
//private void ExpandPath(OrgTreeItem item) //{ // item.expanded = true; // if (!item.duns.Equals(item.parentDuns)) // { // return currentItem; // } // foreach (OrgTreeItem child in item.items) // { // return FindItemByDuns(child, duns); // } // return null; //} //private static void PersistOrgTree(OrgTreeItem item, OrgTreeItem rootItem) //{ // OrgTreeItem itemClone = (OrgTreeItem)rootItem.Clone(); // item.selected = true; // item.expanded = true; // string orgtreeJson = new JavaScriptSerializer().Serialize(rootItem); // // update item where sourcestr70 = item.duns and set varchar // foreach (OrgTreeItem child in item.items) // { // PersistOrgTree(child, itemClone); // } //} private static void BuildOrgTree(OrgTreeItem item, List <LdbItem> newLDBItems, OrgTreeItem root) { List <LdbItem> childItems = newLDBItems.Where(x => x.HqDuns.Equals(item.duns) && !x.Duns.Equals(x.GuDuns)).ToList(); foreach (LdbItem child in childItems) { OrgTreeItem childOrgItem = new OrgTreeItem(); childOrgItem.duns = child.Duns; childOrgItem.label = child.Name; item.items.Add(childOrgItem); root.count++; BuildOrgTree(childOrgItem, newLDBItems, root); } }
private static void ReadCsvNewLdbOrgTree() { List <LdbItem> newLDBItems = new List <LdbItem>(); //using (StreamReader sr = new StreamReader(@"C:\kpl\export3rootCompanyB.csv")) //using (StreamReader sr = new StreamReader(@"D:\kpl\export3rootCompanyB.csv")) using (StreamReader sr = new StreamReader(@"D:\kpl\exportFriedeSpringer.csv")) { string currentLine; // currentLine will be null when the StreamReader reaches the end of file while ((currentLine = sr.ReadLine()) != null) { string[] coulumns = currentLine.Split(new char[] { ';' }); LdbItem item = new LdbItem(); item.Duns = CleanInput(coulumns[0]); item.Name = CleanInput(coulumns[1]); item.HqDuns = CleanInput(coulumns[2]); item.HqName = CleanInput(coulumns[3]); item.GuDuns = CleanInput(coulumns[4]); item.GuName = CleanInput(coulumns[5]); newLDBItems.Add(item); } } // get GUCs List <LdbItem> gucItems = newLDBItems.Where(x => x.GuDuns.Equals(x.Duns)).ToList(); List <OrgTreeItem> rootItems = new List <OrgTreeItem>(); foreach (LdbItem item in gucItems) { OrgTreeItem orgItem = new OrgTreeItem(); orgItem.duns = item.Duns; orgItem.label = item.Name; rootItems.Add(orgItem); List <LdbItem> famillyItems = newLDBItems.Where(x => x.GuDuns.Equals(orgItem.duns)).ToList(); BuildOrgTree(orgItem, famillyItems, orgItem); List <OrgTreeItem> path = new List <OrgTreeItem>(); path.Add(orgItem); PersistOrgTree(orgItem, orgItem, path); } foreach (OrgTreeItem item in rootItems) { //PersistOrgTree(item, item); //item.selected = true; //item.expanded = true; //string orgtreeJson = new JavaScriptSerializer().Serialize(item); // update item where gud = item.duns and set varchar } }
private static void DisplayWrongItems(OrgTreeItem item, List <LdbItem> newLDBItems, string gud) { foreach (OrgTreeItem child in item.items) { LdbItem childItem = newLDBItems.FirstOrDefault(x => x.Duns.Equals(child.duns)); if (childItem != null && !childItem.GuDuns.Equals(gud)) { string wrongItem = $"root:{gud} duns:{childItem.Duns}, parent:{childItem.HqDuns}, gud:{childItem.GuDuns}"; Console.WriteLine(wrongItem); } DisplayWrongItems(child, newLDBItems, gud); } }
private static void CheckProblems() { List <LdbItem> newLDBItems = new List <LdbItem>(); using (StreamReader sr = new StreamReader(@"C:\kpl\newLdbFull.csv")) { string currentLine; // currentLine will be null when the StreamReader reaches the end of file while ((currentLine = sr.ReadLine()) != null) { string[] coulumns = currentLine.Split(new char[] { ';' }); LdbItem item = new LdbItem(); item.Duns = CleanInput(coulumns[0]); item.Name = CleanInput(coulumns[1]); item.HqDuns = CleanInput(coulumns[2]); item.HqName = CleanInput(coulumns[3]); item.GuDuns = CleanInput(coulumns[4]); item.GuName = CleanInput(coulumns[5]); newLDBItems.Add(item); } } // get GUCs List <LdbItem> gucItems = newLDBItems.Where(x => x.GuDuns.Equals(x.Duns)).ToList(); List <OrgTreeItem> rootItems = new List <OrgTreeItem>(); foreach (LdbItem item in gucItems) { OrgTreeItem orgItem = new OrgTreeItem(); orgItem.duns = item.Duns; orgItem.label = item.Name; rootItems.Add(orgItem); BuildOrgTree(orgItem, newLDBItems.Where(x => x.GuDuns.Equals(orgItem.duns)).ToList(), orgItem); } foreach (OrgTreeItem item in rootItems.Where(x => x.items.Count > 0)) { DisplayWrongItems(item, newLDBItems, item.duns);; //foreach (OrgTreeItem child in item.items) //{ // LdbItem childItem = newLDBItems.FirstOrDefault(x=> x.duns.Equals(child.duns)); // if (childItem != null && !childItem.GuDuns.Equals(item.duns)) // { // string wrongItem = $"duns:{childItem.duns}, parent:{childItem.HqDuns}, gud:{childItem.GuDuns}"; // Console.WriteLine(wrongItem); // } //} } }
private static OrgTreeItem FindItemByDuns(OrgTreeItem item, string duns, OrgTreeItem result) { //Console.WriteLine(item.duns); if (item.duns.Equals(duns)) { return(item); } foreach (OrgTreeItem child in item.items) { return(FindItemByDuns(child, duns, result)); } return(null); }
//private static OrgTreeItem FindItemByDuns2(OrgTreeItem item, string duns) //{ // OrgTreeItem currentItem = item.items.FirstOrDefault(x => x.duns.Equals(duns)); // if (currentItem != null) // { // item.expanded = true; // return currentItem; // } // foreach (OrgTreeItem child in item.items) // { // return FindItemByDuns(child, duns); // } // return null; //} private static void FindItemByDuns3(OrgTreeItem item, string duns, OrgTreeItem result) { OrgTreeItem currentItem = item.items.FirstOrDefault(x => x.duns.Equals(duns)); if (currentItem != null) { item.expanded = true; result = currentItem; } else { foreach (OrgTreeItem child in item.items) { FindItemByDuns(child, duns, result); } } }
private static void FixOrphans() { List <LdbItem> newLDBItems = new List <LdbItem>(); using (StreamReader sr = new StreamReader(@"C:\kpl\newLdbFull.csv")) { string currentLine; // currentLine will be null when the StreamReader reaches the end of file while ((currentLine = sr.ReadLine()) != null) { string[] coulumns = currentLine.Split(new char[] { ';' }); LdbItem item = new LdbItem(); item.Duns = CleanInput(coulumns[0]); item.Name = CleanInput(coulumns[1]); item.HqDuns = CleanInput(coulumns[2]); item.HqName = CleanInput(coulumns[3]); item.GuDuns = CleanInput(coulumns[4]); item.GuName = CleanInput(coulumns[5]); newLDBItems.Add(item); } } List <OrgTreeItem> rootItems = new List <OrgTreeItem>(); //test orphan LdbItem orphanitem = newLDBItems.FirstOrDefault(x => x.Duns.Equals("31-606-7164")); OrgTreeItem orgItem = new OrgTreeItem(); orgItem.duns = orphanitem.Duns; orgItem.label = orphanitem.Name; rootItems.Add(orgItem); List <LdbItem> famillyItems = newLDBItems.Where(x => x.GuDuns.Equals(orgItem.duns)).ToList(); List <string> famillyDuns = famillyItems.Select(x => x.Duns).ToList(); List <LdbItem> orphanItems = famillyItems.Where(x => !famillyDuns.Contains(x.HqDuns)).ToList(); foreach (LdbItem orphan in orphanItems.Where(x => !x.OutOfBusiness).ToList()) { orphan.HqDuns = orphan.GuDuns; } BuildOrgTree(orgItem, famillyItems, orgItem); // get GUCs //List<LdbItem> gucItems = newLDBItems.Where(x => x.GuDuns.Equals(x.Duns)).ToList(); //foreach (LdbItem item in gucItems) //{ // OrgTreeItem orgItem = new OrgTreeItem(); // orgItem.duns = item.Duns; // orgItem.label = item.Name; // rootItems.Add(orgItem); // BuildOrgTree(orgItem, newLDBItems.Where(x => x.GuDuns.Equals(orgItem.duns)).ToList(), orgItem); //} foreach (OrgTreeItem item in rootItems.Where(x => x.items.Count > 0)) { DisplayWrongItems(item, newLDBItems, item.duns);; //foreach (OrgTreeItem child in item.items) //{ // LdbItem childItem = newLDBItems.FirstOrDefault(x=> x.duns.Equals(child.duns)); // if (childItem != null && !childItem.GuDuns.Equals(item.duns)) // { // string wrongItem = $"duns:{childItem.duns}, parent:{childItem.HqDuns}, gud:{childItem.GuDuns}"; // Console.WriteLine(wrongItem); // } //} } }