基本信息
源码名称:C# orm 入门级实例代码
源码大小:0.47M
文件格式:.rar
开发语言:C#
更新时间:2015-12-05
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using Models; namespace DAL { public static partial class RightService { #region Select public static IList<Right> GetAllRights() { string sqlAll = "SELECT * FROM Rights"; return GetRightsBySql( sqlAll ); } public static Right GetRightByRightId(int rightId) { string sql = "SELECT * FROM Rights WHERE RightId = @RightId"; try { IDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@RightId", rightId)); if (reader.Read()) { Right right = new Right(); if(!Convert.IsDBNull(reader["RightId"])) right.RightId = (int)reader["RightId"]; if(!Convert.IsDBNull(reader["RightName"])) right.RightName = (string)reader["RightName"]; reader.Close(); right.BeforeReadNullRoles = new EventHandler(right_BeforeReadNullRoles); return right; } else { reader.Close(); return null; } } catch (Exception e) { //Console.WriteLine(e.Message); throw e; } } static void right_BeforeReadNullRoles(object sender, EventArgs e) { Right right = sender as Right; right.Roles = RoleService.GetRolesByRightId(right.RightId); } public static IList<Right> GetRightsByRoleId(int roleId) { string sql = "select * from rights where rightId in (select RightId from RoleRight where RoleId = @RoleId)"; SqlParameter para = new SqlParameter("@RoleId", roleId); return GetRightsBySql(sql, para); } private static IList<Right> GetRightsBySql( string sql, params SqlParameter[] values ) { List<Right> list = new List<Right>(); try { DataTable table = DBHelper.GetDataSet( sql, values ); foreach (DataRow row in table.Rows) { Right right = new Right(); if(!Convert.IsDBNull(row["RightId"])) right.RightId = (int)row["RightId"]; if(!Convert.IsDBNull(row["RightName"])) right.RightName = (string)row["RightName"]; right.BeforeReadNullRoles = new EventHandler(right_BeforeReadNullRoles); list.Add(right); } return list; } catch (Exception e) { //Console.WriteLine(e.Message); throw e; } } #endregion select } }
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Models; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void DetailsView1_ItemCreated(object sender, EventArgs e) { User user = DetailsView1.DataItem as User; if (user == null) return; Label lblRoles = DetailsView1.FindControl("lblRoles") as Label; if (lblRoles != null) { lblRoles.Text = string.Empty; foreach (Role role in user.Roles) { lblRoles.Text = role.RoleId.ToString() "." role.RoleName "<BR>"; } } } protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e) { GridView1.DataBind(); } protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { GridView1.DataBind(); } }