/// <summary> /// 更新一条数据 /// </summary> public bool Update(WxKeyModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update CORE.dbo.WxKey set "); strSql.Append(" WxSendId = @WxSendId , "); strSql.Append(" KeyTitle = @KeyTitle , "); strSql.Append(" KeyTypeId = @KeyTypeId , "); strSql.Append(" KeyTypeDetailId = @KeyTypeDetailId "); strSql.Append(" where KeyId=@KeyId "); SqlParameter[] parameters = { new SqlParameter("@KeyId", SqlDbType.Decimal, 9), new SqlParameter("@WxSendId", SqlDbType.Decimal, 9), new SqlParameter("@KeyTitle", SqlDbType.VarChar, 100), new SqlParameter("@KeyTypeId", SqlDbType.VarChar, 50), new SqlParameter("@KeyTypeDetailId", SqlDbType.VarChar, 50) }; parameters[0].Value = model.KeyId; parameters[1].Value = model.WxSendId; parameters[2].Value = model.KeyTitle; parameters[3].Value = model.KeyTypeId; parameters[4].Value = model.KeyTypeDetailId; 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(WxKeyModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CORE.dbo.WxKey ("); strSql.Append("WxSendId,KeyTitle,KeyTypeId,KeyTypeDetailId"); strSql.Append(") values ("); strSql.Append("@WxSendId,@KeyTitle,@KeyTypeId,@KeyTypeDetailId"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@WxSendId", SqlDbType.Decimal, 9), new SqlParameter("@KeyTitle", SqlDbType.VarChar, 100), new SqlParameter("@KeyTypeId", SqlDbType.VarChar, 50), new SqlParameter("@KeyTypeDetailId", SqlDbType.VarChar, 50) }; parameters[0].Value = model.WxSendId; parameters[1].Value = model.KeyTitle; parameters[2].Value = model.KeyTypeId; parameters[3].Value = model.KeyTypeDetailId; 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 WxKeyModel GetModel(decimal KeyId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select KeyId, WxSendId, KeyTitle, KeyTypeId, KeyTypeDetailId "); strSql.Append(" from CORE.dbo.WxKey "); strSql.Append(" where KeyId=@KeyId"); SqlParameter[] parameters = { new SqlParameter("@KeyId", SqlDbType.Decimal) }; parameters[0].Value = KeyId; WxKeyModel model = new WxKeyModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["KeyId"].ToString() != "") { model.KeyId = decimal.Parse(ds.Tables[0].Rows[0]["KeyId"].ToString()); } if (ds.Tables[0].Rows[0]["WxSendId"].ToString() != "") { model.WxSendId = decimal.Parse(ds.Tables[0].Rows[0]["WxSendId"].ToString()); } model.KeyTitle = ds.Tables[0].Rows[0]["KeyTitle"].ToString(); model.KeyTypeId = ds.Tables[0].Rows[0]["KeyTypeId"].ToString(); model.KeyTypeDetailId = ds.Tables[0].Rows[0]["KeyTypeDetailId"].ToString(); return(model); } else { return(model); } }
private void SaveSendInfo() { #region 事务开启 TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { #endregion Model.WxSendInfoModel model = new WxSendInfoModel(); BLL.WxBLL bll = new BLL.WxBLL(); model.WxSendId = ReDecimal("WxSendId", 0); if (model.WxSendId == 0) { model.WxPtId = ReDecimal("WxPtId"); } else { //如果是修改, 选取出原来的数据 model = bll.GetWxSendModel(model.WxSendId); } model.WxSendTitle = ReStr("WxSendTitle"); model.WxSendType = ReStr("WxSendType"); model.WxSendClassId = ReInt("WxSendClassId"); model.Memo = ReStr("Memo"); model.FmImgId = ReStr("FmImgId"); model.WxSuCaiId = ReDecimal("WxSuCaiId", 0); model.SendContent = ReStrDeCode("SendContent"); bll.SaveSendInfo(model); DataTable dtKeys = ReTable("KeysAreray"); if (dtKeys.Rows.Count == 0) { throw new Exception("没有添加激发时间, 这个回应没有触发将没有意义!"); } DAL.WxKeyDAL keyDal = new DAL.WxKeyDAL(); keyDal.DeleteList(" WxSendId='" + model.WxSendId + "' "); //首先删除所有的key关联关系 foreach (DataRow drKeys in dtKeys.Rows) { if (model.WxSendId == 0) { throw new Exception("在执行插入之后,WxSendId不能为0!"); } Model.WxKeyModel KeyModel = new WxKeyModel(); KeyModel.WxSendId = model.WxSendId; KeyModel.KeyTitle = drKeys["KeyTitle"].ToString(); KeyModel.KeyTypeId = drKeys["KeyTypeId"].ToString(); KeyModel.KeyTypeDetailId = drKeys["KeyTypeDetailId"].ToString(); keyDal.Add(KeyModel); //逐个添加新的关联关系 } ReDict.Add("WxSendId", model.WxSendId); #region 事务关闭 transactionScope.Complete(); } #endregion ReTrue(); }