/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.prizes model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_prizes("); strSql.Append("user_id,user_name,prize,add_time"); strSql.Append(") values ("); strSql.Append("@user_id,@user_name,@prize,@add_time"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.VarChar, 150), new SqlParameter("@prize", SqlDbType.VarChar, 500), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.user_name; parameters[2].Value = model.prize; parameters[3].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.prizes GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, user_name, prize, add_time "); strSql.Append(" from dt_prizes "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.prizes model = new Model.prizes(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); model.prize = ds.Tables[0].Rows[0]["prize"].ToString(); if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.prizes model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_prizes set "); strSql.Append(" user_id = @user_id , "); strSql.Append(" user_name = @user_name , "); strSql.Append(" prize = @prize , "); strSql.Append(" add_time = @add_time "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.VarChar, 150), new SqlParameter("@prize", SqlDbType.VarChar, 500), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.user_id; parameters[2].Value = model.user_name; parameters[3].Value = model.prize; parameters[4].Value = model.add_time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.prizes model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.prizes model) { return(dal.Add(model)); }
/// <summary> /// 添加中间记录 /// </summary> /// <param name="user_id"></param> /// <param name="user_name"></param> /// <param name="prize"></param> private void add_prize(int user_id, string user_name, string prize) { Model.prizes model = new Model.prizes(); model.add_time = DateTime.Now; model.prize = prize; model.user_id = user_id; model.user_name = user_name; BLL.prizes pbll = new BLL.prizes(); pbll.Add(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.prizes GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, user_name, prize, add_time "); strSql.Append(" from dt_prizes "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.prizes model = new Model.prizes(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); model.prize = ds.Tables[0].Rows[0]["prize"].ToString(); if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return model; } else { return null; } }