Beispiel #1
0
        protected void buttonOK_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                string permissions = Request["cb_permission"];

                if (permissions.IsNullOrWhiteSpace())
                    permissions = string.Empty;

                var role = new saRoleInfo();
                role.sName = txtRoleName.Text.Trim();
                role.iSort = int.Parse(txtSort.Text.Trim());
                role.sRemark = txtDes.Text.Trim();
                role.IsActive = !this.cbxIsActive.Checked;

                int iRoleId = 0;
                int.TryParse(Request["iRoleId"], out iRoleId);

                if (this.IsModifyAction)
                {
                    role.iIden = iRoleId;
                    saRole.Current.UpdateRole(role, permissions);

                    Response.Clear();

                    ClientScript.RegisterStartupScript(this.GetType(), string.Empty,
                       "<script type=\"text/javascript\">alert('{0}');location.href='RoleManage.aspx';</script>".FormatEx("修改成功!"));

                }
                else
                {
                    role.iIden = IdenGenerator.Current.NewIden(saRoleInfo.sTableName);

                    saRole.Current.CreateRole(role, permissions);

                    Response.Clear();

                    ClientScript.RegisterStartupScript(this.GetType(), string.Empty,
                          "<script type=\"text/javascript\">alert('{0}');location.href='RoleManage.aspx';</script>".FormatEx("添加成功!"));



                }
                txtId.Value = string.Empty;
            }
        }
Beispiel #2
0
 public void CreateRole(saRoleInfo role, string iMenuIds)
 {
     dal.Create(role, iMenuIds);
     CacheService.Current.RemoveObject(CacheKey.DicRole);
 }
Beispiel #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <param name="iMenuIds"></param>
        public void Update(saRoleInfo model, string iMenuIds)
        {
            string errMessage = string.Empty;
            if (!CheckUQ.CheckUqBeforeUpdate(saRoleInfo.sTableName, model, out errMessage))
                throw new Exception(errMessage);

            Database db = DatabaseFactory.CreateDatabase();
            using (DbConnection con = db.CreateConnection())
            {
                con.Open();
                DbTransaction trans = con.BeginTransaction();
                try
                {
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append(" update saRole set ");
                    strSql.Append(" sName=@sName,");
                    strSql.Append(" iSort=@iSort,");
                    strSql.Append(" sRemark=@sRemark,");
                    strSql.Append(" IsActive=@IsActive");
                    strSql.Append(" where iIden=@iIden ");
                    DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                    db.AddInParameter(dbCommand, "iIden", DbType.Int32, model.iIden);
                    db.AddInParameter(dbCommand, "sName", DbType.String, model.sName);
                    db.AddInParameter(dbCommand, "iSort", DbType.Int32, model.iSort);
                    db.AddInParameter(dbCommand, "IsActive", DbType.Boolean, model.IsActive);
                    db.AddInParameter(dbCommand, "sRemark", DbType.String, model.sRemark);
                    db.ExecuteNonQuery(dbCommand, trans);
                    //删除角色的权限
                    string sql = "delete saRoleMenu where iRoleId=@iRoleId";
                    var cmd = db.GetSqlStringCommand(sql);
                    db.AddInParameter(cmd, "iRoleId", DbType.Int32, model.iIden);
                    db.ExecuteNonQuery(cmd, trans);
                    //保存角色的权限
                    if (!iMenuIds.IsNullOrWhiteSpace())
                    {
                        foreach (var iMenuId in iMenuIds.Split(','))
                        {
                            StringBuilder rmsql = new StringBuilder();
                            rmsql.Append(" insert into saRoleMenu(iIden,iRoleId,iMenuId)");
                            rmsql.Append(" values (@iIden,@iRoleId,@iMenuId)");
                            DbCommand rmcmd = db.GetSqlStringCommand(rmsql.ToString());
                            db.AddInParameter(rmcmd, "iIden", DbType.Int32, new IdenGenerator().NewIden(saRoleMenuInfo.sTableName));
                            db.AddInParameter(rmcmd, "iRoleId", DbType.Int32, model.iIden);

                            db.AddInParameter(rmcmd, "iMenuId", DbType.Int32, int.Parse(iMenuId));
                            db.ExecuteScalar(rmcmd, trans);
                        }
                    }
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
                finally
                {
                    con.Close();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataReader"></param>
        /// <returns></returns>
        public static saRoleInfo DataRowBind(DataRow dataReader)
        {
            myPortal.Model.saRoleInfo model = new myPortal.Model.saRoleInfo();
            object ojb;
            ojb = dataReader["iIden"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.iIden = (int)ojb;
            }

            model.sName = dataReader["sName"].ToString();
            ojb = dataReader["iSort"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.iSort = (int)ojb;
            }
 
            ojb = dataReader["IsActive"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsActive = (bool)ojb;
            }

            ojb = dataReader["bIsAdministrator"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.bIsAdministrator = (bool)ojb;
            }
            model.sRemark = dataReader["sRemark"].ToString();
            return model;
        }