public IEnumerable<NewsContent> SearchUnPaged(NewsSearchJson json) { try { if (json == null) { throw new ArgumentNullException("json for search is null "); } IList<Core.Business.NewsContent> newsContentlist = new List<Core.Business.NewsContent>(); SqlServerUtility sql = new SqlServerUtility(); if (!string.IsNullOrEmpty(json.Title)) { sql.AddParameter("@title", SqlDbType.NVarChar, json.Title); } if (json.PublishStartTime != null && json.PublishStartTime.Value > DateTime.MinValue) { sql.AddParameter("@publishstartdate", SqlDbType.DateTime, json.PublishStartTime.Value); } if (json.PublishEndTime != null && json.PublishEndTime.Value > DateTime.MinValue) { sql.AddParameter("@publishenddate", SqlDbType.DateTime, json.PublishEndTime.Value); } if (json.CheckStartTime != null && json.CheckStartTime.Value > DateTime.MinValue) { sql.AddParameter("@checkstartdate", SqlDbType.DateTime, json.CheckStartTime.Value); } if (json.CheckEndTime != null && json.CheckEndTime.Value > DateTime.MinValue) { sql.AddParameter("@checkenddate", SqlDbType.DateTime, json.CheckEndTime.Value); } if (!string.IsNullOrEmpty(json.Tag)) { sql.AddParameter("@tag", SqlDbType.NVarChar, json.Tag); } if (!string.IsNullOrEmpty(json.Source)) { sql.AddParameter("@source", SqlDbType.NVarChar, json.Source); } if (!string.IsNullOrEmpty(json.Author)) { sql.AddParameter("@author", SqlDbType.NVarChar, json.Author); } if (!string.IsNullOrEmpty(json.Checker)) { sql.AddParameter("@checker", SqlDbType.NVarChar, json.Checker); } if (json.StartTraffic != null && json.StartTraffic >= 0) { sql.AddParameter("@starttraffic", SqlDbType.Int, json.StartTraffic.Value); } if (json.EndTraffic != null && json.EndTraffic >= 0) { sql.AddParameter("@endtraffic", SqlDbType.Int, json.EndTraffic.Value); } if (json.Module != null && json.Module.Value != Guid.Empty) { sql.AddParameter("@moduleid", SqlDbType.UniqueIdentifier, json.Module.Value); } if (json.Unit != null && json.Unit.Value != Guid.Empty) { sql.AddParameter("@unit", SqlDbType.UniqueIdentifier, json.Unit.Value); } if (json.IsCenter != null) { sql.AddParameter("@center", SqlDbType.Int, json.IsCenter.Value); } SqlDataReader reader = sql.ExecuteSPReader("usp_SearchNewUpPaged"); if (reader != null) { while (reader.Read()) { Core.Business.NewsContent newsContent = new Core.Business.NewsContent(); if (!reader.IsDBNull(0)) newsContent.Id = reader.GetGuid(0); if (!reader.IsDBNull(1)) newsContent.ModuleID = reader.GetGuid(1); if (!reader.IsDBNull(2)) newsContent.Title = reader.GetString(2); if (!reader.IsDBNull(3)) newsContent.Content = reader.GetString(3); if (!reader.IsDBNull(4)) newsContent.PublishTime = reader.GetDateTime(4); if (!reader.IsDBNull(5)) newsContent.Tag = reader.GetInt32(5); if (!reader.IsDBNull(6)) newsContent.Annex = reader.GetInt32(6); if (!reader.IsDBNull(7)) newsContent.Status = reader.GetInt32(7); if (!reader.IsDBNull(8)) newsContent.Source = reader.GetString(8); if (!reader.IsDBNull(9)) newsContent.Author = reader.GetString(9); if (!reader.IsDBNull(10)) newsContent.Checker = reader.GetString(10); if (!reader.IsDBNull(11)) newsContent.CheckTime = reader.GetDateTime(11); if (!reader.IsDBNull(12)) newsContent.Index = reader.GetInt32(12); if (!reader.IsDBNull(13)) newsContent.Traffic = reader.GetInt64(13); if (!reader.IsDBNull(14)) newsContent.SortTime = reader.GetDateTime(14); if (!reader.IsDBNull(15)) newsContent.ModuleName = reader.GetString(15); newsContent.MarkOld(); newsContentlist.Add(newsContent); } reader.Close(); } return newsContentlist; } catch (Exception ex) { throw ex; } }
public int GetTotalCount(NewsSearchJson json) { if (json == null) throw new ArgumentNullException("json is null "); SqlServerUtility sql = new SqlServerUtility(); if (!string.IsNullOrEmpty(json.Title)) { sql.AddParameter("@title", SqlDbType.NVarChar, json.Title); } if (json.PublishStartTime != null && json.PublishStartTime.Value > DateTime.MinValue) { sql.AddParameter("@publishstartdate", SqlDbType.DateTime, json.PublishStartTime.Value); } if (json.PublishEndTime != null && json.PublishEndTime.Value > DateTime.MinValue) { sql.AddParameter("@publishenddate", SqlDbType.DateTime, json.PublishEndTime.Value); } if (json.CheckStartTime != null && json.CheckStartTime.Value > DateTime.MinValue) { sql.AddParameter("@checkstartdate", SqlDbType.DateTime, json.CheckStartTime.Value); } if (json.CheckEndTime != null && json.CheckEndTime.Value > DateTime.MinValue) { sql.AddParameter("@checkenddate", SqlDbType.DateTime, json.CheckEndTime.Value); } if (!string.IsNullOrEmpty(json.Tag)) { sql.AddParameter("@tag", SqlDbType.NVarChar, json.Tag); } if (!string.IsNullOrEmpty(json.Source)) { sql.AddParameter("@source", SqlDbType.NVarChar, json.Source); } if (!string.IsNullOrEmpty(json.Author)) { sql.AddParameter("@author", SqlDbType.NVarChar, json.Author); } if (!string.IsNullOrEmpty(json.Checker)) { sql.AddParameter("@checker", SqlDbType.NVarChar, json.Checker); } if (json.StartTraffic != null && json.StartTraffic >= 0) { sql.AddParameter("@starttraffic", SqlDbType.Int, json.StartTraffic.Value); } if (json.EndTraffic != null && json.EndTraffic >= 0) { sql.AddParameter("@endtraffic", SqlDbType.Int, json.EndTraffic.Value); } if (json.Module != null && json.Module.Value != Guid.Empty) { sql.AddParameter("@moduleid", SqlDbType.UniqueIdentifier, json.Module.Value); } if (json.Unit != null && json.Unit.Value != Guid.Empty) { sql.AddParameter("@unit", SqlDbType.UniqueIdentifier, json.Unit.Value); } if (json.IsCenter != null) { sql.AddParameter("@center", SqlDbType.Int, json.IsCenter.Value); } SqlDataReader reader = sql.ExecuteSPReader("usp_GetTotalCount"); int totalCount = 0; if (reader != null) { while (reader.Read()) { if (!reader.IsDBNull(0)) totalCount = reader.GetInt32(0); } reader.Close(); } return totalCount; }