/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.share model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_share("); strSql.Append("user_id,user_name,type,add_time"); strSql.Append(") values ("); strSql.Append("@user_id,@user_name,@type,@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("@type", SqlDbType.VarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.user_name; parameters[2].Value = model.type; 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.share GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, user_name, type, add_time "); strSql.Append(" from dt_share "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.share model = new Model.share(); 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.type = ds.Tables[0].Rows[0]["type"].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.share model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_share set "); strSql.Append(" user_id = @user_id , "); strSql.Append(" user_name = @user_name , "); strSql.Append(" type = @type , "); 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("@type", SqlDbType.VarChar, 50), 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.type; 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.share model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.share model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.share GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, user_name, type, add_time "); strSql.Append(" from dt_share "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.share model = new Model.share(); 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.type = ds.Tables[0].Rows[0]["type"].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; } }