/// <summary> /// 更新一条数据 /// </summary> public bool Update(WxSuCaiDetailModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update CORE.dbo.WxSuCaiDetail set "); strSql.Append(" OtherPara = @OtherPara , "); strSql.Append(" OrderNo = @OrderNo , "); strSql.Append(" WxSuCaiInfoId = @WxSuCaiInfoId , "); strSql.Append(" WxSuCaiDetailTitle = @WxSuCaiDetailTitle , "); strSql.Append(" WxSuCaiDetailMemo = @WxSuCaiDetailMemo , "); strSql.Append(" WxSuCaiDetailContent = @WxSuCaiDetailContent , "); strSql.Append(" WxSuCaiDetailClassId = @WxSuCaiDetailClassId , "); strSql.Append(" ImgId = @ImgId , "); strSql.Append(" Url = @Url , "); strSql.Append(" ReKey = @ReKey "); strSql.Append(" where WxSuCaiDetailId=@WxSuCaiDetailId "); SqlParameter[] parameters = { new SqlParameter("@WxSuCaiDetailId", SqlDbType.Decimal, 9), new SqlParameter("@OtherPara", SqlDbType.VarChar, 200), new SqlParameter("@OrderNo", SqlDbType.Int, 4), new SqlParameter("@WxSuCaiInfoId", SqlDbType.Decimal, 9), new SqlParameter("@WxSuCaiDetailTitle", SqlDbType.VarChar, 50), new SqlParameter("@WxSuCaiDetailMemo", SqlDbType.VarChar, 1000), new SqlParameter("@WxSuCaiDetailContent", SqlDbType.NText), new SqlParameter("@WxSuCaiDetailClassId", SqlDbType.Int, 4), new SqlParameter("@ImgId", SqlDbType.VarChar, 50), new SqlParameter("@Url", SqlDbType.VarChar, 200), new SqlParameter("@ReKey", SqlDbType.VarChar, 50) }; parameters[0].Value = model.WxSuCaiDetailId; parameters[1].Value = model.OtherPara; parameters[2].Value = model.OrderNo; parameters[3].Value = model.WxSuCaiInfoId; parameters[4].Value = model.WxSuCaiDetailTitle; parameters[5].Value = model.WxSuCaiDetailMemo; parameters[6].Value = model.WxSuCaiDetailContent; parameters[7].Value = model.WxSuCaiDetailClassId; parameters[8].Value = model.ImgId; parameters[9].Value = model.Url; parameters[10].Value = model.ReKey; 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(WxSuCaiDetailModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CORE.dbo.WxSuCaiDetail ("); strSql.Append("OtherPara,OrderNo,WxSuCaiInfoId,WxSuCaiDetailTitle,WxSuCaiDetailMemo,WxSuCaiDetailContent,WxSuCaiDetailClassId,ImgId,Url,ReKey"); strSql.Append(") values ("); strSql.Append("@OtherPara,@OrderNo,@WxSuCaiInfoId,@WxSuCaiDetailTitle,@WxSuCaiDetailMemo,@WxSuCaiDetailContent,@WxSuCaiDetailClassId,@ImgId,@Url,@ReKey"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@OtherPara", SqlDbType.VarChar, 200), new SqlParameter("@OrderNo", SqlDbType.Int, 4), new SqlParameter("@WxSuCaiInfoId", SqlDbType.Decimal, 9), new SqlParameter("@WxSuCaiDetailTitle", SqlDbType.VarChar, 50), new SqlParameter("@WxSuCaiDetailMemo", SqlDbType.VarChar, 1000), new SqlParameter("@WxSuCaiDetailContent", SqlDbType.NText), new SqlParameter("@WxSuCaiDetailClassId", SqlDbType.Int, 4), new SqlParameter("@ImgId", SqlDbType.VarChar, 50), new SqlParameter("@Url", SqlDbType.VarChar, 200), new SqlParameter("@ReKey", SqlDbType.VarChar, 50) }; parameters[0].Value = model.OtherPara; parameters[1].Value = model.OrderNo; parameters[2].Value = model.WxSuCaiInfoId; parameters[3].Value = model.WxSuCaiDetailTitle; parameters[4].Value = model.WxSuCaiDetailMemo; parameters[5].Value = model.WxSuCaiDetailContent; parameters[6].Value = model.WxSuCaiDetailClassId; parameters[7].Value = model.ImgId; parameters[8].Value = model.Url; parameters[9].Value = model.ReKey; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public WxSuCaiDetailModel GetModel(decimal WxSuCaiDetailId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select WxSuCaiDetailId, OtherPara, OrderNo, WxSuCaiInfoId, WxSuCaiDetailTitle, WxSuCaiDetailMemo, WxSuCaiDetailContent, WxSuCaiDetailClassId, ImgId, Url, ReKey "); strSql.Append(" from CORE.dbo.WxSuCaiDetail "); strSql.Append(" where WxSuCaiDetailId=@WxSuCaiDetailId"); SqlParameter[] parameters = { new SqlParameter("@WxSuCaiDetailId", SqlDbType.Decimal) }; parameters[0].Value = WxSuCaiDetailId; WxSuCaiDetailModel model = new WxSuCaiDetailModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["WxSuCaiDetailId"].ToString() != "") { model.WxSuCaiDetailId = decimal.Parse(ds.Tables[0].Rows[0]["WxSuCaiDetailId"].ToString()); } model.OtherPara = ds.Tables[0].Rows[0]["OtherPara"].ToString(); if (ds.Tables[0].Rows[0]["OrderNo"].ToString() != "") { model.OrderNo = int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString()); } if (ds.Tables[0].Rows[0]["WxSuCaiInfoId"].ToString() != "") { model.WxSuCaiInfoId = decimal.Parse(ds.Tables[0].Rows[0]["WxSuCaiInfoId"].ToString()); } model.WxSuCaiDetailTitle = ds.Tables[0].Rows[0]["WxSuCaiDetailTitle"].ToString(); model.WxSuCaiDetailMemo = ds.Tables[0].Rows[0]["WxSuCaiDetailMemo"].ToString(); model.WxSuCaiDetailContent = ds.Tables[0].Rows[0]["WxSuCaiDetailContent"].ToString(); if (ds.Tables[0].Rows[0]["WxSuCaiDetailClassId"].ToString() != "") { model.WxSuCaiDetailClassId = int.Parse(ds.Tables[0].Rows[0]["WxSuCaiDetailClassId"].ToString()); } model.ImgId = ds.Tables[0].Rows[0]["ImgId"].ToString(); model.Url = ds.Tables[0].Rows[0]["Url"].ToString(); model.ReKey = ds.Tables[0].Rows[0]["ReKey"].ToString(); return(model); } else { return(model); } }
private void SaveSuCaiInfo() { Model.WxSuCaiInfoModel model = new WxSuCaiInfoModel(); BLL.WxBLL wbll = new BLL.WxBLL(); Model.CurrentMerModel cm = BLL.MerchantBLL.CurrentModel(); #region 事务开启 TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { #endregion model.WxSuCaiInfoId = ReDecimal("WxSuCaiInfoId", 0); if (model.WxSuCaiInfoId == 0) { //新增 } else { model = wbll.GetSuCaiInfoModel(model.WxSuCaiInfoId); } model.WxSuCaiTitle = ReStr("WxSuCaiTitle"); model.InputCode = ReStr("InputCode", Common.PinYin.GetCodstring(model.WxSuCaiTitle)); model.WxSuCaiContent = ReStrDeCode("WxSuCaiContent"); model.Memo = ReStr("Memo", ""); model.WxSuCaiTypeId = ReInt("WxSuCaiTypeId"); model.WxSuCaiClassId = ReInt("WxSuCaiClassId"); model.CreateUser = cm.CurrentUserId; model.Invalid = ReBool("Invalid", false); model.FmImgId = ReStr("FmImgId", ""); model.MerId = ReDecimal("MerId", cm.CurrentMerId); wbll.SaveSuCaiInfo(model); switch (model.WxSuCaiClassId) { case 2: //如果是图文 wbll.RemoveSuCaiDetail(" WxSuCaiInfoId='" + model.WxSuCaiInfoId + "' "); DataTable dtDetail = ReTable("detail"); if (dtDetail.Rows.Count == 0) { throw new Exception("图文回复需要至少一条明细!"); } foreach (DataRow drDetail in dtDetail.Rows) { Model.WxSuCaiDetailModel DetailModel = new WxSuCaiDetailModel(); DetailModel.ImgId = drDetail["ImgId"].ToString(); DetailModel.OrderNo = int.Parse(drDetail["OrderNo"].ToString()); DetailModel.OtherPara = drDetail["OtherPara"].ToString(); DetailModel.ReKey = drDetail["ReKey"].ToString(); DetailModel.Url = HttpUtility.UrlDecode(drDetail["Url"].ToString()); DetailModel.WxSuCaiInfoId = model.WxSuCaiInfoId; DetailModel.WxSuCaiDetailMemo = drDetail["WxSuCaiDetailMemo"].ToString(); try { DetailModel.WxSuCaiDetailClassId = int.Parse(drDetail["WxSuCaiDetailClassId"].ToString()); } catch { continue; } try { DetailModel.WxSuCaiDetailContent = drDetail["WxSuCaiDetailContent"].ToString(); } catch { DetailModel.WxSuCaiDetailContent = ""; } DetailModel.WxSuCaiDetailId = 0; //必须的,就靠它新增 DetailModel.WxSuCaiDetailTitle = drDetail["WxSuCaiDetailTitle"].ToString(); wbll.SaveSuCaiDetail(DetailModel); } break; default: //其他 break; } #region 事务关闭 transactionScope.Complete(); } #endregion ReDict2.Add("WxSuCaiInfoId", model.WxSuCaiInfoId.ToString()); ReTrue(); }