Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cubski committed Aug 18, 2015
0 parents commit f756806
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
22 changes: 22 additions & 0 deletions QuickbooksExporter.sln
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions QuickbooksExporter/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="OdbcDsn" value="QuickbooksExporter" />
<add key="OutputFolder" value="" />
<add key="OutputFileName" value="" />
</appSettings>
</configuration>
22 changes: 22 additions & 0 deletions QuickbooksExporter/Models/ExportSettings.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
77 changes: 77 additions & 0 deletions QuickbooksExporter/Program.cs
Original file line number Diff line number Diff line change
@@ -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<DataColumn>().Select(i => i.ColumnName).ToArray()));

foreach (var row in dt.Rows.Cast<DataRow>())
{
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"]
};
}
}
}
36 changes: 36 additions & 0 deletions QuickbooksExporter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
61 changes: 61 additions & 0 deletions QuickbooksExporter/QuickbooksExporter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0D3DA266-A381-4E29-B978-2846FC39169A}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>QuickbooksExporter</RootNamespace>
<AssemblyName>QuickbooksExporter</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Models\ExportSettings.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit f756806

Please sign in to comment.