narsil/Tanshu.Accounts.BI/ProductBI.cs
2011-12-05 14:53:02 +05:30

135 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.DAOFactory;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
namespace Tanshu.Accounts.BI
{
public class ProductBI : IProductBI
{
public bool Insert(ProductBO product)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.Insert(product);
}
}
}
public bool Update(ProductBO product)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.Update(product);
}
}
}
public bool Delete(Guid productID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.Delete(productID);
}
}
}
public ProductBO GetProductFromName(string nameAndUnits)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetProduct(nameAndUnits);
}
}
}
public ProductBO GetProduct(Guid productID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetProduct(productID);
}
}
}
public decimal GetProductStock(DateTime date, Guid productID, Guid? voucherID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetProductStock(date, productID, voucherID);
}
}
}
public List<ProductDisplayBO> GetProducts()
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetProducts();
}
}
}
public List<ProductDisplaySmallBO> GetFilteredProducts(Dictionary<string, string> filter)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetFilteredProducts(filter);
}
}
}
public void UpdateShortName()
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
dao.UpdateShortName();
}
}
}
public List<ProductDisplaySmallBO> GetUnFilteredProducts()
{
Dictionary<string, string> filter = new Dictionary<string, string>();
filter.Add("Name", "");
filter.Add("Type", "");
return GetFilteredProducts(filter);
}
public List<ProductTypeBO> GetProductTypes()
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (IProductDAO dao = factory.GetProductDAO(connection))
{
return dao.GetProductTypes();
}
}
}
}
}