123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using System.Collections.Generic;
- //using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- //
- using System.Data;
- namespace Com.Jpsoft.Hospital.Web.Module.Sys.Re_UserRole
- {
- public partial class Insert : Com.Jpsoft.Hospital.Web.Common.BasePage
- {
- Com.Jpsoft.Hospital.BLL.jp_sys_user user = new Com.Jpsoft.Hospital.BLL.jp_sys_user();
- Com.Jpsoft.Hospital.Model.jp_sys_user usermodel = new Com.Jpsoft.Hospital.Model.jp_sys_user();
- Com.Jpsoft.Hospital.Model.jp_sys_userrole userrolemodel = new Com.Jpsoft.Hospital.Model.jp_sys_userrole();
- Com.Jpsoft.Hospital.BLL.jp_sys_userrole userrole = new Com.Jpsoft.Hospital.BLL.jp_sys_userrole();
- Com.Jpsoft.Hospital.BLL.jp_sys_role role = new Com.Jpsoft.Hospital.BLL.jp_sys_role();
- Com.Jpsoft.Hospital.Model.jp_sys_role rolemodel = new Com.Jpsoft.Hospital.Model.jp_sys_role();
- public string CheckBoxName = string.Empty;
- public string RoleName = string.Empty;
- public string RoleDesc = string.Empty;
- protected void Page_Load(object sender, EventArgs e)
- {
-
- if (!IsPostBack)
- {
- if (Request.QueryString["user_id"] != null && Request.QueryString["user_id"].ToString().Trim() != "")
- {
- int uid = int.Parse(Request.QueryString["user_id"].ToString());
- ShowData(uid);
- }
- }
- }
- private void ShowData(int id)
- {
- usermodel = user.GetModel(id);
- if (usermodel != null)
- {
- this.username.Text = usermodel.user_loginname.ToString();
- this.remark.Text = usermodel.user_remark.ToString();
- this.id.Text = usermodel.user_id.ToString();
- }
- DataTable dt = role.GetAllList().Tables[0];
- if (dt.Rows.Count > 0)
- {
- this.repeat.DataSource = dt;
- this.repeat.DataBind();
- }
- //进入界面时显示用户的角色信息
- DataTable userdt=userrole.GetList(" ur_userid="+usermodel.user_id).Tables[0];
- if (userdt.Rows.Count > 0)
- {
- for (int i = 0; i < userdt.Rows.Count; i++)
- {
- int ur_roleid = int.Parse(userdt.Rows[i]["ur_roleid"].ToString());
- foreach (RepeaterItem ri in repeat.Items)
- {
- CheckBox cbox =(CheckBox)ri.FindControl("cb");
- if (cbox.Text == ur_roleid.ToString())
- {
- cbox.Checked = true;
- }
- }
- }
- }
- }
- protected void btnBack_Click(object sender, EventArgs e)
- {
- Response.Redirect("../User/List.aspx");
- }
- protected void btnOK_Click(object sender, EventArgs e)
- {
- //删除数据
- int uid = int.Parse(this.id.Text);
- DataTable dt = userrole.GetList(" ur_userid=" + uid).Tables[0];
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- int urid = int.Parse(dt.Rows[i]["ur_id"].ToString());
- try
- {
- userrole.Delete(urid);
- }
- catch (Exception ex)
- {
- Response.Write("<script>alert('添加失败,愿因:"+ex.ToString()+"');</script>");
- }
- }
- }
- //添加数据
- foreach (RepeaterItem ri in repeat.Items)
- {
- if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem)
- {
- CheckBox cb = ri.FindControl("cb") as CheckBox;
- if (cb.Checked == true)
- {
- userrolemodel.ur_roleid = int.Parse(cb.Text);
- userrolemodel.ur_userid = int.Parse(this.id.Text);
- userrole.Add(userrolemodel);
- Response.Write("<script>alert('添加成功!');</script>");
- }
- }
- }
- }
- }
- }
|