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();
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@CommodityId",trueModel.CommodityId),
new SqlParameter("@SpecificationId",trueModel.SpecificationId)
};
try
{
_dataBase.Query("sp_OA_CommoditySpeciAssociate_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 批量删除
///
///
///
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;
}
///
/// 批量添加数据
///
///
///
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;
}
///
/// 管理关联类别-规格
///
///
///
///
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;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@CommodityId",trueModel.CommodityId),
new SqlParameter("@SpecificationId",trueModel.SpecificationId)
};
try
{
_dataBase.Query("sp_OA_CommoditySpeciAssociate_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_CommoditySpeciAssociate trueModel = model as Model.OA_CommoditySpeciAssociate;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@CommodityId",trueModel.CommodityId)
};
try
{
_dataBase.Query("sp_OA_CommoditySpeciAssociate_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
throw new NotImplementedException();
}
///
/// 得到类别下面的规格
///
///
///
public DataTable SelectModelPage(string CommodityId)
{
string selTaget = " * ";
string fromSource = " OA_CommoditySpeciAssociate where CommodityId='" + CommodityId + "'";
return _dataBase.SelectModel(selTaget, fromSource);
}
public IEnumerable 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(selTarget, fromSource);
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 单个查询
///
///
///
public Model.OA_CommoditySpeciAssociate SelectSingelModel(string SpecificationId)
{
try
{
string selTarget = " * ";
string fromSource = " OA_CommoditySpeciAssociate where SpecificationId='" + SpecificationId + "'";
List m_OA_CommoditySpeciAssociateList = _dataBase.SelectModel(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;
}
}
}
}