diff options
| author | mo khan <mo@mokhan.ca> | 2007-08-26 20:10:42 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2007-08-26 20:10:42 -0600 |
| commit | 330be9feefb6394479553be0e078b4c4df3cbff1 (patch) | |
| tree | 55618c8af0d36583cde0ea5b4b193b98815a35aa /src/app/Cmpp298.Assignment3.Task | |
import from svntrunk
Diffstat (limited to 'src/app/Cmpp298.Assignment3.Task')
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/Cmpp298.Assignment3.Task.csproj | 63 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/IInvoiceTask.cs | 12 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/ITermTask.cs | 8 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/IVendorTask.cs | 9 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/InvoiceTask.cs | 113 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/Properties/AssemblyInfo.cs | 35 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/TermTask.cs | 31 | ||||
| -rw-r--r-- | src/app/Cmpp298.Assignment3.Task/VendorTask.cs | 44 |
8 files changed, 315 insertions, 0 deletions
diff --git a/src/app/Cmpp298.Assignment3.Task/Cmpp298.Assignment3.Task.csproj b/src/app/Cmpp298.Assignment3.Task/Cmpp298.Assignment3.Task.csproj new file mode 100644 index 0000000..415d8e7 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/Cmpp298.Assignment3.Task.csproj @@ -0,0 +1,63 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A747CA6E-EEA1-42E0-BA90-69317F8BF45D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Cmpp298.Assignment3.Task</RootNamespace>
+ <AssemblyName>Cmpp298.Assignment3.Task</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <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' ">
+ <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.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="IInvoiceTask.cs" />
+ <Compile Include="InvoiceTask.cs" />
+ <Compile Include="ITermTask.cs" />
+ <Compile Include="IVendorTask.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TermTask.cs" />
+ <Compile Include="VendorTask.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Cmpp298.Assignment3.DataAccess\Cmpp298.Assignment3.DataAccess.csproj">
+ <Project>{48B09B0E-F2D5-463D-9FAB-C1781CA46D4D}</Project>
+ <Name>Cmpp298.Assignment3.DataAccess</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Cmpp298.Assignment3.Dto\Cmpp298.Assignment3.Dto.csproj">
+ <Project>{29260A8E-3F7B-4D9B-BBE3-81210F4B9E5B}</Project>
+ <Name>Cmpp298.Assignment3.Dto</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\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>
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/IInvoiceTask.cs b/src/app/Cmpp298.Assignment3.Task/IInvoiceTask.cs new file mode 100644 index 0000000..43d6244 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/IInvoiceTask.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public interface IInvoiceTask {
+ int SaveNewInvoice( SaveInvoiceDto saveInvoiceDto );
+ IEnumerable< DisplayInvoiceDto > GetAllInvoices( string forVendorId );
+ DisplayInvoiceDto GetInvoiceBy(string invoiceId);
+ void DeleteInvoice( string invoiceId );
+ void UpdateInvoice( UpdateInvoiceDto dto );
+ }
+}
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/ITermTask.cs b/src/app/Cmpp298.Assignment3.Task/ITermTask.cs new file mode 100644 index 0000000..9ed735f --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/ITermTask.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public interface ITermTask {
+ IEnumerable< IDropDownListItem > GetAll( );
+ }
+}
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/IVendorTask.cs b/src/app/Cmpp298.Assignment3.Task/IVendorTask.cs new file mode 100644 index 0000000..56900e8 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/IVendorTask.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public interface IVendorTask {
+ IEnumerable< IDropDownListItem > GetAllVendorNames( );
+ DisplayVendorNameDto FindVendorNameBy( string vendorId );
+ }
+}
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/InvoiceTask.cs b/src/app/Cmpp298.Assignment3.Task/InvoiceTask.cs new file mode 100644 index 0000000..dee8d5d --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/InvoiceTask.cs @@ -0,0 +1,113 @@ +using System.Collections.Generic;
+using System.Data;
+using System.Text;
+using Cmpp298.Assignment3.DataAccess;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public class InvoiceTask : IInvoiceTask {
+ public InvoiceTask( ) : this( new DatabaseGateway( ) ) {}
+
+ public InvoiceTask( IDatabaseGateway gateway ) {
+ _gateway = gateway;
+ }
+
+ public int SaveNewInvoice( SaveInvoiceDto saveInvoiceDto ) {
+ InsertQueryBuilder builder = new InsertQueryBuilder( Tables.Invoices.TableName );
+ builder.Add( Tables.Invoices.VendorID, saveInvoiceDto.VendorId );
+ builder.Add( Tables.Invoices.InvoiceNumber, saveInvoiceDto.InvoiceNumber );
+ builder.Add( Tables.Invoices.InvoiceDate, saveInvoiceDto.InvoiceDate );
+ builder.Add( Tables.Invoices.InvoiceTotal, saveInvoiceDto.InvoiceTotal );
+ builder.Add( Tables.Invoices.PaymentTotal, saveInvoiceDto.PaymentTotal );
+ builder.Add( Tables.Invoices.CreditTotal, saveInvoiceDto.CreditTotal );
+ builder.Add( Tables.Invoices.TermsID, saveInvoiceDto.TermsId );
+ builder.Add( Tables.Invoices.DueDate, saveInvoiceDto.DueDate );
+ builder.Add( Tables.Invoices.PaymentDate, saveInvoiceDto.PaymentDate );
+
+ return _gateway.InsertRowUsing( builder );
+ }
+
+ public IEnumerable< DisplayInvoiceDto > GetAllInvoices( string forVendorId ) {
+ SelectQueryBuilder builder = new SelectQueryBuilder( Tables.Invoices.TableName );
+ builder.AddColumn( Tables.Invoices.InvoiceID );
+ builder.AddColumn( Tables.Invoices.InvoiceNumber );
+ builder.AddColumn( Tables.Invoices.InvoiceDate );
+ builder.AddColumn( Tables.Invoices.InvoiceTotal );
+ builder.AddColumn( Tables.Invoices.PaymentTotal );
+ builder.AddColumn( Tables.Invoices.CreditTotal );
+ builder.AddColumn( Tables.Invoices.DueDate );
+ builder.AddColumn( Tables.Invoices.PaymentDate );
+ builder.AddColumn( Tables.Terms.Description );
+ builder.AddColumn( Tables.Vendors.Name );
+ builder.InnerJoin( Tables.Terms.TermsID, Tables.Invoices.TermsID );
+ builder.InnerJoin( Tables.Vendors.VendorID, Tables.Invoices.VendorID );
+ builder.Where( Tables.Invoices.VendorID, forVendorId );
+
+ IList< DisplayInvoiceDto > dtos = new List< DisplayInvoiceDto >( );
+ foreach ( DataRow row in _gateway.GetTableFrom( builder ).Rows ) {
+ dtos.Add( CreateFrom( row ) );
+ }
+ return dtos;
+ }
+
+ public DisplayInvoiceDto GetInvoiceBy( string invoiceId ) {
+ SelectQueryBuilder builder = new SelectQueryBuilder( Tables.Invoices.TableName );
+ builder.AddColumn( Tables.Invoices.InvoiceID );
+ builder.AddColumn( Tables.Invoices.InvoiceNumber );
+ builder.AddColumn( Tables.Invoices.InvoiceDate );
+ builder.AddColumn( Tables.Invoices.InvoiceTotal );
+ builder.AddColumn( Tables.Invoices.PaymentTotal );
+ builder.AddColumn( Tables.Invoices.CreditTotal );
+ builder.AddColumn( Tables.Invoices.DueDate );
+ builder.AddColumn( Tables.Invoices.PaymentDate );
+ builder.AddColumn( Tables.Terms.Description );
+ builder.AddColumn( Tables.Vendors.Name );
+ builder.InnerJoin( Tables.Terms.TermsID, Tables.Invoices.TermsID );
+ builder.InnerJoin( Tables.Vendors.VendorID, Tables.Invoices.VendorID );
+ builder.Where( Tables.Invoices.InvoiceID, invoiceId );
+ DataTable table = _gateway.GetTableFrom( builder );
+ return table.Rows.Count == 1 ? CreateFrom( table.Rows[ 0 ] ) : null;
+ }
+
+ public void DeleteInvoice( string invoiceId ) {
+ StringBuilder builder = new StringBuilder( );
+
+ builder.AppendFormat( "DELETE FROM [{0}] WHERE [{0}].[{1}] = {2}",
+ Tables.Invoices.TableName,
+ Tables.Invoices.InvoiceID.ColumnName,
+ invoiceId );
+
+ _gateway.Execute( builder.ToString( ) );
+ }
+
+ public void UpdateInvoice( UpdateInvoiceDto dto ) {
+ UpdateQueryBuilder builder = new UpdateQueryBuilder( Tables.Invoices.InvoiceID, dto.InvoiceId );
+ builder.Add( Tables.Invoices.CreditTotal, dto.CreditTotal );
+ builder.Add( Tables.Invoices.DueDate, dto.DueDate );
+ builder.Add( Tables.Invoices.InvoiceDate, dto.InvoiceDate );
+ builder.Add( Tables.Invoices.InvoiceNumber, dto.InvoiceNumber );
+ builder.Add( Tables.Invoices.InvoiceTotal, dto.InvoiceTotal );
+ builder.Add( Tables.Invoices.PaymentDate, dto.PaymentDate );
+ builder.Add( Tables.Invoices.PaymentTotal, dto.PaymentTotal );
+ builder.Add( Tables.Invoices.TermsID, dto.TermsId );
+
+ _gateway.UpdateRowUsing( builder );
+ }
+
+ private IDatabaseGateway _gateway;
+
+ private static DisplayInvoiceDto CreateFrom( DataRow row ) {
+ return
+ new DisplayInvoiceDto( row[ Tables.Invoices.InvoiceID.ColumnName ].ToString( ),
+ row[ Tables.Vendors.Name.ColumnName ].ToString( ),
+ row[ Tables.Invoices.InvoiceNumber.ColumnName ].ToString( ),
+ row[ Tables.Invoices.InvoiceDate.ColumnName ].ToString( ),
+ row[ Tables.Invoices.InvoiceTotal.ColumnName ].ToString( ),
+ row[ Tables.Invoices.PaymentTotal.ColumnName ].ToString( ),
+ row[ Tables.Invoices.CreditTotal.ColumnName ].ToString( ),
+ row[ Tables.Terms.Description.ColumnName ].ToString( ),
+ row[ Tables.Invoices.DueDate.ColumnName ].ToString( ),
+ row[ Tables.Invoices.PaymentDate.ColumnName ].ToString( ) );
+ }
+ }
+}
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/Properties/AssemblyInfo.cs b/src/app/Cmpp298.Assignment3.Task/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a2fe345 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +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("Cmpp298.Assignment3.Task")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Cmpp298.Assignment3.Task")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[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("3987eab5-54b9-4396-81ae-cab8bdbbad27")]
+
+// 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 Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/app/Cmpp298.Assignment3.Task/TermTask.cs b/src/app/Cmpp298.Assignment3.Task/TermTask.cs new file mode 100644 index 0000000..826d5ec --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/TermTask.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic;
+using System.Data;
+using Cmpp298.Assignment3.DataAccess;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public class TermTask : ITermTask {
+ private IDatabaseGateway _gateway;
+
+ public TermTask( ) : this( new DatabaseGateway( ) ) {}
+
+ public TermTask( IDatabaseGateway gateway ) {
+ _gateway = gateway;
+ }
+
+ public IEnumerable< IDropDownListItem > GetAll( ) {
+ SelectQueryBuilder builder = new SelectQueryBuilder( Tables.Terms.TableName );
+ builder.AddColumn( Tables.Terms.TermsID );
+ builder.AddColumn( Tables.Terms.Description );
+ return CreateFrom( _gateway.GetTableFrom( builder ) );
+ }
+
+ private static IEnumerable< IDropDownListItem > CreateFrom( DataTable table ) {
+ foreach ( DataRow row in table.Rows ) {
+ yield return
+ new DropDownListItem( row[ Tables.Terms.Description.ColumnName ].ToString( ),
+ row[ Tables.Terms.TermsID.ColumnName ].ToString( ) );
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/src/app/Cmpp298.Assignment3.Task/VendorTask.cs b/src/app/Cmpp298.Assignment3.Task/VendorTask.cs new file mode 100644 index 0000000..2c69016 --- /dev/null +++ b/src/app/Cmpp298.Assignment3.Task/VendorTask.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic;
+using System.Data;
+using Cmpp298.Assignment3.DataAccess;
+using Cmpp298.Assignment3.Dto;
+
+namespace Cmpp298.Assignment3.Task {
+ public class VendorTask : IVendorTask {
+ private IDatabaseGateway _gateway;
+
+ public VendorTask( ) : this( new DatabaseGateway( ) ) {}
+
+ public VendorTask( IDatabaseGateway gateway ) {
+ _gateway = gateway;
+ }
+
+ public IEnumerable< IDropDownListItem > GetAllVendorNames( ) {
+ SelectQueryBuilder builder = new SelectQueryBuilder( Tables.Vendors.TableName );
+ builder.AddColumn( Tables.Vendors.VendorID );
+ builder.AddColumn( Tables.Vendors.Name );
+ return CreateItemsFrom( _gateway.GetTableFrom( builder ) );
+ }
+
+ public DisplayVendorNameDto FindVendorNameBy( string vendorId ) {
+ SelectQueryBuilder builder = new SelectQueryBuilder( Tables.Vendors.TableName );
+ builder.AddColumn( Tables.Vendors.VendorID );
+ builder.AddColumn( Tables.Vendors.Name );
+ builder.Where( Tables.Vendors.VendorID, vendorId );
+ return CreateDtoFrom( _gateway.GetTableFrom( builder ) );
+ }
+
+ private static DisplayVendorNameDto CreateDtoFrom( DataTable resultSet ) {
+ return new DisplayVendorNameDto( resultSet.Rows[ 0 ][ Tables.Vendors.VendorID.ColumnName ].ToString( ),
+ resultSet.Rows[ 0 ][ Tables.Vendors.Name.ColumnName ].ToString( ) );
+ }
+
+ private static IEnumerable< IDropDownListItem > CreateItemsFrom( DataTable table ) {
+ foreach ( DataRow row in table.Rows ) {
+ yield return
+ new DropDownListItem( row[ Tables.Vendors.Name.ColumnName ].ToString( ),
+ row[ Tables.Vendors.VendorID.ColumnName ].ToString( ) );
+ }
+ }
+ }
+}
\ No newline at end of file |
