/// <summary> /// 更新一条数据 /// </summary> public bool Update(RemindModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update Remind set "); strSql.Append(" RemindId = @RemindId , "); strSql.Append(" ReKey = @ReKey , "); strSql.Append(" RemindTitle = @RemindTitle , "); strSql.Append(" CreateTime = @CreateTime , "); strSql.Append(" RemindTypeId = @RemindTypeId , "); strSql.Append(" Url = @Url , "); strSql.Append(" UserLook = @UserLook , "); strSql.Append(" MerLook = @MerLook , "); strSql.Append(" ReUserId = @ReUserId , "); strSql.Append(" ReMerchantId = @ReMerchantId "); strSql.Append(" where RemindId=@RemindId "); SqlParameter[] parameters = { new SqlParameter("@RemindId", SqlDbType.VarChar, 50), new SqlParameter("@ReKey", SqlDbType.VarChar, 50), new SqlParameter("@RemindTitle", SqlDbType.VarChar, 250), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@RemindTypeId", SqlDbType.VarChar, 10), new SqlParameter("@Url", SqlDbType.VarChar, 50), new SqlParameter("@UserLook", SqlDbType.Bit, 1), new SqlParameter("@MerLook", SqlDbType.Bit, 1), new SqlParameter("@ReUserId", SqlDbType.VarChar, 50), new SqlParameter("@ReMerchantId", SqlDbType.Decimal, 9) }; parameters[0].Value = model.RemindId; parameters[1].Value = model.ReKey; parameters[2].Value = model.RemindTitle; parameters[3].Value = model.CreateTime; parameters[4].Value = model.RemindTypeId; parameters[5].Value = model.Url; parameters[6].Value = model.UserLook; parameters[7].Value = model.MerLook; parameters[8].Value = model.ReUserId; parameters[9].Value = model.ReMerchantId; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(RemindModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Remind("); strSql.Append("RemindId,ReKey,RemindTitle,CreateTime,RemindTypeId,Url,UserLook,MerLook,ReUserId,ReMerchantId"); strSql.Append(") values ("); strSql.Append("@RemindId,@ReKey,@RemindTitle,@CreateTime,@RemindTypeId,@Url,@UserLook,@MerLook,@ReUserId,@ReMerchantId"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@RemindId", SqlDbType.VarChar, 50), new SqlParameter("@ReKey", SqlDbType.VarChar, 50), new SqlParameter("@RemindTitle", SqlDbType.VarChar, 250), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@RemindTypeId", SqlDbType.VarChar, 10), new SqlParameter("@Url", SqlDbType.VarChar, 50), new SqlParameter("@UserLook", SqlDbType.Bit, 1), new SqlParameter("@MerLook", SqlDbType.Bit, 1), new SqlParameter("@ReUserId", SqlDbType.VarChar, 50), new SqlParameter("@ReMerchantId", SqlDbType.Decimal, 9) }; parameters[0].Value = model.RemindId; parameters[1].Value = model.ReKey; parameters[2].Value = model.RemindTitle; parameters[3].Value = model.CreateTime; parameters[4].Value = model.RemindTypeId; parameters[5].Value = model.Url; parameters[6].Value = model.UserLook; parameters[7].Value = model.MerLook; parameters[8].Value = model.ReUserId; parameters[9].Value = model.ReMerchantId; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }
private void SaveTieZiInfo() { BLL.BBSBLL bbll = new BLL.BBSBLL(); Model.TieZiModel model = new TieZiModel(); model.TieZiId = ReDecimal("TieZiId", 0); if (bbll.HasTieZiPower(model.TieZiId)) { //是否有操作权限 } else { throw new Exception("您没有操作权限!"); } if (model.TieZiId > 0) {//修改 model = bbll.GetTieZiModel(model.TieZiId); model.CreateTime = ReTime("CreateTime", DateTime.Now); } else { //新增 model.Ip = ReStr("Ip", HttpContext.Current.Request.UserHostAddress); model.CreateUser = Common.CookieSings.GetCurrentUserId(); model.Source = ReStr("Source", ""); model.HideUser = ReBool("HideUser"); model.WxOpenId = ReStr("WxOpenId", ""); model.YueMingZhong = ""; model.RecommendLv = ReInt("RecommendLv", 0); } model.TieZiTitle = ReStr("TieZiTitle", ""); bool AddHot = ReBool("AddHot", false); model.TieZiContent = ReStrDeCode("TieZiContent"); model.TieZiSummary = Common.StringPlus.GetLeftStr(Common.StringPlus.OutHtmlText(model.TieZiContent), 120, ""); model.TieZiImgId = ReStr("TieZiImgId", ""); model.MiniImgUrl = ReStr("MiniImgUrl", ""); model.ForumId = ReDecimal("ForumId"); model.TieZiType = ReStr("TieZiType", ""); model.TieZiClass = ReStr("TieZiClass", ""); model.ParentTieZiId = ReDecimal("ParentTieZiId", 0); model.RepLastUser = model.CreateUser; model.Invalid = ReBool("Invalid", false); DataTable dtImg = ReTable("imgArray"); #region 事务开启 TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { #endregion dtImg = BLL.BJ.ImgSetting.ImgArraySetting(dtImg, model.TieZiContent); if (dtImg != null) { model.TieZiImgId = dtImg.Rows[0]["ImgId"].ToString(); } bbll.SaveTieZi(model); bbll.DeleteTieZiVsImgByTieZiId(model.TieZiId); //删除帖子下所有的图片,重新插入. if (dtImg != null) { foreach (DataRow dr in dtImg.Rows) { Model.TieZiVsImgModel VsImgModel = new TieZiVsImgModel(); VsImgModel.TieZiId = model.TieZiId; VsImgModel.ImgId = dr["ImgId"].ToString(); VsImgModel.vsType = "UserImg"; bbll.AddTieZiVsImg(VsImgModel); } } ReDict2.Add("ForumId", model.ForumId.ToString()); ReDict2.Add("TieZiId", model.TieZiId.ToString()); if (model.ParentTieZiId > 0) { int ParentRepCount = DAL.DalComm.ExInt(" select RepCount from BBS.DBO.TIEZI WHERE TieZiId='" + model.ParentTieZiId + "' "); ReDict2.Add("ParentRepCount", ParentRepCount.ToString()); #region 开始提醒 RemindModel remindmodel = new RemindModel(); remindmodel.CreateTime = DateTime.Now; remindmodel.MerLook = false; remindmodel.ReKey = model.ParentTieZiId.ToString(); remindmodel.ReMerchantId = 0; remindmodel.RemindTitle = "您发布的帖子有了新的回应!"; remindmodel.RemindTypeId = model.TieZiType; remindmodel.ReUserId = ReStr("ReUserId", ""); remindmodel.Url = "/t/?TieZiId=" + ReDecimal("ReTieZiId") + ""; remindmodel.UserLook = false; BLL.CommBLL commBll = new BLL.CommBLL(); if (remindmodel.ReUserId.Trim() != "") { commBll.SaveReMind(remindmodel); } #endregion #region 如果是回帖,更新主贴时间 if (model.TieZiType == "回帖") { //说明本帖是个回帖,更新回帖数目, 和最后发表人 int i = DAL.DalComm.ExReInt(" update bbs.dbo.TieZi set UpdateTime ='" + DateTime.Now.ToString() + "' , RepLastUser='******' where TieZiId='" + model.ParentTieZiId + "' "); if (i <= 0) { throw new Exception("没有找到ID为" + model.ParentTieZiId + "的主贴!"); } } #endregion } #region 事务结束 transactionScope.Complete(); } #endregion ReTrue(); }
/// <summary> /// 得到一个对象实体 /// </summary> public RemindModel GetModel(string RemindId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select RemindId, ReKey, RemindTitle, CreateTime, RemindTypeId, Url, UserLook, MerLook, ReUserId, ReMerchantId "); strSql.Append(" from Remind "); strSql.Append(" where RemindId=@RemindId "); SqlParameter[] parameters = { new SqlParameter("@RemindId", SqlDbType.VarChar, 50) }; parameters[0].Value = RemindId; RemindModel model = new RemindModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.RemindId = ds.Tables[0].Rows[0]["RemindId"].ToString(); model.ReKey = ds.Tables[0].Rows[0]["ReKey"].ToString(); model.RemindTitle = ds.Tables[0].Rows[0]["RemindTitle"].ToString(); if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } model.RemindTypeId = ds.Tables[0].Rows[0]["RemindTypeId"].ToString(); model.Url = ds.Tables[0].Rows[0]["Url"].ToString(); if (ds.Tables[0].Rows[0]["UserLook"].ToString() != "") { if ((ds.Tables[0].Rows[0]["UserLook"].ToString() == "1") || (ds.Tables[0].Rows[0]["UserLook"].ToString().ToLower() == "true")) { model.UserLook = true; } else { model.UserLook = false; } } if (ds.Tables[0].Rows[0]["MerLook"].ToString() != "") { if ((ds.Tables[0].Rows[0]["MerLook"].ToString() == "1") || (ds.Tables[0].Rows[0]["MerLook"].ToString().ToLower() == "true")) { model.MerLook = true; } else { model.MerLook = false; } } model.ReUserId = ds.Tables[0].Rows[0]["ReUserId"].ToString(); if (ds.Tables[0].Rows[0]["ReMerchantId"].ToString() != "") { model.ReMerchantId = decimal.Parse(ds.Tables[0].Rows[0]["ReMerchantId"].ToString()); } return(model); } else { return(null); } }