90 lines
4.4 KiB
C#
90 lines
4.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using Tanshu.Accounts.Contracts;
|
|||
|
using Tanshu.Data.DAO;
|
|||
|
using Tanshu.Accounts.DAOFactory;
|
|||
|
using FluentNHibernate.Automapping;
|
|||
|
using FluentNHibernate.Cfg;
|
|||
|
|
|||
|
namespace Tanshu.Accounts.SqlDAO
|
|||
|
{
|
|||
|
public class ProductGroupModifierDAO : BaseDAO, IProductGroupModifierDAO
|
|||
|
{
|
|||
|
public ProductGroupModifierDAO(IConnectionDAO connection)
|
|||
|
: base(connection)
|
|||
|
{ }
|
|||
|
|
|||
|
public bool Insert(ProductGroupModifierBO productGroupModifier)
|
|||
|
{
|
|||
|
using (SqlCommand cmd = new SqlCommand(@"
|
|||
|
SELECT @ProductGroupModifierID = ISNULL(MAX(ProductGroupModifierID),0) + 1 FROM ProductGroupModifierID;
|
|||
|
INSERT INTO ProductGroupModifier (ProductGroupModifierID, ProductGroupID, ModifierID, ShowAutomatically) VALUES (@ProductGroupModifierID, @ProductGroupID, @ModifierID, @ShowAutomatically);
|
|||
|
"))
|
|||
|
{
|
|||
|
cmd.Parameters.Add("@ProductGroupModifierID", System.Data.SqlDbType.Int);
|
|||
|
cmd.Parameters["@ProductGroupModifierID"].Direction = System.Data.ParameterDirection.Output;
|
|||
|
if (productGroupModifier.ProductGroupID.HasValue)
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", productGroupModifier.ProductGroupID);
|
|||
|
else
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", DBNull.Value);
|
|||
|
cmd.Parameters.AddWithValue("@ModifierID", productGroupModifier.ModifierID);
|
|||
|
cmd.Parameters.AddWithValue("@ShowAutomatically", productGroupModifier.ShowAutomatically);
|
|||
|
connection.ExecuteNonQuery(cmd);
|
|||
|
productGroupModifier.ProductGroupModifierID = (int)cmd.Parameters["@ProductGroupModifierID"].Value;
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool Update(ProductGroupModifierBO productGroupModifier)
|
|||
|
{
|
|||
|
using (SqlCommand cmd = new SqlCommand(@"UPDATE ProductGroupModifier SET ProductGroupID = @ProductGroupID, ModifierID = @ModifierID, ShowAutomatically = @ShowAutomatically WHERE ProductGroupModifierID = @ProductGroupModifierID;"))
|
|||
|
{
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupModifierID", productGroupModifier.ProductGroupModifierID);
|
|||
|
if (productGroupModifier.ProductGroupID.HasValue)
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", productGroupModifier.ProductGroupID);
|
|||
|
else
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", DBNull.Value);
|
|||
|
cmd.Parameters.AddWithValue("@ModifierID", productGroupModifier.ModifierID);
|
|||
|
cmd.Parameters.AddWithValue("@ShowAutomatically", productGroupModifier.ShowAutomatically);
|
|||
|
connection.ExecuteNonQuery(cmd);
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool Delete(int productGroupModifierID)
|
|||
|
{
|
|||
|
using (SqlCommand cmd = new SqlCommand("DELETE FROM ProductGroupModifier WHERE ProductGroupModifierID = @ProductGroupModifierID"))
|
|||
|
{
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupModifierID", productGroupModifierID);
|
|||
|
connection.ExecuteNonQuery(cmd);
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<ProductGroupModifierBO> GetProductGroupModifiers(Guid productGroupID)
|
|||
|
{
|
|||
|
SqlCommand cmd = new SqlCommand("SELECT * FROM ProductGroupModifier Where ProductGroupID = @ProductGroupID;");
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", productGroupID);
|
|||
|
return BusinessObjectDAO<ProductGroupModifierBO>.GetBusinessObjects(connection.ExecuteReader(cmd));
|
|||
|
}
|
|||
|
|
|||
|
public List<ProductGroupModifierBO> GetProductGroupModifiers()
|
|||
|
{
|
|||
|
using (SqlCommand cmd = new SqlCommand("SELECT * FROM ProductGroupModifier"))
|
|||
|
{
|
|||
|
return BusinessObjectDAO<ProductGroupModifierBO>.GetBusinessObjects(connection.ExecuteReader(cmd));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public bool HasCompulsoryModifier(Guid productGroupID)
|
|||
|
{
|
|||
|
using (SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM ProductGroupModifier WHERE ShowAutomatically = 1 AND (ProductGroupID IS NULL OR ProductGroupID = @ProductGroupID)"))
|
|||
|
{
|
|||
|
cmd.Parameters.AddWithValue("@ProductGroupID", productGroupID);
|
|||
|
return (int)connection.ExecuteScalar(cmd) > 0;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|