/// <summary> /// 增加一条数据 /// </summary> public int Add(ROYcms.Sys.Model.ROYcms_Class_UGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + PubConstant.date_prefix + "Class_UGroup("); strSql.Append("Class_id,UGroup_id,User_id,Time)"); strSql.Append(" values ("); strSql.Append("@Class_id,@UGroup_id,@User_id,@Time)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Class_id", SqlDbType.Int, 4), new SqlParameter("@UGroup_id", SqlDbType.Int, 4), new SqlParameter("@User_id", SqlDbType.Int, 4), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.Class_id; parameters[1].Value = model.UGroup_id; parameters[2].Value = model.User_id; parameters[3].Value = model.Time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(ROYcms.Sys.Model.ROYcms_Class_UGroup model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + PubConstant.date_prefix + "Class_UGroup set "); strSql.Append("Class_id=@Class_id,"); strSql.Append("UGroup_id=@UGroup_id,"); strSql.Append("User_id=@User_id,"); strSql.Append("Time=@Time"); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@Class_id", SqlDbType.Int, 4), new SqlParameter("@UGroup_id", SqlDbType.Int, 4), new SqlParameter("@User_id", SqlDbType.Int, 4), new SqlParameter("@Time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.Class_id; parameters[2].Value = model.UGroup_id; parameters[3].Value = model.User_id; parameters[4].Value = model.Time; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public ROYcms.Sys.Model.ROYcms_Class_UGroup GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,Class_id,UGroup_id,User_id,Time from " + PubConstant.date_prefix + "Class_UGroup "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; ROYcms.Sys.Model.ROYcms_Class_UGroup model = new ROYcms.Sys.Model.ROYcms_Class_UGroup(); 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]["Class_id"].ToString() != "") { model.Class_id = int.Parse(ds.Tables[0].Rows[0]["Class_id"].ToString()); } if (ds.Tables[0].Rows[0]["UGroup_id"].ToString() != "") { model.UGroup_id = int.Parse(ds.Tables[0].Rows[0]["UGroup_id"].ToString()); } if (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]["Time"].ToString() != "") { model.Time = DateTime.Parse(ds.Tables[0].Rows[0]["Time"].ToString()); } return(model); } else { return(null); } }