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 Info_SortDAL : IInfo_SortDAL
{
private Database _dataBase = null;
public Info_SortDAL()
{
_dataBase = new Database();
}
public Info_SortDAL(Database database)
{
_dataBase = database;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Sort trueModel = model as Model.Info_Sort;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@CateTypeId",trueModel.CateTypeId),
new SqlParameter("@ParentId",trueModel.ParentId),
new SqlParameter("@Title",trueModel.Title),
new SqlParameter("@Icon",trueModel.Icon),
new SqlParameter("@Leavel",trueModel.Leavel),
new SqlParameter("@Status",trueModel.Status),
new SqlParameter("@IsHomeShow",trueModel.IsHomeShow),
new SqlParameter("@IsOtherPage",trueModel.IsOtherPage),
new SqlParameter("@Herf",trueModel.Herf),
new SqlParameter("@Remarks",trueModel.Remarks),
new SqlParameter("@OrderNum",trueModel.OrderNum),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@AdminId",trueModel.AdminId)
};
try
{
_dataBase.Query("sp_Info_Sort_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Sort trueModel = model as Model.Info_Sort;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@CateTypeId",trueModel.CateTypeId),
new SqlParameter("@ParentId",trueModel.ParentId),
new SqlParameter("@Title",trueModel.Title),
new SqlParameter("@Icon",trueModel.Icon),
new SqlParameter("@Leavel",trueModel.Leavel),
new SqlParameter("@Status",trueModel.Status),
new SqlParameter("@IsHomeShow",trueModel.IsHomeShow),
new SqlParameter("@IsOtherPage",trueModel.IsOtherPage),
new SqlParameter("@Herf",trueModel.Herf),
new SqlParameter("@Remarks",trueModel.Remarks),
new SqlParameter("@OrderNum",trueModel.OrderNum),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@AdminId",trueModel.AdminId)
};
try
{
_dataBase.Query("sp_Info_Sort_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.Info_Sort trueModel = model as Model.Info_Sort;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_Info_Sort_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除分类及分类下信息
///
///
///
public bool DeleteModelAll(int? Keyid)
{
try
{
Info_ContentDAL dal_Info_ContentDAL = new Info_ContentDAL(_dataBase);
Info_Sort m_Info_Sort = SelectModelByKeyId(Keyid);
List m_Info_ContentList = dal_Info_ContentDAL.SelectListBySortId(m_Info_Sort.Keyid) as List;
using (TransactionScope t_TransactionScope = new TransactionScope())
{
bool result = false;
result = DeleteModel(m_Info_Sort);
if (result)
{
if (m_Info_ContentList != null)
{
foreach (var m_Info_Content in m_Info_ContentList)
{
if (result)
result = dal_Info_ContentDAL.DeleteModel(m_Info_Content);
else
break;
}
}
else
result = false;
}
if (result)
t_TransactionScope.Complete();
return result;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
throw new NotImplementedException();
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 根据上级编号查询下级分类
///
/// 编号
///
public IEnumerable SelectListByParentId(int? ParentId)
{
if (ParentId == null)
return null;//错误数据返会空
try
{
IList result = _dataBase.SelectModel("*", "Info_Sort", string.Format(" ParentId='{0}' ORDER BY OrderNum ASC", ParentId)) as IList;//执行查询
return result;//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据上级编号查询全部下级分类的id字符串
///
/// 编号
///
public string GetKeyidsByParentId(int? ParentId)
{
if (ParentId == null)
return null;//错误数据返会空
try
{
string result = "" + ParentId;
SelectListByParentId(ParentId,ref result);
result.Trim(',');
return result;//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据上级编号查询下级分类
///
/// 编号
///
public void SelectListByParentId(int? ParentId,ref string result)
{
try
{
IList m_Info_SortList = _dataBase.SelectModel("*", "Info_Sort", string.Format(" ParentId='{0}'", ParentId)) as IList;//执行查询
foreach (var m_Info_Sort in m_Info_SortList)
{
result += "," + m_Info_Sort.Keyid;
SelectListByParentId(m_Info_Sort.Keyid,ref result);
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 查询全部分类
///
///
public DataTable SelectList(Guid FirmId)
{
return _dataBase.SelectModel("*", "Info_Sort", string.Format(" AdminId='" + FirmId + "' " + " ORDER BY OrderNum ASC"));
}
///
/// 根据编号查询单个信息
///
/// 编号
///
public Info_Sort SelectModelByKeyId(int? KeyId)
{
if (KeyId == null)
return null;//错误数据返会空
Info_Sort m_Info_Sort = new Info_Sort();
try
{
IList result = _dataBase.SelectModel("*", "Info_Sort", string.Format(" Keyid='{0}' ", KeyId)) as IList;//执行查询
if (null == result || result.Count == 0)
{
m_Info_Sort = null;
}
else
{
m_Info_Sort = result[0];
}
}
catch (Exception ex)
{
throw ex;
}
return m_Info_Sort;
}
}
}