Пример #1
0
        public void Save(UserRole objUserRole)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objUserRole.PkId == 0)
            {
                sql = " insert into tbl_user_role(RoleName, DataFilter, RoleStatus) " +
                      " values(@RoleName, @DataFilter, @RoleStatus); " +
                      " select LAST_INSERT_ID(); ";

                parameterList.Add(new MySqlParameter("@RoleName", objUserRole.RoleName));
                parameterList.Add(new MySqlParameter("@DataFilter", objUserRole.DataFilter));
                parameterList.Add(new MySqlParameter("@RoleStatus", objUserRole.RoleStatus));

                objUserRole.PkId = DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString().ToInt();
            }

            else
            {
                sql = " update tbl_user_role set RoleName=@RoleName, DataFilter=@DataFilter, RoleStatus=@RoleStatus where PkId=@PkId ";

                parameterList.Add(new MySqlParameter("@RoleName", objUserRole.RoleName));
                parameterList.Add(new MySqlParameter("@DataFilter", objUserRole.DataFilter));
                parameterList.Add(new MySqlParameter("@RoleStatus", objUserRole.RoleStatus));
                parameterList.Add(new MySqlParameter("@PkId", objUserRole.PkId));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }
Пример #2
0
        public void Save(UserRole objUserRole)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objUserRole.PkId == 0)
            {
                sql = " insert into tbl_user_role(PkId, RoleName, DataFilter, RoleStatus) " +
                      " values(TUR_PKID.NEXTVAL, :RoleName, :DataFilter, :RoleStatus) " +
                      " RETURNING PkId INTO :PkId ";

                parameterList.Add(new OracleParameter(":RoleName", objUserRole.RoleName));
                parameterList.Add(new OracleParameter(":DataFilter", objUserRole.DataFilter));
                parameterList.Add(new OracleParameter(":RoleStatus", objUserRole.RoleStatus));
                var p = new OracleParameter(":PkId", OracleDbType.Int32, 0, ParameterDirection.Output);
                parameterList.Add(p);

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());

                objUserRole.PkId = Convert.ToInt32(((OracleDecimal)p.Value).Value);
            }

            else
            {
                sql = " update tbl_user_role set RoleName=:RoleName, DataFilter=:DataFilter, RoleStatus=:RoleStatus where PkId=:PkId ";

                parameterList.Add(new OracleParameter(":RoleName", objUserRole.RoleName));
                parameterList.Add(new OracleParameter(":DataFilter", objUserRole.DataFilter));
                parameterList.Add(new OracleParameter(":RoleStatus", objUserRole.RoleStatus));
                parameterList.Add(new OracleParameter(":PkId", objUserRole.PkId));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }
Пример #3
0
        public bool CheckExists(UserRole objUserRole)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            sql = " select count(*) from tbl_user_role where RoleName=@RoleName ";

            parameterList.Add(new MySqlParameter("@RoleName", objUserRole.RoleName));

            return int.Parse(DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString()) > 0;
        }
Пример #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                IUserService service = ServiceFactory.GetService<IUserService>();

                UserRole entity = null;
                List<UserRolePermission> rolePermissionList = new List<UserRolePermission>();

                if (this.IsInsert)
                {
                    entity = new UserRole()
                    {
                        RoleName = this.txtRoleName.Text.Trim(),
                        DataFilter = this.ddlDataFilter.SelectedValue.ToByte(0),
                        RoleStatus = this.ddlRoleStatus.SelectedValue.ToByte(0)
                    };

                    if (service.CheckExists_Role(entity))
                    {
                        this.JscriptMsg("角色名称已存在", null, "Error");

                        return;
                    }
                }

                else
                {
                    entity = service.GetObject_Role(this.PkId);

                    if (entity != null)
                    {
                        entity.DataFilter = this.ddlDataFilter.SelectedValue.ToByte(0);
                        entity.RoleStatus = this.ddlRoleStatus.SelectedValue.ToByte(0);
                    }
                }

                service.Save_Role(entity);

                foreach (TreeNode tnOne in this.tvPermission.Nodes)
                {
                    if (tnOne.Checked)
                    {
                        rolePermissionList.Add(new UserRolePermission() { RoleId = entity.PkId, PermCode = tnOne.Value });
                    }

                    foreach (TreeNode tnTwo in tnOne.ChildNodes)
                    {
                        if (tnTwo.Checked)
                        {
                            rolePermissionList.Add(new UserRolePermission() { RoleId = entity.PkId, PermCode = tnTwo.Value });
                        }
                    }
                }

                service.Delete_RolePermission(entity.PkId);
                service.Save_RolePermission(rolePermissionList);

                if (this.IsInsert && (sender as Button).CommandName == "SubmitContinue")
                {
                    this.ReturnUrl = this.Request.Url.PathAndQuery;
                }

                this.JscriptMsg("数据保存成功", this.ReturnUrl, "Success");
            }

            UserConvert.ClearCache();
        }
Пример #5
0
        public bool CheckExists_Role(UserRole objUserRole)
        {
            var repository = ServiceFactory.GetService<IUserRoleRepository>();

            return repository.CheckExists(objUserRole);
        }
Пример #6
0
        public void Save_Role(UserRole objUserRole)
        {
            var repository = ServiceFactory.GetService<IUserRoleRepository>();

            repository.Save(objUserRole);
        }