public int Compare(object x, object y) { InvoiceHeaderGroup inv1 = (InvoiceHeaderGroup)x; InvoiceHeaderGroup inv2 = (InvoiceHeaderGroup)y; if (inv1 != null && inv2 != null) { if (inv1.Compare(inv1, inv2) != 0) { //parse.elementList.Insert(0, "InvoiceHeaderGroup"); //Invg.Insert(0 , new KeyValuePair<string, List<string>>("InvoiceGroup", )); Invg.Insert(0, new KeyValuePair <string, List <string> >("InvoiceGroup", InvoiceHeaderGroup.Invhdrgrp)); return(-1); } else { return(0); } } return(1); }
public int Compare(object x, object y) { bool result = true; InvoiceHeaderGroup invHdr1 = (InvoiceHeaderGroup)x; InvoiceHeaderGroup invHdr2 = (InvoiceHeaderGroup)y; if (invHdr1 != null && invHdr2 != null) { if (invHdr1.InvoiceNumber != invHdr2.InvoiceNumber) { parse.elementList.Insert(0, "InvoiceNumber"); Invhdrgrp.Insert(0, "InvoiceNumber"); } if (invHdr1.InvoiceType != invHdr2.InvoiceType) { parse.elementList.Insert(0, "InvoiceType"); Invhdrgrp.Insert(0, "InvoiceType"); } if (invHdr1.InvoiceResend != invHdr2.InvoiceResend) { Invhdrgrp.Insert(0, "InvoiceResend"); parse.elementList.Insert(0, "InvoiceResend"); } if (invHdr1.OrderShipmentStatus != invHdr2.OrderShipmentStatus) { parse.elementList.Insert(0, "OrderShipmentStatus"); Invhdrgrp.Insert(0, "OrderShipmentStatus"); } if (invHdr1.InvoiceDate != invHdr2.InvoiceDate) { parse.elementList.Insert(0, "InvoiceDate"); Invhdrgrp.Insert(0, "InvoiceDate"); } if (invHdr1.SalesOrderNumber != invHdr2.SalesOrderNumber) { parse.elementList.Insert(0, "SalesOrderNumber"); Invhdrgrp.Insert(0, "SalesOrderNumber"); } if (invHdr1.SalesOrderDate != invHdr2.SalesOrderDate) { parse.elementList.Insert(0, "SalesOrderDate"); Invhdrgrp.Insert(0, "SalesOrderDate"); } if (invHdr1.PurchaseOrderNumber != invHdr2.PurchaseOrderNumber) { parse.elementList.Insert(0, "PurchaseOrderNumber"); Invhdrgrp.Insert(0, "PurchaseOrderNumber"); } if (invHdr1.RedTailPOID != invHdr2.RedTailPOID) { parse.elementList.Insert(0, "RedTailPOID"); Invhdrgrp.Insert(0, "RedTailPOID"); } if (invHdr1.CurrencyCode != invHdr2.CurrencyCode) { parse.elementList.Insert(0, "CurrencyCode"); Invhdrgrp.Insert(0, "CurrencyCode"); } if (invHdr1.InvoiceAmount != invHdr2.InvoiceAmount) { parse.elementList.Insert(0, "InvoiceAmount"); Invhdrgrp.Insert(0, "InvoiceAmount"); } if (invHdr1.TaxAmount != invHdr2.TaxAmount) { parse.elementList.Insert(0, "TaxAmount"); Invhdrgrp.Insert(0, "TaxAmount"); } if (invHdr1.FreightAmount != invHdr2.FreightAmount) { parse.elementList.Insert(0, "FreightAmount"); Invhdrgrp.Insert(0, "FreightAmount"); } if (invHdr1.MiscChargeAmount != invHdr2.MiscChargeAmount) { parse.elementList.Insert(0, "MiscChargeAmount"); Invhdrgrp.Insert(0, "MiscChargeAmount"); } if (invHdr1.SalesDiscAmount != invHdr2.SalesDiscAmount) { parse.elementList.Insert(0, "SalesDiscAmount"); Invhdrgrp.Insert(0, "SalesDiscAmount"); } if (invHdr1.TermsDescription != invHdr2.TermsDescription) { parse.elementList.Insert(0, "TermsDescription"); Invhdrgrp.Insert(0, "TermsDescription"); } if (invHdr1.TermsDiscountPercent != invHdr2.TermsDiscountPercent) { parse.elementList.Insert(0, "TermsDiscountPercent"); Invhdrgrp.Insert(0, "TermsDiscountPercent"); } if (invHdr1.TermsDiscountDays != invHdr2.TermsDiscountDays) { parse.elementList.Insert(0, "TermsDiscountDays"); Invhdrgrp.Insert(0, "TermsDiscountDays"); } if (invHdr1.TermsNetDueDays != invHdr2.TermsNetDueDays) { parse.elementList.Insert(0, "TermsNetDueDays"); Invhdrgrp.Insert(0, "TermsNetDueDays"); } if (invHdr1.TermsDiscountDate != invHdr2.TermsDiscountDate) { parse.elementList.Insert(0, "TermsDiscountDate"); Invhdrgrp.Insert(0, "TermsDiscountDate"); } if (invHdr1.TermsNetDueDate != invHdr2.TermsNetDueDate) { parse.elementList.Insert(0, "TermsNetDueDate"); Invhdrgrp.Insert(0, "TermsNetDueDate"); } if (invHdr1.TermsDiscountBasis != invHdr2.TermsDiscountBasis) { parse.elementList.Insert(0, "TermsDiscountBasis"); Invhdrgrp.Insert(0, "TermsDiscountBasis"); } if (invHdr1.TermsDiscountAmount != invHdr2.TermsDiscountAmount) { parse.elementList.Insert(0, "TermsDiscountAmount"); Invhdrgrp.Insert(0, "TermsDiscountAmount"); } if (invHdr1.NetInvoiceAmount != invHdr2.NetInvoiceAmount) { parse.elementList.Insert(0, "NetInvoiceAmount"); Invhdrgrp.Insert(0, "NetInvoiceAmount"); } if (invHdr1.ShipVia != invHdr2.ShipVia) { parse.elementList.Insert(0, "ShipVia"); Invhdrgrp.Insert(0, "ShipVia"); } //if(!parse.line.Contains(invHdr1.AddressGroup.Addresses[0].EntityIDCode) && // !parse.line.Contains(invHdr2.AddressGroup.Addresses[0].EntityIDCode)) //if (invHdr1.AddressGroup.Addresses[0].EntityIDCode != "SF" && //invHdr2.AddressGroup.Addresses[0].EntityIDCode != "SF") { if (invHdr1.AddressGroup.Compare(invHdr1.AddressGroup, invHdr2.AddressGroup) != 0) { //ihg.Insert(0, new KeyValuePair<string, List<string>>("AddressGroup", Address.addr)); //ihg.Insert result = false; //parse.elementList.Insert(0, addr); } } //if(!parse.line.Contains(CommentGroup) && ) //string obj = invHdr2.InvoiceItemGrouprr[0].CommentGroup.ToString(); //string obj2 = obj.Remove(0, 12); //if (invHdr1.CommentGroup != null) //{ // string objx = invHdr1.InvoiceItemGrouprr[0].CommentGroup.ToString(); //} //string obj1 = objx.Remove(0, 12); //if (!parse.line.Contains(obj1) && !parse.line.Contains(obj2)) if ((invHdr1.CommentGroup != null && invHdr2.CommentGroup == null) || (invHdr2.CommentGroup != null && invHdr1.CommentGroup == null)) { parse.elementList.Insert(0, "CommentGroup"); } else if (invHdr1.CommentGroup == null && invHdr2.CommentGroup == null) { } else { invHdr1.CommentGroup.Compare(invHdr1.CommentGroup, invHdr2.CommentGroup); } if (invHdr1.InvoiceItemGrouprr != null && invHdr2.InvoiceItemGrouprr != null && invHdr1.InvoiceItemGrouprr.Count == invHdr2.InvoiceItemGrouprr.Count) { for (int i = 0; i < invHdr1.InvoiceItemGrouprr.Count; i++) { if (invHdr1.InvoiceItemGrouprr[i].Compare(invHdr1.InvoiceItemGrouprr[i], invHdr2.InvoiceItemGrouprr[i]) != 0) { //if(LotRecord.lotr.Count > 0) result = false; //parse.elementList.Insert(0,ihg.Insert(0, new KeyValuePair<string, List<string>>("InvoiceItemGroup", InvoiceHeaderGroup.Invhdrgrp)); "InvoiceItemGroup"); } } } if (CommentGroup != null) { if (CommentGroup.cmnt.Count > 0) { ihg.Insert(0, new KeyValuePair <string, List <string> >("<CommentGroup>", CommentGroup.cmnt)); } } if (LotRecord.lotr.Count > 0) { ihg.Insert(0, new KeyValuePair <string, List <string> >("<LotGroup>", LotRecord.lotr)); } if (InvoiceItemGroup.InvItmGrp.Count > 0) { ihg.Insert(0, new KeyValuePair <string, List <string> >("<InvoiceItemGroup>", InvoiceItemGroup.InvItmGrp)); } if (Address.addr.Count > 0) { ihg.Insert(0, new KeyValuePair <string, List <string> >("<AddressGroup>", Address.addr)); } if (Invhdrgrp.Count > 0) { ihg.Insert(0, new KeyValuePair <string, List <string> >("<InvoiceHeaderGroup>", InvoiceHeaderGroup.Invhdrgrp)); } } else if (invHdr1 == null && invHdr2 == null) { result = true; } else { result = false; } return(result ? 0 : 1); }
static void ain(string[] args) { //Console.WriteLine("Enter Target Path"); //string targetPath = Console.ReadLine(); //Console.WriteLine("Enter Source Path"); //string sourcePath = Console.ReadLine(); //Console.WriteLine("Enter Result File Path"); //string resultFilePath = Console.ReadLine(); //Console.WriteLine("Enter the path for Hiearchy File"); //string Hiearchy = Console.ReadLine(); var path1 = "C:\\Users\\schaturvedi\\Downloads\\child.xml"; XDocument doc1 = XDocument.Load(path1); var alle = doc1.Descendants(); var file1 = Program.DeSerialize(path1); string sorted = Program.GetSortedXML(path1); string original = Program.GetOriginalXML(path1); Program.FillNodesAtKey(Program.GetXDOC(sorted).Root); string targetPath = @"C:\Users\schaturvedi\Downloads\Invoices (1) (1)\Invoices (1)"; string sourcePath = @"C:\Users\schaturvedi\Downloads\810_20200131_032553"; string resultFilePath = @"C:\Users\schaturvedi\Desktop\Test\Result.txt"; string Hiearchy = @"C:\Users\schaturvedi\Downloads\hiearchy.txt"; string[] sourceFile = Directory.GetFiles(sourcePath, "*.xml"); //string[] HiearchyFile = Directory.GetFiles(HiearchyPath, "*.xml"); //List<InvoiceHeaderGroup> Hir = new List<InvoiceHeaderGroup>(); var Source = DeSerialize(sourceFile[0]); //var Hiearchy = DeSerialize(HiearchyFile[0]); //Dictionary<string, string> pt = new Dictionary<string, string>(); //string contents = File.ReadAllText(@"C:\Users\schaturvedi\Downloads\hiearchy.txt"); //var lines = File.ReadLines(@"C:\Users\schaturvedi\Downloads\hiearchy.txt"); //string[] vc = lines.ToArray(); //vc = vc.Where(x => !string.IsNullOrEmpty(x)).ToArray(); //List<string> temp = new List<string>(); //foreach(var v in vc) //{ // if (v.Length > 3) // temp.Add(v); //} //vc = temp.ToArray(); //List<string[]> lineList = lines.ToList(); //pt = File.ReadLines(@"C:\Users\schaturvedi\Downloads\hiearchy.txt").ToDictionary(k => k[0], v => v[1]); var SourceInvoices = Source?.InvoiceGroup?.ToDictionary(x => x.InvoiceHeaderGroup.InvoiceNumber, x => x.InvoiceHeaderGroup); //var HiearchyInvoices = Hiearchy?.InvoiceGroup?.ToDictionary(x => x.InvoiceHeaderGroup.InvoiceNumber, x => x.InvoiceHeaderGroup); //InvoiceHeaderGroup hire = Hiearchy.InvoiceGroup. //var HiearchyInvoices = Hiearchy?.InvoiceGroup?(x => x.InvoiceHeaderGroup) Dictionary <string, InvoiceHeaderGroup> TargetInvoices = new Dictionary <string, InvoiceHeaderGroup>(); string[] targetFiles = Directory.GetFiles(targetPath, "*.xml"); foreach (var t in targetFiles) { var TargetInvoice = DeSerialize(t); if (!TargetInvoices.ContainsKey(TargetInvoice.InvoiceGroup[0].InvoiceHeaderGroup.InvoiceNumber)) { TargetInvoices.Add(TargetInvoice.InvoiceGroup[0].InvoiceHeaderGroup.InvoiceNumber, TargetInvoice.InvoiceGroup[0].InvoiceHeaderGroup); } } // List<KeyValuePair<string, string>> res = new List<KeyValuePair<string, string>>(); List <string> availableInTargetAbsetInSource = new List <string>(); availableInTargetAbsetInSource = TargetInvoices.Keys.Except(SourceInvoices.Keys).ToList(); List <string> availableInSourceAbsentInTarget = new List <string>(); availableInSourceAbsentInTarget = SourceInvoices.Keys.Except(TargetInvoices.Keys).ToList(); availableInTargetAbsetInSource.ForEach(x => TargetInvoices.Remove(x)); availableInSourceAbsentInTarget.ForEach(x => SourceInvoices.Remove(x)); using (StreamReader sr = new StreamReader(Hiearchy)) { line = sr.ReadToEnd(); } //Code=2 when Invoice is available in meta but not in target //List<string> availableInMasterAbsentInTarget = new List<string>(); //availableInMasterAbsentInTarget = parentInvoices.Keys.Except(childInvoices.Keys).ToList(); // res.AddRange(availableInMasterAbsentInTarget.Select(x => new KeyValuePair<string, string>(x, "Invoice is available in source but not in target")).ToList()); //availableInMasterAbsentInTarget.ForEach(x => parentInvoices.Remove(x)); //Code=3 when Invoice is available in target but not in meta //List<string> availableInTargetAbsentInMaster = new List<string>(); //availableInTargetAbsentInMaster = childInvoices.Keys.Except(parentInvoices.Keys).ToList(); //res.AddRange(availableInTargetAbsentInMaster.Select(x => new KeyValuePair<string, string>(x, "Invoice is available in target but not in source")).ToList()); //availableInTargetAbsentInMaster.ForEach(x => childInvoices.Remove(x)); foreach (KeyValuePair <string, InvoiceHeaderGroup> entry in TargetInvoices) { string key = entry.Key; InvoiceHeaderGroup value = entry.Value; InvoiceHeaderGroup par = SourceInvoices[key]; //InvoiceHeaderGroup Hir = HiearchyInvoices[key; AddressGroup obj = new AddressGroup(); InvoiceItemGroup IIG = new InvoiceItemGroup(); LotGroup lt = new LotGroup(); LotRecord lr = new LotRecord(); InvoiceGroup ig = new InvoiceGroup(); InvoiceHeaderGroup h = entry.Value; //foreach (KeyValuePair<string, InvoiceHeaderGroup> ent in HiearchyInvoices) //{ // h = ent.Value; //} { if (ig.Compare(par, value) != 0) { //result.Insert(0, new KeyValuePair<string, List< KeyValuePair<string, List<string>>>>("<InvoiceGroup>", InvoiceHeaderGroup.ihg)); if (elementList.Count > 0) { final.Insert(0, new KeyValuePair <string, List <string> >(key, elementList)); } elementList = new List <string>(); } } //} } /* using (StreamWriter writer = new StreamWriter(resultFilePath)) * * { * foreach (var x in result) * { * writer.WriteLine(x); * } * * }*/ var dir = @"C:\Test\testing"; // folder location if (!Directory.Exists(dir)) // if it doesn't exist, create { Directory.CreateDirectory(dir); } // use Path.Combine to combine 2 strings to a path var filename = "Testing.txt"; dir = System.IO.Path.Combine(dir, filename); File.Create(dir); /* using (StreamWriter writer = new StreamWriter(resultFilePath)) * { * Console.WriteLine("Invoices Present in Target but not in Source"); * foreach(var invoice in availableInTargetAbsetInSource) * { * writer.WriteLine(invoice); * } * Console.WriteLine("\n"); * } * * using (StreamWriter writer = new StreamWriter(resultFilePath)) * { * Console.WriteLine("Invoices Present in Source not in Target"); * foreach (var invoice in availableInSourceAbsentInTarget) * { * writer.WriteLine(invoice); * } * Console.WriteLine("\n"); * * }*/ using (StreamWriter writer = new StreamWriter(resultFilePath)) { for (int i = 0; i < final.Count; i++) { var rt = final[i].Value.Distinct().ToList(); writer.WriteLine(final[i].Key); if (rt.Count > 1) { for (int y = 0; y < rt.Count; y++) { writer.WriteLine(rt[y]); } } else { writer.WriteLine(final[i].Value[0]); } } // for (int y = 0; y < rt.Count; y++) // for (int i=0;i<result.Count;i++) // { // var rt = result[i].Value.Distinct().ToList(); // writer.WriteLine(result[i].Key); // if (rt.Count > 1 ) // { // for(int y =0 ; y<rt.Count; y++) // { // if(y==rt.Count-1) // { // writer.WriteLine(rt[y].Key); // for (int k = 0; k < rt[y].Value.Count; k++) // { // writer.WriteLine(rt[y].Value[k]); // } // break; // } // else if(rt[y].Key != rt[y+1].Key) // writer.WriteLine(rt[y].Key); // for( int k=0;k<rt[y].Value.Count;k++) // { // writer.WriteLine(rt[y].Value[k]); // } // } // } // else // { // writer.WriteLine(result[i].Value[0]); // } // } } }