/// <summary> /// Restores join on loading or after saving /// </summary> /// <param name="filename">Filename of the datasource to join</param> /// <param name="fieldList">Csv list of fields</param> /// <param name="joinOptions">Provider specific options</param> /// <param name="joinSource">At table to be filled to data source and passed to the ocx</param> public static void Table_OnUpdateJoin(string filename, string fieldList, string joinOptions, Table joinSource) { DataTable dt; filename = filename.ToLower(); if (filename.EndsWith(".xls") || filename.EndsWith(".xlsx")) { dt = XlsImportHelper.GetData(filename, GetOption("workbook", joinOptions)); } else if (filename.EndsWith(".csv")) { dt = CsvImportHelper.GetData(filename, GetOption("separator", joinOptions)); } else { return; } DbfImportHelper.FillMapWinGisTable(dt, joinSource); }
private bool ReloadExternal(IAttributeTable table) { switch (SourceType) { case JoinSourceType.Dbf: if (!table.Open(Filename)) { return(false); } break; case JoinSourceType.Xls: { var dt = XlsImportHelper.GetData(Filename, SelectedOption); if (dt == null) { return(false); } DbfImportHelper.FillMapWinGisTable(dt, table); } break; case JoinSourceType.Csv: { var dt = CsvImportHelper.GetData(Filename, SelectedOption); if (dt == null) { return(false); } DbfImportHelper.FillMapWinGisTable(dt, table); } break; default: return(false); } return(true); }
private static void Main(string[] args) { // Log the starting ILog logger = LogManager.GetLogger(typeof(Program)); logger.Info("Starting the import"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Please paste the Etsy CSV folder path on your drive:"); Console.ForegroundColor = ConsoleColor.White; string importFolderPath = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Please paste the Etsy file name with the file extension \".csv\":"); Console.ForegroundColor = ConsoleColor.White; string importFilename = Console.ReadLine(); string importFullPath = importFolderPath + "\\" + importFilename; logger.InfoFormat("Got the full file path: {0}", importFullPath); List <EtsyImport> orders; try { #region Import the Etsy data orders = CsvImportHelper.Import <EtsyImport>(importFullPath, typeof(EtsyMapping), true, false); WriteSuccessMessage(string.Format("{0} orders successfully imported.", orders.Count())); logger.InfoFormat("{0} orders successfully imported.", orders.Count()); #endregion Import the Etsy data #region Prepare the export template // Filter only the orders which don't have a DatePosted yet, cuz those with a DatePosted are already shipped. List <EtsyImport> filteredOrders = orders.FindAll(o => o.DatePosted == string.Empty); Console.WriteLine(string.Format("Found {0} order(s) not posted yet. Only the orders without a posted date in the Etsy file will be exported.", filteredOrders.Count())); List <MonkeyExport> exportList = new List <MonkeyExport>(); int exportCounter = 0; foreach (EtsyImport order in filteredOrders) { // Convert country name to ISO country code (2 letters) var regions = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID)); RegionInfo filteredRegion = regions.FirstOrDefault(r => r.EnglishName.Contains(order.DeliveryCountry)); string countryCode = filteredRegion.TwoLetterISORegionName; // Doc ParcelMonkey https://www.parcelmonkey.com/bulk-shipping/csv // ParcelMonkey CSV spec https://s3-eu-west-1.amazonaws.com/international-live/files/bulk-shipping-parcel-monkey-csv-spec.pdf exportList.Add(new MonkeyExport { CustomerShipmentReference = order.OrderID, OrderDate = order.SaleDate, Weight = ConfigurationManager.AppSettings["Weight"], Length = ConfigurationManager.AppSettings["Length"], Width = ConfigurationManager.AppSettings["Width"], Height = ConfigurationManager.AppSettings["Height"], SenderName = ConfigurationManager.AppSettings["SenderName"], SenderEmail = ConfigurationManager.AppSettings["SenderEmail"], SenderPhone = ConfigurationManager.AppSettings["SenderEmail"], SenderAddressOrganisation = ConfigurationManager.AppSettings["SenderEmail"], SenderAddressLine1 = ConfigurationManager.AppSettings["SenderAddressLine1"], SenderAddressLine2 = ConfigurationManager.AppSettings["SenderAddressLine2"], SenderAddressCity = ConfigurationManager.AppSettings["SenderAddressCity"], SenderAddressProvince = ConfigurationManager.AppSettings["SenderAddressProvince"], SenderAddressPostcode = ConfigurationManager.AppSettings["SenderAddressPostcode"], SenderAddressCountryCode = ConfigurationManager.AppSettings["SenderAddressCountryCode"], IsSenderAddressResidential = ConfigurationManager.AppSettings["IsSenderAddressResidential"], CollectionNotes = "", RecipientName = order.FullName, RecipientEmail = "*****@*****.**", RecipientPhone = "0611400478", DeliveryAddressOrganisation = "", DeliveryAddressLine1 = order.Street1, DeliveryAddressLine2 = order.Street2, DeliveryAddressCity = order.DeliveryCity, DeliveryAddressProvince = order.DeliveryState, DeliveryAddressPostcode = order.DeliveryZipcode, DeliveryAddressCountrycode = countryCode, IsDeliveryAddressResidential = "Yes", DeliveryNote = "", CustomsInvoiceType = ConfigurationManager.AppSettings["CustomsInvoiceType"], CustomsExportReason = ConfigurationManager.AppSettings["CustomsExportReason"], CustomsExportType = ConfigurationManager.AppSettings["CustomsExportType"], CodeCountryManufacture = ConfigurationManager.AppSettings["CodeCountryManufacture"], SenderCustomsType = ConfigurationManager.AppSettings["SenderCustomsType"], SenderCustomsTaxReference = ConfigurationManager.AppSettings["SenderCustomsTaxReference"], SenderCustomsCompanyName = ConfigurationManager.AppSettings["SenderCustomsCompanyName"], RecipientCustomsType = ConfigurationManager.AppSettings["RecipientCustomsType"], RecipientCustomsTaxReference = "", RecipientCustomsCompanyName = "", CurrencyCode = ConfigurationManager.AppSettings["CurrencyCode"], ProductDescription = ConfigurationManager.AppSettings["ProductDescription"], ProductQuantity = order.NumberofItems, ProductUnitPrice = (float.Parse(order.OrderValue, CultureInfo.InvariantCulture.NumberFormat) / float.Parse(order.NumberofItems)).ToString() }); exportCounter++; } try { DateTime today = DateTime.Now; string exportPath = string.Format("{0}\\Exports\\", Directory.GetCurrentDirectory()); string exportFilename = string.Format("exported-orders_{0}.csv", today.ToString("ddMMyyyy-HHmm")); HttpResponseMessage response = CsvExportHelper.Export <MonkeyExport>(exportList, typeof(MonkeyMapping), exportFilename, true); var stream = AsyncHelper.RunSync(async() => await response.Content.ReadAsStreamAsync()); // Saving file to the desired path using (var file = File.Create(exportPath + exportFilename)) { CopyStream(stream, file); } WriteSuccessMessage(string.Format("NICE!!! CSV file with {0} order(s) exported successfully!! File exported: {1}{2}", exportCounter, exportPath, exportFilename)); logger.InfoFormat("NICE!!! CSV file with {0} order(s) exported successfully!!", exportCounter); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(":) If you find this little tool useful, buy me a coffee: https://paypal.me/opaleLBC"); Console.WriteLine("Thank you! ^_^"); Console.ReadLine(); } catch (Exception ex) { WriteErrorMessage(ex.Message); logger.ErrorFormat("Error during exporting. Error message: {0}", ex.Message); } #endregion Prepare the export template } catch (Exception ex) { WriteErrorMessage(ex.Message); logger.ErrorFormat("Error during importing. Error message: {0}", ex.Message); } Console.ReadLine(); }