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 EC_CuttingPaperSpecDAL : IEC_CuttingPaperSpecDAL
{
private Database _dataBase = null;
public EC_CuttingPaperSpecDAL()
{
_dataBase = new Database();
}
public EC_CuttingPaperSpecDAL(Database database)
{
_dataBase = database;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_CuttingPaperSpec trueModel = model as Model.EC_CuttingPaperSpec;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@FirmId",trueModel.FirmId),
new SqlParameter("@SpecName",trueModel.SpecName),
new SqlParameter("@Width",trueModel.Width),
new SqlParameter("@Length",trueModel.Length),
new SqlParameter("@States",trueModel.States),
new SqlParameter("@OperateTime",trueModel.OperateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@IsPriority",trueModel.IsPriority)
};
try
{
_dataBase.Query("sp_EC_CuttingPaperSpec_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_CuttingPaperSpec trueModel = model as Model.EC_CuttingPaperSpec;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@FirmId",trueModel.FirmId),
new SqlParameter("@SpecName",trueModel.SpecName),
new SqlParameter("@Width",trueModel.Width),
new SqlParameter("@Length",trueModel.Length),
new SqlParameter("@States",trueModel.States),
new SqlParameter("@OperateTime",trueModel.OperateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@IsPriority",trueModel.IsPriority)
};
try
{
_dataBase.Query("sp_EC_CuttingPaperSpec_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_CuttingPaperSpec trueModel = model as Model.EC_CuttingPaperSpec;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_EC_CuttingPaperSpec_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 IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid MemberId)
{
try
{
string condition = " 1=1 and FirmId = '" + MemberId + "'";
return _dataBase.SelectModelPage(pagination, " * ", " EC_CuttingPaperSpec", "IsPriority desc, Keyid desc", " IsPriority desc, Keyid desc", condition);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 根据编号获得信息
///
/// 编号
///
public EC_CuttingPaperSpec GetModelByKeyid(int? Keyid)
{
try
{
if (Keyid == null || Keyid < 0)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_CuttingPaperSpec", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据会员编号和类型获取列表
///
///
///
///
public EC_CuttingPaperSpec SelectListByMemberIdAndParType(Guid MemberId, string ParType)
{
try
{
IList result = _dataBase.SelectModel("*", "EC_CuttingPaperSpec", string.Format(" FirmId='{0}' and SpecName='{1}'", MemberId, ParType)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 设置优先级
///
///
///
public bool EditModel(int? Keyid)
{
try
{
bool IsSuccess = true;
EC_CuttingPaperSpec m_EC_CuttingPaperSpec = GetModelByKeyid(Keyid);
m_EC_CuttingPaperSpec.IsPriority = 1;
List m_OA_CorporateClientsList = SelectListByFirmId(m_EC_CuttingPaperSpec.FirmId) as List;
using (TransactionScope t_TransactionScope = new TransactionScope())
{
foreach (var item in m_OA_CorporateClientsList)
{
if (IsSuccess)
{
item.IsPriority = 0;
IsSuccess = UpdateModel(item);
}
else
return false;
}
if (IsSuccess)
IsSuccess = UpdateModel(m_EC_CuttingPaperSpec);
if (IsSuccess)
t_TransactionScope.Complete();
}
return true;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据厂商编号查询全部会员
///
/// 编号
///
public IEnumerable SelectListByFirmId(Guid FirmId)
{
if (FirmId == null)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_CuttingPaperSpec", string.Format(" FirmId='{0}'", FirmId)) as IList;//执行查询
return result;//返回结果
}
}
}