コード例 #1
0
 protected override bool InternalExecute(ProcessExecutingContext context)
 {
     if (string.IsNullOrEmpty(NumberValue))
     {
         Result = true;
     }
     else
     {
         var entitySchemaManager = context.UserConnection.GetSchemaManager("EntitySchemaManager") as EntitySchemaManager;
         var entitySchema        = entitySchemaManager.GetInstanceByUId(EntitySchemaUId) as EntitySchema;
         var entitySchemaName    = entitySchema.Name;
         var columnName          = entitySchema.Columns.GetByUId(ColumnUId).Name;
         var numberSelect        = new Terrasoft.Core.DB.Select(context.UserConnection)
                                   .Column(Terrasoft.Core.DB.Func.Count(columnName)).As("NumberCount")
                                   .From(entitySchema.Name).Where(columnName).IsEqual(new QueryParameter(NumberValue)) as Terrasoft.Core.DB.Select;
         using (var dbExecutor = context.UserConnection.EnsureDBConnection()) {
             using (var reader = numberSelect.ExecuteReader(dbExecutor)) {
                 if (reader.Read() && UserConnection.DBTypeConverter.DBValueToInt(reader[0]) > 0)
                 {
                     Result = false;
                 }
                 else
                 {
                     Result = true;
                 }
             }
         }
     }
     return(true);
 }
コード例 #2
0
    private static System.Collections.ObjectModel.Collection <KeyValuePair <Guid, string> > GetParentProjects(Guid projectId, UserConnection userConnection)
    {
        Select projectSelect =
            new Terrasoft.Core.DB.Select(userConnection)
            .Column("Id").As("Id")
            .Column("Name").As("Name")
            .Column("ParentProjectId").As("ParentProjectId")
            .From("Project") as Select;
        HierarchicalSelectOptions options = new HierarchicalSelectOptions()
        {
            PrimaryColumnName = "Id",
            ParentColumnName  = "ParentProjectId",
            SelectType        = HierarchicalSelectType.Parents
        };
        QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

        startingCondition.LeftExpression = new QueryColumnExpression("Id");
        startingCondition.IsEqual(Column.Parameter(projectId, "ParentProjectId", Terrasoft.Common.ParameterDirection.Input));
        projectSelect.HierarchicalOptions = options;
        var list = new System.Collections.ObjectModel.Collection <KeyValuePair <Guid, string> >();

        using (var dbExecutor = userConnection.EnsureDBConnection()) {
            using (var reader = projectSelect.ExecuteReader(dbExecutor)) {
                while (reader.Read())
                {
                    Guid id = Guid.Empty;
                    if (Guid.TryParse(reader[0].ToString(), out id))
                    {
                        list.Add(new KeyValuePair <Guid, string>(id, reader[1].ToString()));
                    }
                }
            }
        }
        return(list);
    }
コード例 #3
0
    public static Dictionary <Guid, KeyValuePair <Guid, string> > GetChildProjects(Guid projectId, UserConnection userConnection)
    {
        Query projectSelect =
            new Terrasoft.Core.DB.Select(userConnection)
            .Column("Id").As("Id")
            .Column("Name").As("Name")
            .Column("ParentProjectId").As("ParentProjectId")
            .From("Project");

        projectSelect.Parameters.Add(new QueryParameter("StartingUnitId", null));
        projectSelect.Parameters.Add(new QueryParameter("MaxDepth", null));
        projectSelect.InitializeParameters();
        HierarchicalSelectOptions options = new HierarchicalSelectOptions()
        {
            PrimaryColumnName = "Id",
            ParentColumnName  = "ParentProjectId",
            SelectType        = HierarchicalSelectType.Children,
            MaxDepthParameter = projectSelect.Parameters.GetByName("MaxDepth")
        };

        QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

        startingCondition.LeftExpression = new QueryColumnExpression("Id");
        startingCondition.IsEqual(Column.Parameter(projectId, "ParentProjectId", Terrasoft.Common.ParameterDirection.Input));
        string sqlText    = userConnection.DBEngine.GetQuerySqlText(projectSelect as Select, options);
        var    parameters = new QueryParameterCollection();

        parameters.Add(new QueryParameter()
        {
            Name  = "ParentProjectId",
            Value = projectId
        });
        var list = new Dictionary <Guid, KeyValuePair <Guid, string> >();

        using (var dbExecutor = userConnection.EnsureDBConnection()) {
            using (var reader = dbExecutor.ExecuteReader(sqlText, parameters)) {
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        var parentId = Guid.Empty;
                        if (!reader.IsDBNull(2))
                        {
                            parentId = userConnection.DBTypeConverter.DBValueToGuid(reader[2]);
                        }
                        var id = userConnection.DBTypeConverter.DBValueToGuid(reader[0]);
                        list.Add(id, new KeyValuePair <Guid, string>(parentId, reader[1].ToString()));
                    }
                }
            }
        }
        return(list);
    }
コード例 #4
0
    private static System.Collections.ObjectModel.Collection <KeyValuePair <Guid, string> > GetParentProjects(Guid projectId, UserConnection userConnection)
    {
        Query projectSelect =
            new Terrasoft.Core.DB.Select(userConnection)
            .Column("Id").As("Id")
            .Column("Name").As("Name")
            .Column("ParentProjectId").As("ParentProjectId")
            .From("Project");

        projectSelect.Parameters.Add(new QueryParameter("StartingUnitId", null));
        projectSelect.Parameters.Add(new QueryParameter("MaxDepth", null));
        projectSelect.InitializeParameters();
        HierarchicalSelectOptions options = new HierarchicalSelectOptions()
        {
            PrimaryColumnName = "Id",
            ParentColumnName  = "ParentProjectId",
            SelectType        = HierarchicalSelectType.Parents,
            MaxDepthParameter = projectSelect.Parameters.GetByName("MaxDepth")
        };

        QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

        startingCondition.LeftExpression = new QueryColumnExpression("Id");
        startingCondition.IsEqual(Column.Parameter(projectId, "ParentProjectId", Terrasoft.Common.ParameterDirection.Input));
        string sqlText    = userConnection.DBEngine.GetQuerySqlText(projectSelect as Select, options);
        var    parameters = new QueryParameterCollection();

        parameters.Add(new QueryParameter()
        {
            Name  = "ParentProjectId",
            Value = projectId
        });
        var list = new System.Collections.ObjectModel.Collection <KeyValuePair <Guid, string> >();

        using (var dbExecutor = userConnection.EnsureDBConnection()) {
            using (var reader = dbExecutor.ExecuteReader(sqlText, parameters)) {
                while (reader.Read())
                {
                    Guid id = Guid.Empty;
                    if (Guid.TryParse(reader[0].ToString(), out id))
                    {
                        list.Add(new KeyValuePair <Guid, string>(id, reader[1].ToString()));
                    }
                }
            }
        }
        return(list);
    }
        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);
        }
コード例 #6
0
        /// <summary>
        /// ##### ## ########### ############## #### ###### ###### # ########## ############## #### ######## ###############
        /// (###########, #############, ############ ### #######) ### ############## ##### ####### ##########.
        /// </summary>
        /// <param name="parentRoleId">############# ############### ### ############## ####.</param>
        /// <returns>###### ############### #### ########### ############### #####, ####### ##########.</returns>
        public object[] GetChildAdminUnits(string parentRoleId)
        {
            Select adminUnitSelect =
                new Terrasoft.Core.DB.Select(UserConnection).Column("Id")
                .As("Id")
                .Column("Name")
                .As("Name")
                .Column("ParentRoleId")
                .As("ParentRoleId")
                .From("SysAdminUnit")
                .Where("SysAdminUnitTypeValue")
                .In(Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Organisation, "AdminUnitType_Organisation", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Department, "AdminUnitType_Department", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Manager, "AdminUnitType_Manager", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Team, "AdminUnitType_Team", Common.ParameterDirection.Input),
                    Column.Parameter(6, "AdminUnitType_FunctionalRole", Common.ParameterDirection.Input)) as Select;
            HierarchicalSelectOptions options = new HierarchicalSelectOptions()
            {
                PrimaryColumnName = "Id",
                ParentColumnName  = "ParentRoleId",
                SelectType        = HierarchicalSelectType.Children
            };
            QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

            startingCondition.LeftExpression = new QueryColumnExpression("ParentRoleId");
            startingCondition.IsEqual(Column.Parameter(new Guid(parentRoleId), "FolderId", Common.ParameterDirection.Input));
            adminUnitSelect.HierarchicalOptions = options;
            var list = new List <object>();

            list.Add(new Guid(parentRoleId));
            using (DBExecutor dbExecutor = UserConnection.EnsureDBConnection())
            {
                using (IDataReader reader = adminUnitSelect.ExecuteReader(dbExecutor))
                {
                    while (reader.Read())
                    {
                        Guid id = reader.GetColumnValue <Guid>("Id");
                        list.Add(id);
                    }
                }
            }
            return(list.ToArray());
        }
コード例 #7
0
    public static Dictionary <Guid, KeyValuePair <Guid, string> > GetChildProjects(Guid projectId, UserConnection userConnection)
    {
        Select projectSelect =
            new Terrasoft.Core.DB.Select(userConnection)
            .Column("Id").As("Id")
            .Column("Name").As("Name")
            .Column("ParentProjectId").As("ParentProjectId")
            .From("Project") as Select;
        HierarchicalSelectOptions options = new HierarchicalSelectOptions()
        {
            PrimaryColumnName = "Id",
            ParentColumnName  = "ParentProjectId",
            SelectType        = HierarchicalSelectType.Children
        };
        QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

        startingCondition.LeftExpression = new QueryColumnExpression("Id");
        startingCondition.IsEqual(Column.Parameter(projectId, "ParentProjectId", Terrasoft.Common.ParameterDirection.Input));
        projectSelect.HierarchicalOptions = options;
        var list = new Dictionary <Guid, KeyValuePair <Guid, string> >();

        using (var dbExecutor = userConnection.EnsureDBConnection()) {
            using (var reader = projectSelect.ExecuteReader(dbExecutor)) {
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        var parentId = Guid.Empty;
                        if (!reader.IsDBNull(2))
                        {
                            parentId = userConnection.DBTypeConverter.DBValueToGuid(reader[2]);
                        }
                        var id = userConnection.DBTypeConverter.DBValueToGuid(reader[0]);
                        list.Add(id, new KeyValuePair <Guid, string>(parentId, reader[1].ToString()));
                    }
                }
            }
        }
        return(list);
    }
        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);
        }
コード例 #9
0
        /// <summary>
        /// ##### ## ########### ############## #### ###### ###### # ########## ############## #### ######## ###############
        /// (###########, #############, ############ ### #######) ### ############## ##### ####### ##########.
        /// </summary>
        /// <param name="parentRoleId">############# ############### ### ############## ####.</param>
        /// <returns>###### ############### #### ########### ############### #####, ####### ##########.</returns>
        public object[] GetChildAdminUnits(string parentRoleId)
        {
            Query adminUnitSelect =
                new Terrasoft.Core.DB.Select(UserConnection).Column("Id")
                .As("Id")
                .Column("Name")
                .As("Name")
                .Column("ParentRoleId")
                .As("ParentRoleId")
                .From("SysAdminUnit")
                .Where("SysAdminUnitTypeValue")
                .In(Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Organisation, "AdminUnitType_Organisation", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Department, "AdminUnitType_Department", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Manager, "AdminUnitType_Manager", Common.ParameterDirection.Input),
                    Column.Parameter(Terrasoft.Core.DB.SysAdminUnitType.Team, "AdminUnitType_Team", Common.ParameterDirection.Input),
                    Column.Parameter(6, "AdminUnitType_FunctionalRole", Common.ParameterDirection.Input));

            adminUnitSelect.Parameters.Add(new QueryParameter("StartingUnitId", null));
            adminUnitSelect.Parameters.Add(new QueryParameter("MaxDepth", null));
            adminUnitSelect.InitializeParameters();
            HierarchicalSelectOptions options = new HierarchicalSelectOptions()
            {
                PrimaryColumnName = "Id",
                ParentColumnName  = "ParentRoleId",
                SelectType        = HierarchicalSelectType.Children,
                MaxDepthParameter = adminUnitSelect.Parameters.GetByName("MaxDepth")
            };
            QueryCondition startingCondition = options.StartingPrimaryColumnCondition;

            startingCondition.LeftExpression = new QueryColumnExpression("ParentRoleId");
            startingCondition.IsEqual(Column.Parameter(parentRoleId, "FolderId", Common.ParameterDirection.Input));
            string sqlText    = UserConnection.DBEngine.GetQuerySqlText(adminUnitSelect as Select, options);
            var    parameters = new QueryParameterCollection();

            parameters.Add(new QueryParameter()
            {
                Name          = "AdminUnitType_Organisation",
                Value         = Terrasoft.Core.DB.SysAdminUnitType.Organisation,
                ValueTypeName = "Integer"
            });
            parameters.Add(new QueryParameter()
            {
                Name          = "AdminUnitType_Department",
                Value         = Terrasoft.Core.DB.SysAdminUnitType.Department,
                ValueTypeName = "Integer"
            });
            parameters.Add(new QueryParameter()
            {
                Name          = "AdminUnitType_Manager",
                Value         = Terrasoft.Core.DB.SysAdminUnitType.Manager,
                ValueTypeName = "Integer"
            });
            parameters.Add(new QueryParameter()
            {
                Name          = "AdminUnitType_Team",
                Value         = Terrasoft.Core.DB.SysAdminUnitType.Team,
                ValueTypeName = "Integer"
            });
            parameters.Add(new QueryParameter()
            {
                Name          = "AdminUnitType_FunctionalRole",
                Value         = 6,
                ValueTypeName = "Integer"
            });
            parameters.Add(new QueryParameter()
            {
                Name          = "FolderId",
                Value         = parentRoleId,
                ValueTypeName = "Guid"
            });
            var list = new List <object>();

            list.Add(new Guid(parentRoleId));
            using (DBExecutor dbExecutor = UserConnection.EnsureDBConnection())
            {
                using (IDataReader reader = dbExecutor.ExecuteReader(sqlText, parameters))
                {
                    while (reader.Read())
                    {
                        Guid id = reader.GetColumnValue <Guid>("Id");
                        list.Add(id);
                    }
                }
            }
            return(list.ToArray());
        }