public MainWindow() { InitializeComponent(); IList <DelimitedFileInfo> currentInventoryFileNames = new List <DelimitedFileInfo>() { new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products_shopify_inventory.latest.csv", "sku", "^\\w{4}\\d{8}") }; IList <DelimitedFileInfo> oldInventoryFileNames = new List <DelimitedFileInfo>() { new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products_shopify_inventory.old.csv", "sku", "^\\w{4}\\d{8}") }; DelimitedFile oldInventoryFile = new DelimitedFile(); foreach (DelimitedFileInfo file in oldInventoryFileNames) { oldInventoryFile.LoadFileLines(file.FullName, HeaderNames, file.RegExLineIdentifierPattern, KeyName); } DelimitedFile newInventoryFile = new DelimitedFile(); foreach (DelimitedFileInfo file in currentInventoryFileNames) { newInventoryFile.LoadFileLines(file.FullName, HeaderNames, file.RegExLineIdentifierPattern, KeyName); } IList <DelimitedFileRow> changedProductInventoryQts = DelimitedFile.Compare(oldInventoryFile, newInventoryFile); if (changedProductInventoryQts.Count > 0) { IList <DelimitedFileRow> inventoryRows = new List <DelimitedFileRow>(); foreach (DelimitedFileRow data in changedProductInventoryQts) { DelimitedFileColumn keyColumn = data[KeyName]; String keyNameValue = DelimitedFile.GetKey(keyColumn.Value.ToString()); var oldCSVData = oldInventoryFile.GetRowByKeyName(keyNameValue); //.Query(csvData => csvData.GetColumnValue(KeyName) == data.GetColumnValue(KeyName)).FirstOrDefault(); var newCSVData = newInventoryFile.GetRowByKeyName(keyNameValue); //.Query(csvData => csvData.GetColumnValue(KeyName) == data.GetColumnValue(KeyName)).FirstOrDefault(); if (!(oldCSVData is null) && !(newCSVData is null)) { DelimitedFileRow inventoryRow = new DelimitedFileRow(); inventoryRow.CreateColumn(KeyName, data.GetColumnValue(KeyName), true); inventoryRow.CreateColumn("BEFORE", oldCSVData.GetColumnValue(QtyFieldName)); inventoryRow.CreateColumn("AFTER", newCSVData.GetColumnValue(QtyFieldName)); inventoryRows.Add(inventoryRow); } } DelimitedFile changedInventoryQtysFile = new DelimitedFile(); changedInventoryQtysFile.AddLines(inventoryRows); changedInventoryQtysFile.Save("sku,before,after", $"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\changed.inventory.qtys.csv"); } MessageBox.Show($"Completed Processing the Files and Found {changedProductInventoryQts.Count} Products that have changed inventory quantities SKUs."); Application.Current.Shutdown(); }
public MainWindow() { InitializeComponent(); IList <DelimitedFileInfo> lastestProductFiles = new List <DelimitedFileInfo>() { new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products.latest.csv", "sku", "^\\w{4}\\d{8}") }; IList <DelimitedFileInfo> oldProductFiles = new List <DelimitedFileInfo>() { //new DelimitedFileInfo("C:\\Users\\pawil\\Downloads\\product.files.comparison\\products_export_1.csv", // "Variant SKU", @"(^[0-9]{10,}[a-z0-9]{10,})"), //new DelimitedFileInfo("C:\\Users\\pawil\\Downloads\\product.files.comparison\\products_export_2.csv", // "Variant SKU", @"(^[0-9]{10,}[a-z0-9]{10,})") new DelimitedFileInfo($"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\products.old.csv", "sku", "^\\w{4}\\d{8}") }; DelimitedFile oldProducts = new DelimitedFile(); foreach (DelimitedFileInfo file in oldProductFiles) { oldProducts.LoadFileLines(file.FullName, HeaderNames, KeyName); } DelimitedFile latestProducts = new DelimitedFile(); foreach (DelimitedFileInfo file in lastestProductFiles) { latestProducts.LoadFileLines(file.FullName, HeaderNames, KeyName); } // Look for new products. These will be products // that exist in the new file but not the old file. IList <DelimitedFileRow> newProducts = DelimitedFile.Compare(latestProducts, oldProducts); if (newProducts.Count > 0) { DelimitedFile newProductsFile = new DelimitedFile(); newProductsFile.AddLines(newProducts); newProductsFile.Save("", $"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\new.product.sku.csv"); } // Look for discontinued products. These will be products // that exist in the old file but not the new file. IList <DelimitedFileRow> discontinuedProducts = DelimitedFile.Compare(oldProducts, latestProducts); if (discontinuedProducts.Count > 0) { DelimitedFile discontinuedProductsFile = new DelimitedFile(); discontinuedProductsFile.AddLines(discontinuedProducts); discontinuedProductsFile.Save("", $"C:\\Users\\{userprofile}\\Downloads\\product.files.comparison\\discontinued.product.sku.csv"); } MessageBox.Show($"Completed Processing the Files and Found {newProducts.Count} new product SKUs and {discontinuedProducts.Count} discontinued product SKUs."); Application.Current.Shutdown(); }