/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.PointRule model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into PointRule("); strSql.Append("RName,RxValue,RyValue)"); strSql.Append(" values ("); strSql.Append("@RName,@RxValue,@RyValue)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "RName", DbType.String, model.RName); db.AddInParameter(dbCommand, "RxValue", DbType.String, model.RxValue); db.AddInParameter(dbCommand, "RyValue", DbType.String, model.RyValue); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.PointRule model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update PointRule set "); strSql.Append("RName=@RName,"); strSql.Append("RxValue=@RxValue,"); strSql.Append("RyValue=@RyValue"); strSql.Append(" where RID=@RID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "RID", DbType.Int32, model.RID); db.AddInParameter(dbCommand, "RName", DbType.String, model.RName); db.AddInParameter(dbCommand, "RxValue", DbType.String, model.RxValue); db.AddInParameter(dbCommand, "RyValue", DbType.String, model.RyValue); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.PointRule ReaderBind(IDataReader dataReader) { Model.PointRule model = new Model.PointRule(); object ojb; ojb = dataReader["RID"]; if (ojb != null && ojb != DBNull.Value) { model.RID = Convert.ToInt32(ojb); } model.RName = dataReader["RName"].ToString(); model.RxValue = dataReader["RxValue"].ToString(); model.RyValue = dataReader["RyValue"].ToString(); return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.PointRule GetModel(int RID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select RID,RName,RxValue,RyValue from PointRule "); strSql.Append(" where RID=@RID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "RID", DbType.Int32, RID); Model.PointRule model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.PointRule DataRowToModel(DataRow row) { Model.PointRule model = new Model.PointRule(); if (row != null) { if (row["RID"] != null && row["RID"].ToString() != "") { model.RID = Convert.ToInt32(row["RID"].ToString()); } if (row["RName"] != null) { model.RName = row["RName"].ToString(); } if (row["RxValue"] != null) { model.RxValue = row["RxValue"].ToString(); } if (row["RyValue"] != null) { model.RyValue = row["RyValue"].ToString(); } } return(model); }