using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using CY.IDAL;
|
using System.Data.SqlClient;
|
using System.Data;
|
using CY.Model;
|
using System.Transactions;
|
|
namespace CY.SQLDAL
|
{
|
public class OA_CommoditySpeciAssociateDAL : IOA_CommoditySpeciAssociateDAL
|
{
|
|
private Database _dataBase = null;
|
|
public OA_CommoditySpeciAssociateDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@CommodityId",trueModel.CommodityId),
|
new SqlParameter("@SpecificationId",trueModel.SpecificationId)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_CommoditySpeciAssociate_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
|
|
|
|
|
/// <summary>
|
/// 批量删除
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Model.OA_CommoditySpeciAssociate[] models)
|
{
|
if (null == models || 0 == models.Length)
|
{
|
return false;
|
}
|
else
|
{
|
};
|
bool isOK = false;
|
using (TransactionScope tran = new TransactionScope())
|
{
|
int i = -1;
|
while (++i < models.Length)
|
{
|
isOK = DeleteModel(models[i]);
|
if (!isOK)
|
return false;
|
else
|
continue;
|
}
|
|
if (isOK)
|
tran.Complete();
|
}
|
return true;
|
}
|
/// <summary>
|
/// 批量添加数据
|
/// </summary>
|
/// <param name="modles"></param>
|
/// <returns></returns>
|
public bool InserModel(OA_CommoditySpeciAssociate[] modles)
|
{
|
if (null == modles || 0 == modles.Length)
|
{
|
return false;
|
}
|
else
|
{
|
}
|
bool isWin = false;
|
|
using (TransactionScope tran = new TransactionScope())
|
{
|
int i = -1;
|
while (++i < modles.Length)
|
{
|
isWin = InserModel(modles[i]);
|
if (!isWin)
|
return false;
|
else
|
continue;
|
}
|
|
if (isWin)
|
tran.Complete();
|
}
|
return true;
|
}
|
/// <summary>
|
/// 管理关联类别-规格
|
/// </summary>
|
/// <param name="Deletemodels"></param>
|
/// <param name="Insertmodles"></param>
|
/// <returns></returns>
|
public bool MananeModel(Model.OA_CommoditySpeciAssociate[] Deletemodels, OA_CommoditySpeciAssociate[] Insertmodles)
|
{
|
|
if (null == Deletemodels || 0 == Deletemodels.Length)
|
{
|
return false;
|
}
|
else
|
{
|
};
|
if (null == Insertmodles || 0 == Insertmodles.Length)
|
{
|
return false;
|
}
|
else
|
{
|
}
|
bool isOK = false;
|
|
using (TransactionScope tran = new TransactionScope())
|
{
|
int i = -1;
|
while (++i < Insertmodles.Length)
|
{
|
isOK = InserModel(Insertmodles[i]);
|
if (!isOK)
|
return false;
|
else
|
continue;
|
}
|
|
int j = -1;
|
while (++j < Deletemodels.Length)
|
{
|
isOK = DeleteModel(Deletemodels[i]);
|
if (!isOK)
|
return false;
|
else
|
continue;
|
}
|
|
if (isOK)
|
tran.Complete();
|
}
|
return true;
|
}
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@CommodityId",trueModel.CommodityId),
|
new SqlParameter("@SpecificationId",trueModel.SpecificationId)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_CommoditySpeciAssociate_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@CommodityId",trueModel.CommodityId)
|
};
|
try
|
{
|
_dataBase.Query("sp_OA_CommoditySpeciAssociate_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_CommoditySpeciAssociate> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 得到类别下面的规格
|
/// </summary>
|
/// <param name="CommodityId"></param>
|
/// <returns></returns>
|
public DataTable SelectModelPage(string CommodityId)
|
{
|
string selTaget = " * ";
|
string fromSource = " OA_CommoditySpeciAssociate where CommodityId='" + CommodityId + "'";
|
return _dataBase.SelectModel(selTaget, fromSource);
|
}
|
public IEnumerable<Model.OA_CommoditySpeciAssociate> SelectALLModel(string CommodityId)
|
{
|
string selTarget = " a.*,b.Name AS OA_SpecificationName ";
|
string fromSource = " ( SELECT * FROM dbo.OA_CommoditySpeciAssociate WHERE CommodityId='" + CommodityId + "') AS a LEFT JOIN dbo.OA_Specification AS b ON a.SpecificationId =b.Keyid ";
|
return _dataBase.SelectModel<Model.OA_CommoditySpeciAssociate>(selTarget, fromSource);
|
}
|
|
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_CommoditySpeciAssociate> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="SpecificationId"></param>
|
/// <returns></returns>
|
public Model.OA_CommoditySpeciAssociate SelectSingelModel(string SpecificationId)
|
{
|
try
|
{
|
string selTarget = " * ";
|
string fromSource = " OA_CommoditySpeciAssociate where SpecificationId='" + SpecificationId + "'";
|
List<CY.Model.OA_CommoditySpeciAssociate> m_OA_CommoditySpeciAssociateList = _dataBase.SelectModel<Model.OA_CommoditySpeciAssociate>(selTarget, fromSource).ToList();
|
if (m_OA_CommoditySpeciAssociateList != null && m_OA_CommoditySpeciAssociateList.Count > 0)
|
{
|
return m_OA_CommoditySpeciAssociateList[0];
|
}
|
else
|
{
|
return null;
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
}
|
}
|