/// <summary> /// 得到一个对象实体 /// </summary> public Model.users.user_code GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,user_id,user_name,type,str_code,count,status,eff_time,add_time from " + databaseprefix + "user_code "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.users.user_code model = new Model.users.user_code(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && 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"] != null && ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } if (ds.Tables[0].Rows[0]["user_name"] != null && ds.Tables[0].Rows[0]["user_name"].ToString() != "") { model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = ds.Tables[0].Rows[0]["type"].ToString(); } if (ds.Tables[0].Rows[0]["str_code"] != null && ds.Tables[0].Rows[0]["str_code"].ToString() != "") { model.str_code = ds.Tables[0].Rows[0]["str_code"].ToString(); } if (ds.Tables[0].Rows[0]["count"] != null && ds.Tables[0].Rows[0]["count"].ToString() != "") { model.count = int.Parse(ds.Tables[0].Rows[0]["count"].ToString()); } if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (ds.Tables[0].Rows[0]["eff_time"] != null && ds.Tables[0].Rows[0]["eff_time"].ToString() != "") { model.eff_time = DateTime.Parse(ds.Tables[0].Rows[0]["eff_time"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"] != null && 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.users.user_code model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "user_code set "); strSql.Append("user_id=@user_id,"); strSql.Append("user_name=@user_name,"); strSql.Append("type=@type,"); strSql.Append("str_code=@str_code,"); strSql.Append("count=@count,"); strSql.Append("status=@status,"); strSql.Append("eff_time=@eff_time,"); strSql.Append("add_time=@add_time"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 100), new SqlParameter("@type", SqlDbType.NVarChar, 20), new SqlParameter("@str_code", SqlDbType.NVarChar, 255), new SqlParameter("@count", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.TinyInt, 1), new SqlParameter("@eff_time", SqlDbType.DateTime), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.user_id; parameters[1].Value = model.user_name; parameters[2].Value = model.type; parameters[3].Value = model.str_code; parameters[4].Value = model.count; parameters[5].Value = model.status; parameters[6].Value = model.eff_time; parameters[7].Value = model.add_time; parameters[8].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.users.user_code model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "user_code("); strSql.Append("user_id,user_name,type,str_code,count,status,eff_time,add_time)"); strSql.Append(" values ("); strSql.Append("@user_id,@user_name,@type,@str_code,@count,@status,@eff_time,@add_time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@user_name", SqlDbType.NVarChar, 100), new SqlParameter("@type", SqlDbType.NVarChar, 20), new SqlParameter("@str_code", SqlDbType.NVarChar, 255), new SqlParameter("@count", SqlDbType.Int, 4), new SqlParameter("@status", SqlDbType.TinyInt, 1), new SqlParameter("@eff_time", SqlDbType.DateTime), 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.str_code; parameters[4].Value = model.count; parameters[5].Value = model.status; parameters[6].Value = model.eff_time; parameters[7].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.users.user_code model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.users.user_code model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.users.user_code GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,user_id,user_name,type,str_code,count,status,eff_time,add_time from " + databaseprefix + "user_code "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4)}; parameters[0].Value = id; Model.users.user_code model = new Model.users.user_code(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"] != null && 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"] != null && ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } if (ds.Tables[0].Rows[0]["user_name"] != null && ds.Tables[0].Rows[0]["user_name"].ToString() != "") { model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString(); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = ds.Tables[0].Rows[0]["type"].ToString(); } if (ds.Tables[0].Rows[0]["str_code"] != null && ds.Tables[0].Rows[0]["str_code"].ToString() != "") { model.str_code = ds.Tables[0].Rows[0]["str_code"].ToString(); } if (ds.Tables[0].Rows[0]["count"] != null && ds.Tables[0].Rows[0]["count"].ToString() != "") { model.count = int.Parse(ds.Tables[0].Rows[0]["count"].ToString()); } if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (ds.Tables[0].Rows[0]["eff_time"] != null && ds.Tables[0].Rows[0]["eff_time"].ToString() != "") { model.eff_time = DateTime.Parse(ds.Tables[0].Rows[0]["eff_time"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"] != null && 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; } }