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;
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Sort trueModel = model as Model.Info_Sort;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
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<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Sort trueModel = model as Model.Info_Sort;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
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<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.Info_Sort trueModel = model as Model.Info_Sort;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
try
|
{
|
_dataBase.Query("sp_Info_Sort_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除分类及分类下信息
|
/// </summary>
|
/// <param name="Keyid"></param>
|
/// <returns></returns>
|
public bool DeleteModelAll(int? Keyid)
|
{
|
try
|
{
|
Info_ContentDAL dal_Info_ContentDAL = new Info_ContentDAL(_dataBase);
|
Info_Sort m_Info_Sort = SelectModelByKeyId(Keyid);
|
List<Info_Content> m_Info_ContentList = dal_Info_ContentDAL.SelectListBySortId(m_Info_Sort.Keyid) as List<Info_Content>;
|
|
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;
|
}
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Info_Sort> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.Info_Sort> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 根据上级编号查询下级分类
|
/// </summary>
|
/// <param name="ParentId">编号</param>
|
/// <returns></returns>
|
public IEnumerable<Info_Sort> SelectListByParentId(int? ParentId)
|
{
|
if (ParentId == null)
|
return null;//错误数据返会空
|
try
|
{
|
IList<Info_Sort> result = _dataBase.SelectModel<Info_Sort>("*", "Info_Sort", string.Format(" ParentId='{0}' ORDER BY OrderNum ASC", ParentId)) as IList<Info_Sort>;//执行查询
|
|
return result;//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 根据上级编号查询全部下级分类的id字符串
|
/// </summary>
|
/// <param name="ParentId">编号</param>
|
/// <returns></returns>
|
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;
|
}
|
}
|
|
/// <summary>
|
/// 根据上级编号查询下级分类
|
/// </summary>
|
/// <param name="ParentId">编号</param>
|
/// <returns></returns>
|
public void SelectListByParentId(int? ParentId,ref string result)
|
{
|
try
|
{
|
IList<Info_Sort> m_Info_SortList = _dataBase.SelectModel<Info_Sort>("*", "Info_Sort", string.Format(" ParentId='{0}'", ParentId)) as IList<Info_Sort>;//执行查询
|
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;
|
}
|
}
|
|
|
/// <summary>
|
/// 查询全部分类
|
/// </summary>
|
/// <returns></returns>
|
public DataTable SelectList(Guid FirmId)
|
{
|
return _dataBase.SelectModel("*", "Info_Sort", string.Format(" AdminId='" + FirmId + "' " + " ORDER BY OrderNum ASC"));
|
}
|
|
/// <summary>
|
/// 根据编号查询单个信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public Info_Sort SelectModelByKeyId(int? KeyId)
|
{
|
if (KeyId == null)
|
return null;//错误数据返会空
|
|
Info_Sort m_Info_Sort = new Info_Sort();
|
try
|
{
|
IList<Info_Sort> result = _dataBase.SelectModel<Info_Sort>("*", "Info_Sort", string.Format(" Keyid='{0}' ", KeyId)) as IList<Info_Sort>;//执行查询
|
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;
|
}
|
}
|
}
|