/// <summary> /// 增加一条数据 /// </summary> public bool Add(MerchantVsUserModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MerchantVsUser("); strSql.Append("MerchantId,UserId,Power,Memo"); strSql.Append(") values ("); strSql.Append("@MerchantId,@UserId,@Power,@Memo"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@MerchantId", SqlDbType.Decimal, 9), new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@Power", SqlDbType.Int, 4), new SqlParameter("@Memo", SqlDbType.VarChar, 200) }; parameters[0].Value = model.MerchantId; parameters[1].Value = model.UserId; parameters[2].Value = model.Power; parameters[3].Value = model.Memo; 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 bool Update(MerchantVsUserModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update MerchantVsUser set "); strSql.Append(" MerchantId = @MerchantId , "); strSql.Append(" UserId = @UserId , "); strSql.Append(" Power = @Power , "); strSql.Append(" Memo = @Memo "); strSql.Append(" where MerchantId=@MerchantId and UserId=@UserId "); SqlParameter[] parameters = { new SqlParameter("@MerchantId", SqlDbType.Decimal, 9), new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@Power", SqlDbType.Int, 4), new SqlParameter("@Memo", SqlDbType.VarChar, 200) }; parameters[0].Value = model.MerchantId; parameters[1].Value = model.UserId; parameters[2].Value = model.Power; parameters[3].Value = model.Memo; 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 MerchantVsUserModel GetModel(decimal MerchantId, string UserId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select MerchantId, UserId, Power, Memo "); strSql.Append(" from MerchantVsUser "); strSql.Append(" where MerchantId=@MerchantId and UserId=@UserId "); SqlParameter[] parameters = { new SqlParameter("@MerchantId", SqlDbType.Decimal, 9), new SqlParameter("@UserId", SqlDbType.VarChar, 50) }; parameters[0].Value = MerchantId; parameters[1].Value = UserId; MerchantVsUserModel model = new MerchantVsUserModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["MerchantId"].ToString() != "") { model.MerchantId = decimal.Parse(ds.Tables[0].Rows[0]["MerchantId"].ToString()); } model.UserId = ds.Tables[0].Rows[0]["UserId"].ToString(); if (ds.Tables[0].Rows[0]["Power"].ToString() != "") { model.Power = int.Parse(ds.Tables[0].Rows[0]["Power"].ToString()); } model.Memo = ds.Tables[0].Rows[0]["Memo"].ToString(); return(model); } else { return(null); } }