Пример #1
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnAddRoleForUser_Click(object sender, EventArgs e)
 {
     LabMS.BLL.UserRole BUR = new LabMS.BLL.UserRole();
     LabMS.Model.UserRole MUR = new LabMS.Model.UserRole();
     int UserID = int.Parse(Request.QueryString["UserID"].ToString());
     CheckBox chk;
     bool success = false;
     for (int i = 0; i < gvRole.Rows.Count; i++)
     {
         chk = (CheckBox)gvRole.Rows[i].FindControl("chk");
         if (chk.Checked)
         {
             int RoleID =int.Parse(gvRole.DataKeys[i].Value.ToString());
             MUR.RoleID = RoleID;
             MUR.UserID = UserID;
             BUR.Add(MUR);
             success = true;
         }
     }
     if (success == true)
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('增加角色信息成功!');window.opener.location.href=window.opener.location.href;self.close();</script>");
     }
     else
     {
         Common.JShelper.JSAlert(this.Page, "", "增加角色信息失败!");
     }
 }
Пример #2
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public LabMS.Model.UserRole GetModel(int ID)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 ID,RoleID,UserID from UserRole ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            LabMS.Model.UserRole model=new LabMS.Model.UserRole();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["ID"].ToString()!="")
                {
                    model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if(ds.Tables[0].Rows[0]["RoleID"].ToString()!="")
                {
                    model.RoleID=int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
                }
                if(ds.Tables[0].Rows[0]["UserID"].ToString()!="")
                {
                    model.UserID=int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }