public override Select CreateSelect() { var entitySchemaManager = Page.UserConnection.EntitySchemaManager; //Код, который компилируется только в Workspace CR173384 var select = new Terrasoft.Core.DB.Select(Page.UserConnection) .Column("SysEntitySchemaRecordDefRight", "Id") .Column("SysEntitySchemaRecordDefRight", "SubjectSchemaUId").As("SubjectSchemaId") .Column("VwSysSchemaInfo", "Caption").As("SubjectSchemaCaption") .Column("SysEntitySchemaRecordDefRight", "AuthorSysAdminUnitId").As("AuthorId") .Column("Author", "Name").As("AuthorName") .Column("SysEntitySchemaRecordDefRight", "GranteeSysAdminUnitId").As("GranteeId") .Column("Grantee", "Name").As("GranteeName") .Column("SysEntitySchemaRecordDefRight", "Position") .Column("EntitySchemaRecRightOperation", "Id").As("OperationId") .Column("EntitySchemaRecRightOperation", "Name").As("OperationName") .Column("RightLevel", "Id").As("RightLevelId") .Column("RightLevel", "Name").As("RightLevelName") .From("SysEntitySchemaRecordDefRight") .InnerJoin("SysAdminUnit").As("Author").On("Author", "Id").IsEqual("SysEntitySchemaRecordDefRight", "AuthorSysAdminUnitId") .InnerJoin("SysAdminUnit").As("Grantee").On("Grantee", "Id").IsEqual("SysEntitySchemaRecordDefRight", "GranteeSysAdminUnitId") .InnerJoin("VwSysSchemaInfo").On("VwSysSchemaInfo", "UId").IsEqual("SysEntitySchemaRecordDefRight", "SubjectSchemaUId") .InnerJoin("SysEntitySchemaRecOprRightLvl").As("RightLevel").On("RightLevel", "Value").IsEqual("SysEntitySchemaRecordDefRight", "RightLevel") .InnerJoin("EntitySchemaRecRightOperation").On("EntitySchemaRecRightOperation", "Value").IsEqual("SysEntitySchemaRecordDefRight", "Operation") .OrderByAsc("SysEntitySchemaRecordDefRight", "SubjectSchemaUId") .OrderByAsc("SysEntitySchemaRecordDefRight", "Position") as Terrasoft.Core.DB.Select; string viewCode = GetViewCode(); select.Where("VwSysSchemaInfo", "SysWorkspaceId").IsEqual(Column.Parameter(UserConnection.Workspace.Id)) .And("SysEntitySchemaRecordDefRight", "Operation").IsEqual(new QueryParameter(viewCode)); if (Code.ToString() == "All") { var filterValuesObj = Page.UserConnection.DBSecurityEngine.GetUserAdminUnitCollection(SelectedNodePrimaryColumnValue); select.And("SysEntitySchemaRecordDefRight", "AuthorSysAdminUnitId") .In(Terrasoft.Core.DB.Column.Parameters(filterValuesObj)); } else { select.And("SysEntitySchemaRecordDefRight", "AuthorSysAdminUnitId").IsEqual(Column.Parameter(SelectedNodePrimaryColumnValue)); } return(select); }
public override void FillData(DataSourceRequest dataSourceRequest) { Page.TreeGrid.Clear(); var dataSource = GetDataSource(); dataSource.Clear(); var entitySchemaManager = Page.UserConnection.EntitySchemaManager; var rightsSchema = entitySchemaManager.GetInstanceByName("VwSysEntitySchemaColumnRight"); Terrasoft.Core.DB.Select select = new Terrasoft.Core.DB.Select(Page.UserConnection) .Column(rightsSchema.Name, "Id") .Column(rightsSchema.Name, "SubjectSchemaUId") .Column(rightsSchema.Name, "SubjectColumnUId") .Column("RightLevel", "Name").As("RightLevelName") .Column("RightLevel", "Id").As("RightLevelId") .From(rightsSchema.Name) .InnerJoin("SysEntitySchemaColRightLevel").As("RightLevel") .On("RightLevel", "Id").IsEqual(rightsSchema.Name, "RightLevelId") as Select; string code = GetViewCode(); if (code == "All" && SelectedNodePrimaryColumnValue != Guid.Empty) { var filterValuesObj = Page.UserConnection.DBSecurityEngine.GetUserAdminUnitCollection(SelectedNodePrimaryColumnValue); select.And("SysAdminUnitId") .In(Terrasoft.Core.DB.Column.Parameters(filterValuesObj)); } else { select.And("SysAdminUnitId").IsEqual(Column.Parameter(SelectedNodePrimaryColumnValue)); } select.OrderByAsc(rightsSchema.Name, "SubjectSchemaUId"); select.OrderByAsc(rightsSchema.Name, "SubjectColumnUId"); select.OrderByAsc(rightsSchema.Name, "Position"); string schemaName = String.Empty; string columnName = String.Empty; Guid schemaId = Guid.Empty; Guid columnId = Guid.Empty; Guid curSchemaId = Guid.Empty; Guid curColumnId = Guid.Empty; Guid sParentId = Guid.Empty; Guid cParentId = Guid.Empty; Entity row; int ordinal; string rightLevelName = String.Empty; EntitySchema entitySchema = null; EntitySchemaColumn entityColumn; using (var dbExecutor = UserConnection.EnsureDBConnection()) { using (var reader = select.ExecuteReader(dbExecutor)) { while (reader.Read()) { ordinal = reader.GetOrdinal("SubjectSchemaUId"); if (!reader.IsDBNull(ordinal)) { schemaId = UserConnection.DBTypeConverter.DBValueToGuid(reader[ordinal]); entitySchema = entitySchemaManager.FindInstanceByUId(schemaId); if (entitySchema == null) { continue; } schemaName = entitySchema.Caption.Value; } ordinal = reader.GetOrdinal("SubjectColumnUId"); if (!reader.IsDBNull(ordinal)) { columnId = UserConnection.DBTypeConverter.DBValueToGuid(reader[ordinal]); entityColumn = entitySchema.Columns.FindByUId(columnId); if (entityColumn == null) { continue; } columnName = entityColumn.Caption.Value; entityColumn = null; } if (!schemaId.Equals(curSchemaId)) { row = dataSource.CreateRow(); sParentId = Guid.NewGuid(); row.SetColumnValue("Id", sParentId); row.SetColumnValue("Name", schemaName); row.SetColumnValue("ParentId", null); row.SetColumnValue("Type", "EntitySchema"); dataSource.Add(row); curSchemaId = schemaId; } if (!columnId.Equals(curColumnId)) { row = dataSource.CreateRow(); cParentId = Guid.NewGuid(); row.SetColumnValue("Id", cParentId); row.SetColumnValue("Name", columnName); row.SetColumnValue("ParentId", sParentId); row.SetColumnValue("Type", "EntitySchemaColumn"); var rightLevelId = reader["RightLevelId"]; if (rightLevelId != null && new Guid(rightLevelId.ToString()) != Guid.Empty) { row.SetColumnValue("RightLevel", new Guid(rightLevelId.ToString())); } dataSource.Add(row); curColumnId = columnId; } } } } dataSource.LoadRows(dataSourceRequest); }