/// <summary> /// 新增Permission对象 /// </summary> /// <param name="Permission">需要新增的对象</param> /// <returns>新插入数据的PermissionID</returns> public Int32 AddPermission(Permission obj) { if(obj != null) { return Convert.ToInt32(_dal.InsertReturnID(obj)); } return -1; }
/// <summary> /// 插入一条数据并返回PermissionID /// </summary> /// <param name="Permission">需要插入的对象</param> /// <returns>新插入数据的PermissionID</returns> public Object InsertReturnID(Permission obj) { //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@JoinID",obj.JoinID), new SqlParameter("@JoinType",obj.JoinType), new SqlParameter("@FunctionID",obj.FunctionID), new SqlParameter("@PermissionType",obj.PermissionType), new SqlParameter("@AddTime",obj.AddTime), new SqlParameter("@Status",obj.Status) }; return SqlHelper.ExecuteScalar(SqlHelper.connectionString, _SQL_INSERT_RETURNID, CommandType.Text, param); }
/// <summary> /// 插入一条数据 /// </summary> /// <param name="Permission">需要插入的对象</param> /// <returns>影响行数</returns> public Int32 Insert(Permission obj) { //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@JoinID",obj.JoinID), new SqlParameter("@JoinType",obj.JoinType), new SqlParameter("@FunctionID",obj.FunctionID), new SqlParameter("@PermissionType",obj.PermissionType), new SqlParameter("@AddTime",obj.AddTime), new SqlParameter("@Status",obj.Status) }; return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, _SQL_INSERT, CommandType.Text, param); }
/// <summary> /// 将SqlDataReader对象转换成Permission对象 /// </summary> /// <param name="dr">SqlDataReader对象</param> /// <returns></returns> private Permission ToObject(SqlDataReader dr) { using (dr) { if (dr.HasRows) { while (dr.Read()) { Permission model = new Permission(); model.PermissionID = Convert.ToInt32(dr["PermissionID"]); model.JoinID = Convert.ToInt32(dr["JoinID"]); model.JoinType = Convert.ToByte(dr["JoinType"]); model.FunctionID = Convert.ToInt32(dr["FunctionID"]); model.PermissionType = Convert.ToByte(dr["PermissionType"]); model.AddTime = Convert.ToDateTime(dr["AddTime"]); model.Status = Convert.ToByte(dr["Status"]); return model; } } } return null; }
/// <summary> /// 将SqlDataReader对象转换成Permission对象集合 /// </summary> /// <param name="dr">SqlDataReader对象</param> /// <returns></returns> private List<Permission> ToList(SqlDataReader dr) { List<Permission> list = null; using (dr) { if (dr.HasRows) { list = new List<Permission>(); while (dr.Read()) { Permission model = new Permission(); model.PermissionID = Convert.ToInt32(dr["PermissionID"]); model.JoinID = Convert.ToInt32(dr["JoinID"]); model.JoinType = Convert.ToByte(dr["JoinType"]); model.FunctionID = Convert.ToInt32(dr["FunctionID"]); model.PermissionType = Convert.ToByte(dr["PermissionType"]); model.AddTime = Convert.ToDateTime(dr["AddTime"]); model.Status = Convert.ToByte(dr["Status"]); list.Add(model); } } } return list; }
/// <summary> /// 更新一条新数据。 /// </summary> /// <param name="Permission">需要更新的对象</param> /// <returns>影响行数</returns> public Int32 Update(Permission obj) { //将WHERE条件组合进SQL语句 String sqlStr = String.Format(_SQL_UPDATE, "WHERE [PermissionID] = @PermissionID"); //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@PermissionID",obj.PermissionID), new SqlParameter("@JoinID",obj.JoinID), new SqlParameter("@JoinType",obj.JoinType), new SqlParameter("@FunctionID",obj.FunctionID), new SqlParameter("@PermissionType",obj.PermissionType), new SqlParameter("@AddTime",obj.AddTime), new SqlParameter("@Status",obj.Status) }; return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, sqlStr, CommandType.Text, param); }
/// <summary> /// 修改Permission对象 /// </summary> /// <param name="Permission">需要修改的对象</param> /// <returns>影响行数</returns> public Int32 SetPermission(Permission obj) { if(obj != null) { return _dal.Update(obj); } return -1; }