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; namespace CY.SQLDAL { public class Info_ContentDAL : IInfo_ContentDAL { private Database _dataBase = null; public Info_ContentDAL() { _dataBase = new Database(); } public Info_ContentDAL(Database database) { _dataBase = database; } /// /// 新增 /// /// /// public bool InserModel(Infrastructure.Domain.IAggregateRoot model) { Model.Info_Content trueModel = model as Model.Info_Content; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@MemberId",trueModel.MemberId), new SqlParameter("@Title",trueModel.Title), new SqlParameter("@Title_Bold",trueModel.Title_Bold), new SqlParameter("@Title_Color",trueModel.Title_Color), new SqlParameter("@SortID",trueModel.SortID), new SqlParameter("@Keyword",trueModel.Keyword), new SqlParameter("@MeteDesc",trueModel.MeteDesc), new SqlParameter("@FromSource",trueModel.FromSource), new SqlParameter("@Author",trueModel.Author), new SqlParameter("@WebLink",trueModel.WebLink), new SqlParameter("@IsRecommendation",trueModel.IsRecommendation), new SqlParameter("@IsTop",trueModel.IsTop), new SqlParameter("@InfoContent",trueModel.InfoContent), new SqlParameter("@Star",trueModel.Star), new SqlParameter("@Hits",trueModel.Hits), new SqlParameter("@OrderNum",trueModel.OrderNum), new SqlParameter("@CreatTime",trueModel.CreatTime), new SqlParameter("@UpTime",trueModel.UpTime), new SqlParameter("@GoodNum",trueModel.GoodNum), new SqlParameter("@MediumNum",trueModel.MediumNum), new SqlParameter("@BadNum",trueModel.BadNum), new SqlParameter("@TypeId",trueModel.TypeId) }; try { _dataBase.Query("sp_Info_Content_Insert", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 修改 /// /// /// public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model) { Model.Info_Content trueModel = model as Model.Info_Content; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid), new SqlParameter("@MemberId",trueModel.MemberId), new SqlParameter("@Title",trueModel.Title ?? ""), new SqlParameter("@Title_Bold",trueModel.Title_Bold), new SqlParameter("@Title_Color",trueModel.Title_Color??""), new SqlParameter("@SortID",trueModel.SortID??0), new SqlParameter("@Keyword",trueModel.Keyword ??""), new SqlParameter("@MeteDesc",trueModel.MeteDesc??""), new SqlParameter("@FromSource",trueModel.FromSource??""), new SqlParameter("@Author",trueModel.Author??""), new SqlParameter("@WebLink",trueModel.WebLink??""), new SqlParameter("@IsRecommendation",trueModel.IsRecommendation), new SqlParameter("@IsTop",trueModel.IsTop), new SqlParameter("@InfoContent",trueModel.InfoContent??""), new SqlParameter("@Star",trueModel.Star??1), new SqlParameter("@Hits",trueModel.Hits??1), new SqlParameter("@OrderNum",trueModel.OrderNum??1), new SqlParameter("@CreatTime",trueModel.CreatTime), new SqlParameter("@UpTime",trueModel.UpTime), new SqlParameter("@GoodNum",trueModel.GoodNum??0), new SqlParameter("@MediumNum",trueModel.MediumNum??0), new SqlParameter("@BadNum",trueModel.BadNum??0), new SqlParameter("@TypeId",trueModel.TypeId??0) }; try { _dataBase.Query("sp_Info_Content_Update", CommandType.StoredProcedure, sqlParms.ToArray()); } catch (Exception ex) { throw ex; } return true; } /// /// 删除 /// /// /// public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model) { Model.Info_Content trueModel = model as Model.Info_Content; if (trueModel == null) { return false; } IList sqlParms = new List() { new SqlParameter("@Keyid",trueModel.Keyid) }; try { _dataBase.Query("sp_Info_Content_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 SelectAllModel(Infrastructure.Query.Query query) { throw new NotImplementedException(); } /// /// 根据分类编号分页查询 /// /// /// /// /// /// /// public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid FirmId, int? TypeId, int? SortId, string Title, string OrderString) { if (SortId == null || SortId <= 0) return null;//错误数据返会空 try { Info_SortDAL dal_Info_SortDAL = new Info_SortDAL(); string SelectRow = " a.*,b.Title as TypeName "; string condtion = " 1=1 "; if (TypeId > 0) condtion += " and TypeId='" + TypeId + "' "; if (SortId > 0) { string keyids = dal_Info_SortDAL.GetKeyidsByParentId(SortId); condtion += " and SortID in (" + keyids + ") "; } if (Guid.Empty != FirmId) condtion += " and MemberId = '" + FirmId + "' "; if (!string.IsNullOrEmpty(Title)) condtion += " and a.Title like '%" + Title + "%'"; string test = "select " + SelectRow + " from Info_Content where" + condtion; IList result = _dataBase.SelectModelPage(pagination, SelectRow, " Info_Content as a left join Info_Sort as b on a.SortID = b.Keyid", ("a." + (OrderString.Replace("OrderNum", "a.OrderNum"))).Replace("a.a.", "a."), OrderString, condtion) as IList;//执行查询 return null == result ? null : result;//返回结果 } catch (Exception ex) { throw ex; } } /// /// 根据分类查询全部信息 /// /// /// /// public IEnumerable SelectListBySortId(Guid Bussinessid, int? Num) { if (Bussinessid == null) return null;//错误数据返会空 try { IList result = _dataBase.SelectModel(" top " + Num + " *", "Info_Content", string.Format(" MemberId='{0}' and SortID<>415", Bussinessid)) as IList;//执行查询 return result;//返回结果 } catch (Exception ex) { throw ex; } } /// /// 根据分类查询全部信息 /// /// /// public IEnumerable SelectListBySortId(int? SortId) { if (SortId == null || SortId <= 0) return null;//错误数据返会空 try { IList result = _dataBase.SelectModel(" *", "Info_Content", string.Format(" SortID='{0}' ", SortId)) as IList;//执行查询 return result;//返回结果 } catch (Exception ex) { throw ex; } } /// /// 根据分类编号,条数,标题,排序字段分页查询 /// /// /// /// public IEnumerable SelectListByWhere(int? SortId, int? Num, bool IsHomeShow) { if (SortId == null || SortId <= 0) return null;//错误数据返会空 try { using (IDataReader i_IDataReader = _dataBase.QueryDataReader("sp_Info_Content_SelectListByWhere", CommandType.StoredProcedure, new SqlParameter("@Num", Num), new SqlParameter("@Keyid", SortId), new SqlParameter("@IsHomeShow", IsHomeShow))) { IList result = _dataBase.ReadDataToModel(i_IDataReader) as IList;//执行查询 return null == result ? null : result;//返回结果 } } catch (Exception ex) { throw ex; } } /// /// 根据编号查询信息 /// /// /// public Model.Info_Content SelectModelBySortId(int? Keyid) { if (Keyid == null || Keyid <= 0) return null;//错误数据返会空 try { IList result = _dataBase.SelectModel("*", "Info_Content", string.Format(" Keyid='{0}' ", Keyid)) as IList;//执行查询 if (result != null && result.Count > 0) return result[0];//返回结果 else return null; } catch (Exception ex) { throw ex; } } } }