From f756806b95acad7fd23fde3314bb5c86665ab123 Mon Sep 17 00:00:00 2001 From: Carl Cubillas Date: Tue, 18 Aug 2015 17:50:24 +0800 Subject: [PATCH] Initial commit. --- .gitignore | 31 ++++++++ QuickbooksExporter.sln | 22 ++++++ QuickbooksExporter/App.config | 8 ++ QuickbooksExporter/Models/ExportSettings.cs | 22 ++++++ QuickbooksExporter/Program.cs | 77 +++++++++++++++++++ QuickbooksExporter/Properties/AssemblyInfo.cs | 36 +++++++++ QuickbooksExporter/QuickbooksExporter.csproj | 61 +++++++++++++++ 7 files changed, 257 insertions(+) create mode 100644 .gitignore create mode 100644 QuickbooksExporter.sln create mode 100644 QuickbooksExporter/App.config create mode 100644 QuickbooksExporter/Models/ExportSettings.cs create mode 100644 QuickbooksExporter/Program.cs create mode 100644 QuickbooksExporter/Properties/AssemblyInfo.cs create mode 100644 QuickbooksExporter/QuickbooksExporter.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1883baf --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +Thumbs.db +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.sln.docstates +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +*.vssscc +$tf*/ +packages/ +publish/ \ No newline at end of file diff --git a/QuickbooksExporter.sln b/QuickbooksExporter.sln new file mode 100644 index 0000000..db6a350 --- /dev/null +++ b/QuickbooksExporter.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickbooksExporter", "QuickbooksExporter\QuickbooksExporter.csproj", "{0D3DA266-A381-4E29-B978-2846FC39169A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0D3DA266-A381-4E29-B978-2846FC39169A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D3DA266-A381-4E29-B978-2846FC39169A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D3DA266-A381-4E29-B978-2846FC39169A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D3DA266-A381-4E29-B978-2846FC39169A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/QuickbooksExporter/App.config b/QuickbooksExporter/App.config new file mode 100644 index 0000000..9cb8f7f --- /dev/null +++ b/QuickbooksExporter/App.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/QuickbooksExporter/Models/ExportSettings.cs b/QuickbooksExporter/Models/ExportSettings.cs new file mode 100644 index 0000000..1ce3256 --- /dev/null +++ b/QuickbooksExporter/Models/ExportSettings.cs @@ -0,0 +1,22 @@ +using System; +using System.IO; + +namespace QuickbooksExporter.Models +{ + public class ExportSettings + { + public string Dsn { get; set; } + public string OutputFolder { get; set; } + public string OutputFileName { get; set; } + + public string OutputFilePath + { + get + { + var folder = string.IsNullOrWhiteSpace(OutputFolder) ? Environment.GetFolderPath(Environment.SpecialFolder.Desktop) : OutputFolder; + var fileName = string.IsNullOrWhiteSpace(OutputFileName) ? "item_inventory.csv" : OutputFileName; + return Path.Combine(folder, fileName); + } + } + } +} \ No newline at end of file diff --git a/QuickbooksExporter/Program.cs b/QuickbooksExporter/Program.cs new file mode 100644 index 0000000..49f0771 --- /dev/null +++ b/QuickbooksExporter/Program.cs @@ -0,0 +1,77 @@ +using System; +using System.Configuration; +using System.Data; +using System.Data.Odbc; +using System.IO; +using System.Linq; +using System.Text; +using QuickbooksExporter.Models; + +namespace QuickbooksExporter +{ + class Program + { + static void Main() + { + var settings = GetExportSettings(); + + Console.WriteLine("Retrieving Item Inventories from Quickbooks..."); + + var itemInventories = GetItemInventories(settings); + + Console.WriteLine($"Found {itemInventories.Rows.Count} Item Inventories."); + + Console.WriteLine("Dumping to CSV..."); + + DumpToCsv(settings, itemInventories); + + Console.WriteLine("Press any key to exit..."); + + Console.ReadKey(); + } + + static void DumpToCsv(ExportSettings settings, DataTable dt) + { + var sb = new StringBuilder(); + + sb.AppendLine(string.Join("\t", dt.Columns.Cast().Select(i => i.ColumnName).ToArray())); + + foreach (var row in dt.Rows.Cast()) + { + sb.AppendLine(string.Join("\t", Enumerable.Range(0, dt.Columns.Count).Select(i => row[i].ToString()))); + } + + File.WriteAllText(settings.OutputFilePath, sb.ToString()); + } + + static DataTable GetItemInventories(ExportSettings settings) + { + var results = new DataTable(); + + var cb = new OdbcConnectionStringBuilder { Dsn = settings.Dsn }; + using (var connection = new OdbcConnection(cb.ConnectionString)) + { + connection.Open(); + + using (var adapter = new OdbcDataAdapter("SELECT * FROM ItemInventory", connection)) + { + adapter.Fill(results); + } + + connection.Close(); + } + + return results; + } + + static ExportSettings GetExportSettings() + { + return new ExportSettings + { + Dsn = ConfigurationManager.AppSettings["OdbcDsn"], + OutputFolder = ConfigurationManager.AppSettings["OutputFolder"], + OutputFileName = ConfigurationManager.AppSettings["OutputFileName"] + }; + } + } +} diff --git a/QuickbooksExporter/Properties/AssemblyInfo.cs b/QuickbooksExporter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..572f614 --- /dev/null +++ b/QuickbooksExporter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QuickbooksExporter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("QuickbooksExporter")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0d3da266-a381-4e29-b978-2846fc39169a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/QuickbooksExporter/QuickbooksExporter.csproj b/QuickbooksExporter/QuickbooksExporter.csproj new file mode 100644 index 0000000..b4a943b --- /dev/null +++ b/QuickbooksExporter/QuickbooksExporter.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {0D3DA266-A381-4E29-B978-2846FC39169A} + Exe + Properties + QuickbooksExporter + QuickbooksExporter + v4.0 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file