public IList <InformationInfo> GetList(int pageIndex, int pageSize, out int totalRecords, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select count(*) from Information "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } totalRecords = (int)SqlHelper.ExecuteScalar(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms); if (totalRecords == 0) { return(new List <InformationInfo>()); } sb.Clear(); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, Id,Title,Summary,ContentText,Source,ViewCount,Sort,ViewType,Remark,IsDisable,UserId,LastUpdatedDate from Information " ); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <InformationInfo> list = new List <InformationInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { InformationInfo model = new InformationInfo(); model.Id = reader.GetGuid(1); model.Title = reader.GetString(2); model.Summary = reader.GetString(3); model.ContentText = reader.GetString(4); model.Source = reader.GetString(5); model.ViewCount = reader.GetInt64(6); model.Sort = reader.GetInt32(7); model.ViewType = reader.GetByte(8); model.Remark = reader.GetString(9); model.IsDisable = reader.GetBoolean(10); model.UserId = reader.GetGuid(11); model.LastUpdatedDate = reader.GetDateTime(12); list.Add(model); } } } return(list); }
public Guid InsertByOutput(InformationInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"insert into Information (Title,Summary,ContentText,Source,ViewCount,Sort,ViewType,Remark,IsDisable,UserId,LastUpdatedDate) output inserted.Id values (@Title,@Summary,@ContentText,@Source,@ViewCount,@Sort,@ViewType,@Remark,@IsDisable,@UserId,@LastUpdatedDate) " ); SqlParameter[] parms = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Summary", SqlDbType.NVarChar, 200), new SqlParameter("@ContentText", SqlDbType.NVarChar, 4000), new SqlParameter("@Source", SqlDbType.NVarChar, 100), new SqlParameter("@ViewCount", SqlDbType.BigInt), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@ViewType", SqlDbType.TinyInt), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@IsDisable", SqlDbType.Bit), new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.Title; parms[1].Value = model.Summary; parms[2].Value = model.ContentText; parms[3].Value = model.Source; parms[4].Value = model.ViewCount; parms[5].Value = model.Sort; parms[6].Value = model.ViewType; parms[7].Value = model.Remark; parms[8].Value = model.IsDisable; parms[9].Value = model.UserId; parms[10].Value = model.LastUpdatedDate; object obj = SqlHelper.ExecuteScalar(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms); if (obj != null) { return(Guid.Parse(obj.ToString())); } return(Guid.Empty); }
public IList <InformationInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(250); sb.Append(@"select Id,Title,Summary,ContentText,Source,ViewCount,Sort,ViewType,Remark,IsDisable,UserId,LastUpdatedDate from Information "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } IList <InformationInfo> list = new List <InformationInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { InformationInfo model = new InformationInfo(); model.Id = reader.GetGuid(0); model.Title = reader.GetString(1); model.Summary = reader.GetString(2); model.ContentText = reader.GetString(3); model.Source = reader.GetString(4); model.ViewCount = reader.GetInt64(5); model.Sort = reader.GetInt32(6); model.ViewType = reader.GetByte(7); model.Remark = reader.GetString(8); model.IsDisable = reader.GetBoolean(9); model.UserId = reader.GetGuid(10); model.LastUpdatedDate = reader.GetDateTime(11); list.Add(model); } } } return(list); }
public int Update(InformationInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"update Information set Title = @Title,Summary = @Summary,ContentText = @ContentText,Source = @Source,ViewCount = @ViewCount,Sort = @Sort,ViewType = @ViewType,Remark = @Remark,IsDisable = @IsDisable,UserId = @UserId,LastUpdatedDate = @LastUpdatedDate where Id = @Id " ); SqlParameter[] parms = { new SqlParameter("@Id", SqlDbType.UniqueIdentifier), new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Summary", SqlDbType.NVarChar, 200), new SqlParameter("@ContentText", SqlDbType.NVarChar, 4000), new SqlParameter("@Source", SqlDbType.NVarChar, 100), new SqlParameter("@ViewCount", SqlDbType.BigInt), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@ViewType", SqlDbType.TinyInt), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@IsDisable", SqlDbType.Bit), new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) }; parms[0].Value = model.Id; parms[1].Value = model.Title; parms[2].Value = model.Summary; parms[3].Value = model.ContentText; parms[4].Value = model.Source; parms[5].Value = model.ViewCount; parms[6].Value = model.Sort; parms[7].Value = model.ViewType; parms[8].Value = model.Remark; parms[9].Value = model.IsDisable; parms[10].Value = model.UserId; parms[11].Value = model.LastUpdatedDate; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parms)); }
public InformationInfo GetModel(object Id) { InformationInfo model = null; StringBuilder sb = new StringBuilder(300); sb.Append(@"select top 1 Id,Title,Summary,ContentText,Source,ViewCount,Sort,ViewType,Remark,IsDisable,UserId,LastUpdatedDate from Information where Id = @Id " ); SqlParameter parm = new SqlParameter("@Id", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(Id.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcTeamDbConnString, CommandType.Text, sb.ToString(), parm)) { if (reader != null) { if (reader.Read()) { model = new InformationInfo(); model.Id = reader.GetGuid(0); model.Title = reader.GetString(1); model.Summary = reader.GetString(2); model.ContentText = reader.GetString(3); model.Source = reader.GetString(4); model.ViewCount = reader.GetInt64(5); model.Sort = reader.GetInt32(6); model.ViewType = reader.GetByte(7); model.Remark = reader.GetString(8); model.IsDisable = reader.GetBoolean(9); model.UserId = reader.GetGuid(10); model.LastUpdatedDate = reader.GetDateTime(11); } } } return(model); }
public void SaveInformation(HttpContext context) { try { string id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string sTitle = context.Request.Form["ctl00$cphMain$txtTitle"].Trim(); string sSummary = context.Request.Form["ctl00$cphMain$txtSummary"].Trim(); string sSource = context.Request.Form["ctl00$cphMain$txtSource"].Trim(); string sRemark = context.Request.Form["ctl00$cphMain$txtRemark"].Trim(); string sContent = context.Request.Form["content"].Trim(); string sIsDisable = context.Request.Form["isDisable"].Trim(); string sViewType = context.Request.Form["rdViewType"].Trim(); string sSort = context.Request.Form["ctl00$cphMain$txtSort"].Trim(); sSort = sSort == "" ? "0" : sSort; string sViewCount = context.Request.Form["ctl00$cphMain$txtViewCount"].Trim(); sViewCount = sViewCount == "" ? "0" : sViewCount; string sPictureIdList = context.Request.Form["pictureId"].TrimEnd(','); string sIsPush = context.Request.Form["isPush"].Trim(); sContent = HttpUtility.HtmlDecode(sContent); Guid gId = Guid.Empty; if (id != "") { Guid.TryParse(id, out gId); } InformationInfo model = new InformationInfo(); model.LastUpdatedDate = DateTime.Now; model.Remark = sRemark; model.Id = gId; model.Title = sTitle; model.Summary = sSummary; model.Source = sSource; model.ContentText = sContent; model.Sort = int.Parse(sSort); model.ViewCount = int.Parse(sViewCount); model.ViewType = byte.Parse(sViewType); model.IsDisable = bool.Parse(sIsDisable); model.IsPush = bool.Parse(sIsPush); if (string.IsNullOrWhiteSpace(model.ContentText)) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}"); return; } Information bll = new Information(); InformationPicture bllPP = new InformationPicture(); int effect = -1; if (!gId.Equals(Guid.Empty)) { effect = bll.Update(model); if (effect > 0) { bllPP.Delete(model.Id); if (!string.IsNullOrWhiteSpace(sPictureIdList)) { foreach (string sPictureId in sPictureIdList.Split(',')) { InformationPictureInfo infoPP = new InformationPictureInfo(); Guid pictureId = Guid.Empty; Guid.TryParse(sPictureId, out pictureId); infoPP.InformationId = model.Id; infoPP.PictureId = pictureId; bllPP.InsertModel(infoPP); } } } } else { model.LastUpdatedDate = DateTime.Now; Guid anformationId = bll.InsertByOutput(model); if (!anformationId.Equals(Guid.Empty)) { effect = 1; if (!string.IsNullOrWhiteSpace(sPictureIdList)) { foreach (string sPictureId in sPictureIdList.Split(',')) { InformationPictureInfo infoPP = new InformationPictureInfo(); Guid pictureId = Guid.Empty; Guid.TryParse(sPictureId, out pictureId); infoPP.InformationId = anformationId; infoPP.PictureId = pictureId; bllPP.InsertModel(infoPP); } } } } if (effect == 110) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}"); return; } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Error + "\"}"); return; } if (model.IsPush) { #region 推送信息到推送服务系统 try { PushContentService pushProxy = new PushContentService(); if (System.Configuration.ConfigurationManager.AppSettings["PushServiceUrl"] != null) { pushProxy.Url = System.Configuration.ConfigurationManager.AppSettings["PushServiceUrl"].ToString(); } string sxml = ""; sxml = string.Format(@"<XmlParameters><ReceivePushContent><PushType>{0}</PushType><PushContent>{1}</PushContent><Title>{2}</Title><PushParam>{3}</PushParam></ReceivePushContent></XmlParameters>", "xwfb", "", model.Title, "1"); pushProxy.ReceivePushContentAsync(sxml); } catch { } #endregion } context.Response.Write("{\"success\": true,\"message\": \"" + MessageContent.Submit_Success + "\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.AlertTitle_Ex_Error + ":" + ex.Message + "\"}"); } }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(InformationInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(InformationInfo model) { return(dal.Insert(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public Guid InsertByOutput(InformationInfo model) { return(dal.InsertByOutput(model)); }