/// <summary> /// 得到一个对象实体 /// </summary> public ROYcms.Sys.Model.ROYcms_Authority GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,GroupId,Rid,TYPE,StarTime,EndTime from ROYcms_Authority "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; ROYcms.Sys.Model.ROYcms_Authority model = new ROYcms.Sys.Model.ROYcms_Authority(); 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]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "") { model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } if (ds.Tables[0].Rows[0]["GroupId"] != null && ds.Tables[0].Rows[0]["GroupId"].ToString() != "") { model.GroupId = int.Parse(ds.Tables[0].Rows[0]["GroupId"].ToString()); } if (ds.Tables[0].Rows[0]["Rid"] != null && ds.Tables[0].Rows[0]["Rid"].ToString() != "") { model.Rid = int.Parse(ds.Tables[0].Rows[0]["Rid"].ToString()); } if (ds.Tables[0].Rows[0]["TYPE"] != null && ds.Tables[0].Rows[0]["TYPE"].ToString() != "") { model.TYPE = int.Parse(ds.Tables[0].Rows[0]["TYPE"].ToString()); } if (ds.Tables[0].Rows[0]["StarTime"] != null && ds.Tables[0].Rows[0]["StarTime"].ToString() != "") { model.StarTime = DateTime.Parse(ds.Tables[0].Rows[0]["StarTime"].ToString()); } if (ds.Tables[0].Rows[0]["EndTime"] != null && ds.Tables[0].Rows[0]["EndTime"].ToString() != "") { model.EndTime = DateTime.Parse(ds.Tables[0].Rows[0]["EndTime"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ROYcms.Sys.Model.ROYcms_Authority model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ROYcms_Authority set "); strSql.Append("UserId=@UserId,"); strSql.Append("GroupId=@GroupId,"); strSql.Append("Rid=@Rid,"); strSql.Append("TYPE=@TYPE,"); strSql.Append("StarTime=@StarTime,"); strSql.Append("EndTime=@EndTime"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@GroupId", SqlDbType.Int, 4), new SqlParameter("@Rid", SqlDbType.Int, 4), new SqlParameter("@TYPE", SqlDbType.Int, 4), new SqlParameter("@StarTime", SqlDbType.DateTime), new SqlParameter("@EndTime", SqlDbType.DateTime), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.GroupId; parameters[2].Value = model.Rid; parameters[3].Value = model.TYPE; parameters[4].Value = model.StarTime; parameters[5].Value = model.EndTime; parameters[6].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ROYcms.Sys.Model.ROYcms_Authority model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ROYcms_Authority("); strSql.Append("UserId,GroupId,Rid,TYPE,StarTime,EndTime)"); strSql.Append(" values ("); strSql.Append("@UserId,@GroupId,@Rid,@TYPE,@StarTime,@EndTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@GroupId", SqlDbType.Int, 4), new SqlParameter("@Rid", SqlDbType.Int, 4), new SqlParameter("@TYPE", SqlDbType.Int, 4), new SqlParameter("@StarTime", SqlDbType.DateTime), new SqlParameter("@EndTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.GroupId; parameters[2].Value = model.Rid; parameters[3].Value = model.TYPE; parameters[4].Value = model.StarTime; parameters[5].Value = model.EndTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }