How to extend Spring.Northwind to generate different Northwind reports?

The steps below assumes that you have good knowledge of developing web applications using Microsoft Visual Studio and C#.NET. If you are totally new to these things you can learn ASP.NET and download relevant material from http://www.asp.net

Pre-requisites

  1. Make sure you have already installed Visual Studio 2010 or 2012
  2. Download the latest source code for Spring.NET from https://github.com/spring-projects/spring-net/
  3. Download latest Dlls of Aspose.Cells and Aspose.Pdf for .NET from http://www.aspose.com/community/files/default.aspx

Add support to access Products and Categories tables

Please follow the following steps to extend Spring.Northwind to add support for accessing Products and Categories tables

  1. Unzip the downloaded Source code of Spring.NET and open “Spring.Northwind.2010.sln” located in examples\Spring\Spring.Data.NHibernate.Northwind folder.
  2. Build the project to make sure there are no build errors. If you find any missing dll reference errors you can refer them from “src\Spring” folder.
  3. Set ‘Spring.Northwind.Web.2010’ as Startup Project and press F5 to run SpringAir project in a browser.
  4. You can explore Spring.Northwind by clicking on “Proceed to customer listing” and following the screens shown afterwards
  5. Add Aspose.Cells.dll and Aspose.Pdf.dll as reference to ‘Spring.Northwind.Web.2010’ project.
  6. Add a new interface class in Spring.Northwind.Dao.2010\Domain folder for Products
    
        public interface IProduct
        {
           	int ProductID { get; set; }
           	string ProductName { get; set; }
           	int SupplierID { get; set; }
           	int CategoryID { get; set; }
           	string QuantityPerUnit { get; set; }
           	decimal UnitPrice { get; set; }
           	short UnitsInStock { get; set; }
           	short UnitsOnOrder { get; set; }
           	short ReorderLevel { get; set; }
           	bool Discontinued { get; set; }
        }
        
  7. Update the existing Spring.Northwind.Dao.2010\Domain\Product.cs as follows
    
        public class Product : IProduct
        {
            #region Fields
    
            int productID;
            string productName;
            int supplierID;
            int categoryID;
            string quantityPerUnit;
            decimal unitPrice;
            short unitsInStock;
            short unitsOnOrder;
            short reorderLevel;
            bool discontinued;
    
            #endregion
    
            #region Constructor (s)
    
            public Product()
            {
            }
    
            public Product(string productName, int supplierID, int categoryID, string quantityPerUnit, decimal unitPrice, short unitsInStock, short unitsOnOrder, short reorderLevel, bool discontinued)
            {
                this.productName = productName;
                this.supplierID = supplierID;
                this.categoryID = categoryID;
                this.quantityPerUnit = quantityPerUnit;
                this.unitPrice = unitPrice;
                this.unitsInStock = unitsInStock;
                this.unitsOnOrder = unitsOnOrder;
                this.reorderLevel = reorderLevel;
                this.discontinued = discontinued;
            }
    
            #endregion
    
            #region Properties
    
            public int ProductID
            {
                get { return productID; }
                set { productID = value; }
            }
            
            public string ProductName
            {
                get { return productName; }
                set { productName = value; }
            }
            
            public int SupplierID
            {
                get { return supplierID; }
                set { supplierID = value; }
            }
            
            public int CategoryID
            {
                get { return categoryID; }
                set { categoryID = value; }
            }
            
            public string QuantityPerUnit
            {
                get { return quantityPerUnit; }
                set { quantityPerUnit = value; }
            }
            
            public decimal UnitPrice
            {
                get { return unitPrice; }
                set { unitPrice = value; }
            }
            
            public short UnitsInStock
            {
                get { return unitsInStock; }
                set { unitsInStock = value; }
            }
            
            public short UnitsOnOrder
            {
                get { return unitsOnOrder; }
                set { unitsOnOrder = value; }
            }
            
            public short ReorderLevel
            {
                get { return reorderLevel; }
                set { reorderLevel = value; }
            }
            
            public bool Discontinued
            {
                get { return discontinued; }
                set { discontinued = value; }
            }
            
            #endregion
        }
        
  8. Similary add Interface and Class for Category table as shown below
    
        public interface ICategory
        {
            int CategoryID { get; set; }
            string CategoryName { get; set; }
            string Description { get; set; }
            string Picture { get; set; }
        }
        
    
        public class Category
        {
            #region Fields
            
            int categoryID;
            string categoryName;
            string description;
            string picture;
    
            #endregion
    
            #region Constructor (s)
    
            public Category()
            {
            }
    
            #endregion
    
            #region Properties
            
            public int CategoryID
            {
                get { return categoryID; }
                set { categoryID = value; }
            }
            
            public string CategoryName
            {
                get { return categoryName; }
                set { categoryName = value; }
            }
            
            public string Description
            {
                get { return description; }
                set { description = value; }
            }
            
            public string Picture
            {
                get { return picture; }
                set { picture = value; }
            }
    
            #endregion
        }
            
  9. Add a new Interface in "Spring.Northwind.Dao\Dao" named "ICategoryDao"
    
        public interface ICategoryDao : IDao<Category, int>, ISupportsDeleteDao, ISupportsSave<Category, int>
        {
    
        }
            
  10. Add a new class in "Spring.Northwind.Dao.NHibernate\Dao\NHibernate" named "HibernateCategoryDao"
    
        [Repository]
        public class HibernateCategoryDao : HibernateDao, ICategoryDao
        {
            [Transaction(ReadOnly = true)]
            public Category Get(int categoryId)
            {
                return CurrentSession.Get(categoryId);
            }
    
            [Transaction(ReadOnly = true)]
            public IList GetAll()
            {
                return GetAll();
            }
    
            [Transaction]
            public int Save(Category category)
            {
                return (int)CurrentSession.Save(category);
            }
    
            [Transaction]
            public void Update(Category category)
            {
                CurrentSession.SaveOrUpdate(category);
            }
    
            [Transaction]
            public void Delete(Category category)
            {
                CurrentSession.Delete(category);
            }
        }
            
  11. Add a new mapping for Products table in "Spring.Northwind.Dao.NHibernate\Mappings" named "Product.hbm.xml"
     
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class name="Spring.Northwind.Domain.Product, Spring.Northwind.Dao" table="Products" lazy="false" proxy="Spring.Northwind.Domain.IProduct, Spring.Northwind.Dao">
    
        <id name="ProductID" unsaved-value="0">
          <column name="ProductID" sql-type="int" not-null="true" unique="true" index="PK_Products"/>
          <generator class="assigned" />
        </id>
    
        <property name="ProductName">
          <column name="ProductName" length="40" sql-type="nvarchar" not-null="false" />
        </property>
    
        <property name="SupplierID">
          <column name="SupplierID" sql-type="integer" not-null="true" />
        </property>
        <property name="CategoryID">
          <column name="CategoryID" sql-type="integer" not-null="true" />
        </property>
        <property name="QuantityPerUnit">
          <column name="QuantityPerUnit" length="20" sql-type="nvarchar" not-null="true" />
        </property>
        <property name="UnitPrice">
          <column name="UnitPrice" sql-type="money" not-null="true" />
        </property>
        <property name="UnitsInStock">
          <column name="UnitsInStock" sql-type="smallint" not-null="true" />
        </property>
        <property name="UnitsOnOrder">
          <column name="UnitsOnOrder" sql-type="smallint" not-null="true" />
        </property>
        <property name="ReorderLevel">
          <column name="ReorderLevel" sql-type="smallint" not-null="true" />
        </property>
        <property name="Discontinued">
          <column name="Discontinued" sql-type="bit" not-null="true" />
        </property>
    
      </class>
    </hibernate-mapping>
    
    
            
  12. Similarly add a new mapping for Categories table in "Spring.Northwind.Dao.NHibernate\Mappings" named "Category.hbm.xml"
     
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class name="Spring.Northwind.Domain.Category, Spring.Northwind.Dao" table="Categories" lazy="false" proxy="Spring.Northwind.Domain.ICategory, Spring.Northwind.Dao">
    
        <id name="CategoryID" unsaved-value="0">
          <column name="CategoryID" sql-type="int" not-null="true" unique="true" index="PK_Categories"/>
          <generator class="assigned" />
        </id>
    
        <property name="CategoryName">
          <column name="CategoryName" length="15" sql-type="nvarchar" not-null="false" />
        </property>
    
        <property name="Description">
          <column name="Description" sql-type="ntext" not-null="false" />
        </property>
        
        <property name="Picture">
          <column name="Picture" sql-type="image" not-null="false" />
        </property>
           
      </class>
    </hibernate-mapping>
    
    
            
  13. Make sure to set Build Action to "Embedded Resource" for both "Product.hbm.xml" and "Category.hbm.xml". You can do that by right-clicking on the file, select properties.
  14. Add the following lines to "Spring.Northwind.Dao.NHibernate\Dao\Dao.xml" after "object id="OrderDao" node
     
    
      <object id="ProductDao" type="Spring.Northwind.Dao.NHibernate.HibernateProductDao, Spring.Northwind.Dao.NHibernate">
        <property name="SessionFactory" ref="NHibernateSessionFactory"/>
      </object>
    
      <object id="CategoryDao" type="Spring.Northwind.Dao.NHibernate.HibernateCategoryDao, Spring.Northwind.Dao.NHibernate">
        <property name="SessionFactory" ref="NHibernateSessionFactory"/>
      </object>
            
            

You are now ready to access Products and Categories tables to generate reports. Please check the following pages to see detailed instructions for creating reports. Sample reports generated using Aspose.Cells

Sample reports generated using Aspose.Pdf

Last edited Feb 28, 2014 at 1:01 PM by asposemarketplace, version 2