ERP权限系统(七)

网友投稿 604 2022-08-31

ERP权限系统(七)

ERP权限系统(七)

添加链接权限的字段:

//权限管理 n.Target = "MainFrame"; //折叠 TreeView1.Nodes.Add(n); n.Expanded = false;

页面设计:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserRightManger.aspx.cs" Inherits="BioErpWeb.HRSystem.UserRightManger" %><%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

权限信息添加
权限名
备注
权限信息编辑
权限名
备注
权限管理系统

权限的添加和修改的存储过程:

ALTER PROCEDURE [dbo].[tbRight_ADD]@RightName nvarchar(50),@ReMark nvarchar(50) AS INSERT INTO [tbRight]( [RightName],[ReMark] )VALUES( @RightName,@ReMark )--------修改-----ALTER PROCEDURE [dbo].[tbRight_Update]@ID int,@RightName nvarchar(50),@ReMark nvarchar(50) AS UPDATE [tbRight] SET [RightName] = @RightName,[ReMark] = @ReMark WHERE ID=@ID

-- Description: 根据权限id获取权限信息-- =============================================ALTER PROCEDURE [dbo].[getRightById] @id int ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT ID, RightName, ReMark FROM tbRight WHERE ID=@idEND

权限查询:

所需组件:Gridview,AspNetPager

调用分页业务方法实现分页查询

权限添加和修改:

使用Ajax组件

ModalPopupExtender

相关属性:

TargetControlID:设置触发事件的控件(如按钮)

PopupControlID:设置要显示的面板

BLL层的代码:

public class UserManagerBLL { ///

/// 添加员工信息 /// /// user public int UserMangerAdd(UserManager user) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@LoginName",user.LoginName), new SqlParameter("@UserName",user.UserName), new SqlParameter("@Password",user.Password), new SqlParameter("@DepartmentId",user.DepartmentId), new SqlParameter("@RoleId",user.RoleId), new SqlParameter("@Birthday",user.Birthday), new SqlParameter("@Mobile",user.Mobile), new SqlParameter("@Email",user.Email), new SqlParameter("@Photo",user.Photo), new SqlParameter("@Address",user.Address), new SqlParameter("@LastLoginDate",user.LastLoginDate), new SqlParameter("@Sex",user.Sex), new SqlParameter("@DisplayOrder",user.DisplayOrder), new SqlParameter("@Sate",user.Sate) }; return DataBaseHelper.ExcuteSqlReturnInt("UserManager_ADD", CommandType.StoredProcedure, pars); } /// /// 员工修改 /// /// 员工对象 /// int public int UserManagerUpdate(UserManager user) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@UserId",user.UserId), new SqlParameter("@LoginName",user.LoginName), new SqlParameter("@UserName",user.UserName), new SqlParameter("@Password",user.Password), new SqlParameter("@DepartmentId",user.DepartmentId), new SqlParameter("@RoleId",user.RoleId), new SqlParameter("@Birthday",user.Birthday), new SqlParameter("@Mobile",user.Mobile), new SqlParameter("@Email",user.Email), new SqlParameter("@Photo",user.Photo), new SqlParameter("@Address",user.Address), new SqlParameter("@LastLoginDate",user.LastLoginDate), new SqlParameter("@Sex",user.Sex), new SqlParameter("@DisplayOrder",user.DisplayOrder), new SqlParameter("@Sate",user.Sate) }; return DataBaseHelper.ExcuteSqlReturnInt("UserManager_Update", CommandType.StoredProcedure, pars); } /// /// 根据指定ID返回其对象 /// /// userid /// UserManager public UserManager getuserbyId(string id) { UserManager user = new UserManager(); SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@userid",id) }; SqlDataReader reader = DataBaseHelper.SelectSQLReturnReader("getUserByid", CommandType.StoredProcedure, pars); while (reader.Read()) { user.LoginName = reader["LoginName"].ToString(); user.UserName = reader["UserName"].ToString(); user.DepartmentId =int.Parse(reader["DepartmentId"].ToString()); user.RoleId = int.Parse(reader["RoleId"].ToString()); user.Birthday =Convert.ToDateTime(reader["Birthday"].ToString()); user.Mobile = reader["Mobile"].ToString(); user.Email = reader["Email"].ToString(); user.Photo = reader["Photo"].ToString(); user.Address = reader["Address"].ToString(); user.LastLoginDate = Convert.ToDateTime(reader["LastLoginDate"].ToString()); user.Sex = reader["Sex"].ToString() == "True" ? true : false; user.DisplayOrder =int.Parse( reader["DisplayOrder"].ToString()); user.Sate = reader["Sate"].ToString() == "True" ? true : false; } reader.Close(); return user; } }

后台代码的实现:

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { pagebind(); } } public static int pageindex = 0; public static int pagesize = 10; public static string condition = ""; protected void pagebind() { this.AspNetPager1.RecordCount = SqlComm.getDataCountByCondition("tbRight", condition); this.AspNetPager1.PageSize = pagesize; this.GridView1.DataSource = SqlComm.getDataByPageIndex("tbRight", "*", "ID", condition, pageindex, pagesize); this.GridView1.DataBind(); } protected void btnAdd_Click(object sender, EventArgs e) { tbRight right = new tbRight(); UserRightMangerBLL rightbll = new UserRightMangerBLL(); right.RightName = this.txtRightName0.Text; right.ReMark = this.txtReMark0.Text; if (rightbll.UserRightAdd(right) == 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "alert('提交失败')", true); } else { pagebind(); } } protected void AspNetPager1_PageChanged(object sender, EventArgs e) { pageindex = this.AspNetPager1.CurrentPageIndex - 1; pagebind(); } public static tbRight right1; public static UserRightMangerBLL userrightbll; protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "imgEdit")//编辑 { string id = e.CommandArgument.ToString(); userrightbll = new UserRightMangerBLL(); right1 = new tbRight(); right1= userrightbll.getUserRightByID(id); this.txtRightName1.Text = right1.RightName; this.txtReMark1.Text = right1.ReMark; this.Modal_Update.Show(); } if (e.CommandName == "imgDelete")//删除单条记录 { if (SqlComm.DeleteTableByCondition("dbo.tbRight", " where id='" + e.CommandArgument.ToString() + "'")) { pagebind(); } } if (e.CommandName == "allcheck") //全选 { for (int i = 0; i < this.GridView1.Rows.Count; i++) { ((CheckBox)this.GridView1.Rows[i].FindControl("check_all")).Checked = true; } } if (e.CommandName == "recheck") //反选 { for (int i = 0; i < this.GridView1.Rows.Count; i++) { if (((CheckBox)this.GridView1.Rows[i].FindControl("check_all")).Checked == true) { ((CheckBox)this.GridView1.Rows[i].FindControl("check_all")).Checked = false; } else { ((CheckBox)this.GridView1.Rows[i].FindControl("check_all")).Checked = true; } } } if (e.CommandName == "DeleteChecked")//删除选中的 { for (int i = 0; i < this.GridView1.Rows.Count; i++) { if (((CheckBox)this.GridView1.Rows[i].FindControl("check_all")).Checked == true) { SqlComm.DeleteTableByCondition("tbRight", "where ID=" + this.GridView1.DataKeys[i].Value.ToString()); } } pagebind(); } } protected void btnUpdate_Click(object sender, EventArgs e) { right1.RightName = this.txtRightName1.Text; right1.ReMark = this.txtReMark1.Text; if (userrightbll.UserRightUpdate(right1) != 0) { pagebind(); //ScriptManager.RegisterStartupScript(this, this.GetType(), "test", "alert('提交成功')", true); } }

权限的设置:

界面的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserRightSet.aspx.cs" Inherits="BioErpWeb.HRSystem.UserRightSet" %>

员工权限设置

BLL层的代码:

///

/// 根据编号获取权限信息 /// /// id /// tbRight public tbRight getUserRightByID(string id) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@id",int.Parse(id)) }; tbRight right = new tbRight(); SqlDataReader reader= DataBaseHelper.SelectSQLReturnReader("getRightById", CommandType.StoredProcedure, pars); if (reader.Read()) { right.ID = int.Parse(id); right.RightName = reader["RightName"].ToString(); right.ReMark = reader["ReMark"].ToString(); } reader.Close(); return right; } /// /// 给用户添加权限 /// /// 权限值 /// int public int addtbUserRight(tbUserRight tbuserright) { SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@RightID",tbuserright.RightID), new SqlParameter("@UserID",tbuserright.UserID) }; return DataBaseHelper.ExcuteSqlReturnInt("tbUserRight_Add", CommandType.StoredProcedure, pars); }

UI层的代码:

public partial class UserRightSet : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RightListBind(); } } public void RightListBind() { this.cblRightList.DataSource= SqlComm.GetDataByTableName("tbRight").Tables[0]; this.cblRightList.DataTextField = "RightName"; this.cblRightList.DataValueField = "ID"; this.cblRightList.DataBind(); } protected void txtUserName_TextChanged(object sender, EventArgs e) { if (txtUserName.Text != "请选择") { DataTable dt = SqlComm.GetDataByCondition("tbUserRight", "ID,UserID,RightID", " userid=" + this.txtUserName.Text.Trim()).Tables[0]; //每次重新选择用户后复选框列表中的数据重新设为Flase CheckBoxListReset(); //重新绑定选中员工的权限至列表 for (int j = 0; j < dt.Rows.Count; j++) { for (int i = 0; i < cblRightList.Items.Count; i++) { if (cblRightList.Items[i].Value == dt.Rows[j]["RightID"].ToString()) { cblRightList.Items[i].Selected = true; } } } } } ///

/// 重置复选框列表 /// private void CheckBoxListReset() { for (int i = 0; i < cblRightList.Items.Count; i++) { cblRightList.Items[i].Selected = false; } } protected void btnSave_Click(object sender, EventArgs e) { if (this.txtUserName.Text.Trim() == "" || this.txtUserName.Text.Trim().Length == 0) { ClientScript.RegisterStartupScript(this.GetType(), "test", ""); return; } //删除指定用户的所有权限 DeleteUserRight(this.txtUserName.Text.Trim()); //通过循环遍历给指定用户添加相应权限值 for (int i = 0; i < cblRightList.Items.Count; i++) { if (cblRightList.Items[i].Selected) { AddUserRight(int.Parse(cblRightList.Items[i].Value.ToString()),int.Parse(this.txtUserName.Text.Trim())); } } CheckBoxListReset(); //清空值 this.txtUserName.Text = ""; } /// /// 根据ID删除指定员工权限信息 /// /// /// private bool DeleteUserRight(string userid) { return SqlComm.DeleteTableByCondition("tbUserRight", " where UserID=" + userid); } /// /// 给用户添加一个权限信息 /// /// 权限信息对象 /// private int AddUserRight(int rightid,int userid) { UserRightMangerBLL userightbll = new UserRightMangerBLL(); //给用户权限对象赋值 tbUserRight tbuserright = new tbUserRight(); tbuserright.RightID = rightid; tbuserright.UserID = userid; //调用相应的业务方法实现给用户添加权限 return userightbll.addtbUserRight(tbuserright); } }

添加权限的存储过程:

-- Description: 给用户添加一条权限信息-- =============================================ALTER PROCEDURE [dbo].[tbUserRight_Add] @UserID int,@RightID intASBEGIN SET NOCOUNT ON; INSERT tbUserRight ( UserID, RightID ) VALUES ( @UserID, @RightID )END

效果:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SqlServr分页存储过程的写法
下一篇:什么是内存对齐?Go 是否有必要内存对齐?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~