public SchemaObjectCollection LoadAUScope(string auID, string[] scopes, bool normalOnly, DateTime timePoint)
		{
			auID.NullCheck("auID");
			scopes.NullCheck("scopes");

			if (scopes.Length > 0)
			{
				WhereSqlClauseBuilder where = new WhereSqlClauseBuilder().NormalFor("O.Status").NormalFor("S.Status");
				where.AppendCondition("R.ContainerID", auID);
				where.NormalFor("R.Status");

				InSqlClauseBuilder inSql = new InSqlClauseBuilder("S.ScopeSchemaType");
				inSql.AppendItem(scopes);

				if (normalOnly)
				{
					where.NormalFor("O.Status");
				}

				return LoadAUScope(new ConnectiveSqlClauseCollection(where, inSql), timePoint);
			}
			else
			{
				return new SchemaObjectCollection();
			}
		}
		public SchemaObjectCollection LoadAUScope(string auID, bool normalOnly, DateTime timePoint)
		{
			auID.NullCheck("auID");

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder().NormalFor("O.Status").NormalFor("S.Status");
			where.AppendCondition("R.ContainerID", auID);
			where.NormalFor("R.Status");

			if (normalOnly)
			{
				where.NormalFor("O.Status");
			}

			return LoadAUScope(where, timePoint);
		}
		/// <summary>
		/// 载入指定AUSchemaID中的角色
		/// </summary>
		/// <param name="schemaID">AUSchema的ID</param>
		/// <param name="normalOnly">如果为true,则仅提取正常的,否则包含已删除的</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public AUSchemaRoleCollection LoadAUSchemaRoles(string schemaID, bool normalOnly, DateTime timePoint)
		{
			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendCondition("R.ContainerID", schemaID);
			if (normalOnly) where.NormalFor("O.Status").NormalFor("R.Status");
			return LoadAUSchemaRoles(where, normalOnly, timePoint);
		}
Beispiel #4
0
        public SchemaObjectCollection LoadScopeItems(string[] ids, string scopeType, bool normalOnly, DateTime timePoint)
        {
            ids.NullCheck("ids");

            string sql = "SELECT * FROM SC.SchemaObject WHERE ";

            if (ids.Length > 0)
            {
                InSqlClauseBuilder inSql = new InSqlClauseBuilder("ID").AppendItem(ids);;
                WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
                if (normalOnly)
                {
                    where.NormalFor("Status");
                }

                where.AppendItem("SchemaType", scopeType);
                var timeBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);
                sql += new ConnectiveSqlClauseCollection(inSql, timeBuilder, where).ToSqlString(TSqlBuilder.Instance);

                return(LoadSchemaObjects(sql));
            }
            else
            {
                return(new SchemaObjectCollection());
            }
        }
Beispiel #5
0
        /// <summary>
        /// 根据下级名称,载入指定的管理单元
        /// </summary>
        /// <param name="name">下级名称</param>
        /// <param name="parentID">父级ID</param>
        /// <param name="childSchemaType">子级Schema类型</param>
        /// <param name="normalOnly">是否仅包含正常对象</param>
        /// <param name="timePoint">时间点</param>
        /// <returns></returns>
        public SchemaObjectCollection LoadAUByChildName(string name, string parentID, string childSchemaType, bool normalOnly, DateTime timePoint)
        {
            string sql = @"SELECT O.* FROM SC.SchemaObject O 
INNER JOIN SC.AdminUnitSnapshot S ON O.ID = S.ID AND O.VersionStartTime = S.VersionStartTime AND O.SchemaType = S.SchemaType 
INNER JOIN SC.SchemaRelationObjects R ON O.ID = R.ObjectID AND O.SchemaType = R.ChildSchemaType
WHERE 1=1 AND ";

            var timeCondition1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "S.");
            var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "O.");
            var timeCondition3 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "R.");

            WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
            where.AppendItem("R.ParentID", parentID);
            where.AppendItem("S.Name", name);
            where.AppendItem("R.ChildSchemaType", childSchemaType);

            if (normalOnly)
            {
                where.NormalFor("R.Status").NormalFor("O.Status");
            }

            sql += new ConnectiveSqlClauseCollection(timeCondition1, timeCondition2, timeCondition3, where).ToSqlString(TSqlBuilder.Instance);

            return(LoadSchemaObjects(sql));
        }
Beispiel #6
0
        private void BuildCondition(QueryCondition qc)
        {
            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            if (this.deepOption == 1)
            {
                builder.AppendCondition("C.ContainerID", this.scope.ID);
            }
            else
            {
                if (deepOption == 2)
                {
                    builder.AppendItem("C.ContainerID", this.scope.ID, "<>");
                }
            }
            builder.NormalFor("C.Status").NormalFor("S.Status").NormalFor("SM.Status").NormalFor("AUS.Status");
            var timeBulder1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("C.");
            var timeBulder2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("S.");
            var time3       = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("AUS.");
            var time4       = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("SM.");

            var conditionClause = new ConnectiveSqlClauseCollection(builder, timeBulder1, timeBulder2, time3, time4).ToSqlString(TSqlBuilder.Instance);

            if (string.IsNullOrEmpty(qc.WhereClause) == false)
            {
                qc.WhereClause += " AND (" + conditionClause + ")";
            }
            else
            {
                qc.WhereClause = conditionClause;
            }
        }
		/// <summary>
		/// 载入指定SchemaID的管理单元
		/// </summary>
		/// <param name="auSchemaID"></param>
		/// <param name="normalOnly">为true时表示所有</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public SchemaObjectCollection LoadAUBySchemaID(string auSchemaID, bool normalOnly, DateTime timePoint)
		{
			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendItem("S.AUSchemaID", auSchemaID);
			if (normalOnly)
				where.NormalFor("O.Status");

			return LoadAU(where, timePoint);
		}
		/// <summary>
		/// 根据角色ID载入指定AUSchemaID中的角色
		/// </summary>
		/// <param name="schemaID">AUSchema的ID</param>
		/// <param name="normalOnly">如果为true,则仅提取正常的,否则包含已删除的</param>
		/// <param name="schemaRoleIDs">仅包含角色的ID</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public AUSchemaRoleCollection LoadAUSchemaRoles(string schemaID, string[] schemaRoleIDs, bool normalOnly, DateTime timePoint)
		{
			schemaRoleIDs.NullCheck("schemaRoleIDs");

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendCondition("R.ContainerID", schemaID);
			if (normalOnly) where.NormalFor("O.Status").NormalFor("R.Status");

			InSqlClauseBuilder inSql = new InSqlClauseBuilder("R.MemberID").AppendItem(schemaRoleIDs);
			return LoadAUSchemaRoles(new ConnectiveSqlClauseCollection(where, inSql), normalOnly, timePoint);
		}
		public AUSchemaRole LoadAUSchemaRoleByCodeName(string schemaID, string codeName, bool normalOnly, DateTime timePoint)
		{
			codeName.NullCheck("codeName");
			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendCondition("R.ContainerID", schemaID);
			if (normalOnly) where.NormalFor("O.Status").NormalFor("R.Status");

			where.AppendCondition("S.CodeName", codeName);

			return LoadAUSchemaRoles(where, normalOnly, timePoint).FirstOrDefault();
		}
		public AURole LoadAURole(string schemaRoleID, string unitID, bool normalOnly, DateTime timePoint)
		{
			string sql = @"SELECT O.* FROM SC.SchemaObject O INNER JOIN SC.AURoleSnapshot S
ON O.ID = S.ID AND O.VersionStartTime = S.VersionStartTime AND O.SchemaType = S.SchemaType
INNER JOIN SC.SchemaMembers R ON O.ID = R.MemberID AND O.SchemaType = R.MemberSchemaType
 WHERE";
			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendCondition("S.SchemaRoleID", schemaRoleID);
			where.AppendCondition("R.ContainerID", unitID);
			where.NormalFor("R.Status");

			if (normalOnly) where.NormalFor("O.Status");

			var timeCondition1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "S.");
			var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "O.");

			sql += new ConnectiveSqlClauseCollection(timeCondition1, timeCondition2, where).ToSqlString(TSqlBuilder.Instance);

			return (AURole)LoadSchemaObjects(sql).FirstOrDefault();
		}
		/// <summary>
		/// 载入所有下级管理单元
		/// </summary>
		/// <param name="schemaID">管理单元的AUSchemaID</param>
		/// <param name="parentID">上级管理单元,如果为null则取schemaID</param>
		/// <param name="normalOnly">是否仅含正常数据</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public SchemaObjectCollection LoadSubUnits(string schemaID, string parentID, bool normalOnly, DateTime timePoint)
		{
			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			if (parentID == null)
				parentID = schemaID;
			where.AppendItem("R.ParentID", parentID);
			where.AppendCondition("S.AUSchemaID", schemaID);
			where.AppendItem("R.ChildSchemaType", AUCommon.SchemaAdminUnit);

			if (normalOnly)
				where.NormalFor("R.Status").NormalFor("O.Status");

			return LoadSubUnits(timePoint, where);
		}
		public SchemaObjectCollection LoadScopeItems(string scopeType, bool normalOnly, DateTime timePoint)
		{
			string sql = "SELECT * FROM SC.SchemaObject WHERE ";

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			if (normalOnly)
				where.NormalFor("Status");

			where.AppendItem("SchemaType", scopeType);
			var timeBuilder = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);
			sql += new ConnectiveSqlClauseCollection(timeBuilder, where).ToSqlString(TSqlBuilder.Instance);

			return LoadSchemaObjects(sql);
		}
		/// <summary>
		/// 根据下级名称,载入指定的管理单元
		/// </summary>
		/// <param name="conditions">条件集,O对象表,M关系表,S对象的快照表</param>
		/// <param name="snapshotTable">快照表的名称</param>
		/// <param name="normalOnly">是否仅包含正常对象</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		private SchemaObjectCollection LoadContainers(IConnectiveSqlClause conditions, bool normalOnly, DateTime timePoint)
		{
			string sql = @"SELECT O.* FROM SC.SchemaObject O 
INNER JOIN SC.SchemaMembers M ON O.ID = M.ContainerID AND O.SchemaType = M.ContainerSchemaType
WHERE 1=1 AND ";

			var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "O.");
			var timeCondition3 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "M.");

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			if (normalOnly)
				where.NormalFor("M.Status").NormalFor("O.Status");

			sql += new ConnectiveSqlClauseCollection(timeCondition2, timeCondition3, where, conditions).ToSqlString(TSqlBuilder.Instance);

			return LoadSchemaObjects(sql);
		}
		/// <summary>
		/// 载入指定SchemaID的管理单元
		/// </summary>
		/// <param name="auSchemaID">管理架构的ID</param>
		/// <param name="unitIDs">管理单元ID的集合,或为null,表示所有架构。空数组表示所有</param>
		/// <param name="normalOnly">为true时表示所有</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public SchemaObjectCollection LoadAUBySchemaID(string auSchemaID, string[] unitIDs, bool normalOnly, DateTime timePoint)
		{
			auSchemaID.NullCheck("auSchemaID");

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
			where.AppendItem("S.AUSchemaID", auSchemaID);
			if (normalOnly)
				where.NormalFor("O.Status");

			InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("S.ID");
			if (unitIDs != null)
			{
				return LoadAU(new ConnectiveSqlClauseCollection(where, new InSqlClauseBuilder("S.ID").AppendItem(unitIDs)), timePoint);
			}
			else
			{
				return LoadAU(where, DateTime.MinValue);
			}
		}
		/// <summary>
		/// 根据Schema和代码名称,载入管理架构角色
		/// </summary>
		/// <param name="schemaID"></param>
		/// <param name="codeNames"></param>
		/// <param name="normalOnly"></param>
		/// <param name="timePoint"></param>
		/// <returns></returns>
		public AUSchemaRoleCollection LoadAUSchemaRolesByCodeNames(string schemaID, string[] codeNames, bool normalOnly, DateTime timePoint)
		{
			codeNames.NullCheck("codeNames");
			if (codeNames.Length > 0)
			{
				WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
				where.AppendCondition("R.ContainerID", schemaID);
				if (normalOnly) where.NormalFor("O.Status").NormalFor("R.Status");

				InSqlClauseBuilder inSql = new InSqlClauseBuilder("S.CodeName");
				inSql.AppendItem(codeNames);

				return LoadAUSchemaRoles(new ConnectiveSqlClauseCollection(where, inSql), normalOnly, timePoint);
			}
			else
			{
				return new AUSchemaRoleCollection();
			}
		}
		/// <summary>
		/// 载入所有下级管理单元
		/// </summary>
		/// <param name="schemaID">管理单元的AUSchemaID</param>
		/// <param name="parentID">上级管理单元的ID</param>
		/// <param name="normalOnly">是否仅含正常数据</param>
		/// <param name="timePoint">时间点</param>
		/// <returns></returns>
		public SchemaObjectCollection LoadSubUnits(string schemaID, string[] parentIDs, bool normalOnly, DateTime timePoint)
		{
			parentIDs.NullCheck("parentIDs");

			if (parentIDs.Length > 0)
			{
				WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
				where.AppendCondition("S.AUSchemaID", schemaID);
				where.AppendItem("R.ChildSchemaType", AUCommon.SchemaAdminUnit);

				if (normalOnly)
					where.NormalFor("R.Status").NormalFor("O.Status");

				InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("R.ParentID");

				return LoadSubUnits(timePoint, new ConnectiveSqlClauseCollection(where, inBuilder));
			}
			else
				return new SchemaObjectCollection();
		}
		private SchemaObjectCollection LoadAURolesInner(string[] unitIds, string[] schemaRoleIDs, bool normalOnly, DateTime timePoint)
		{
			string sql = @"SELECT O.* FROM SC.SchemaObject O INNER JOIN SC.AURoleSnapshot S
ON O.ID = S.ID AND O.VersionStartTime = S.VersionStartTime AND O.SchemaType = S.SchemaType
INNER JOIN SC.SchemaMembers R ON O.ID = R.MemberID AND O.SchemaType = R.MemberSchemaType
 WHERE";
			IConnectiveSqlClause inBuilder = DbBuilderHelper.In("S.SchemaRoleID", schemaRoleIDs);

			IConnectiveSqlClause inBuilder2 = DbBuilderHelper.In("R.ContainerID", unitIds);

			WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();

			if (normalOnly) where.NormalFor("O.Status").NormalFor("R.Status");

			var timeCondition1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "S.");
			var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "O.");

			sql += new ConnectiveSqlClauseCollection(timeCondition1, timeCondition2, where, inBuilder, inBuilder2).ToSqlString(TSqlBuilder.Instance);

			return LoadSchemaObjects(sql);
		}
Beispiel #18
0
        public List <AURoleDisplayItem> LoadAURoleDisplayItems(string unitID, bool normalOnly, DateTime timePoint)
        {
            string sql = @"SELECT SR.Name, SR.CodeName, SR.DisplayName, S.ID, S.SchemaRoleID, S.Status FROM SC.AURoleSnapshot S
INNER JOIN SC.SchemaMembers R ON S.ID = R.MemberID AND S.SchemaType = R.MemberSchemaType
INNER JOIN SC.AUSchemaRoleSnapshot SR ON SR.ID = S.SchemaRoleID
 WHERE";

            WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
            where.AppendCondition("R.ContainerID", unitID).AppendCondition("R.ContainerSchemaType", AUCommon.SchemaAdminUnit);
            if (normalOnly)
            {
                where.NormalFor("R.Status").NormalFor("S.Status").NormalFor("SR.Status");
            }

            var timeCondition1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "S.");
            var timeCondition2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "SR.");
            var timeCondition3 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint, "R.");

            sql += new ConnectiveSqlClauseCollection(timeCondition1, timeCondition2, timeCondition3, where).ToSqlString(TSqlBuilder.Instance);

            List <AURoleDisplayItem> result = new List <AURoleDisplayItem>();

            AUCommon.DoDbAction(() =>
            {
                using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
                {
                    using (IDataReader dr = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName()))
                    {
                        while (dr.Read())
                        {
                            AURoleDisplayItem item = new AURoleDisplayItem();
                            ORMapping.DataReaderToObject <AURoleDisplayItem>(dr, item);
                            result.Add(item);
                        }
                    }
                }
            });

            return(result);
        }
Beispiel #19
0
        public AUSchemaCategoryCollection LoadSubCategories(string superID, bool normalOnly, DateTime timePoint)
        {
            var conditions = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder(timePoint);

            WhereSqlClauseBuilder where = new WhereSqlClauseBuilder();
            if (string.IsNullOrEmpty(superID) == false)
            {
                where.AppendItem("ParentID", superID);
            }
            else
            {
                where.AppendItem("ParentID", (string)null, "IS");
            }

            if (normalOnly)
            {
                where.NormalFor("Status");
            }

            conditions.Add(where);
            AUSchemaCategoryCollection result = new AUSchemaCategoryCollection();

            AUCommon.DoDbAction(() =>
            {
                using (DbContext context = DbContext.GetContext(this.GetConnectionName()))
                {
                    VersionedObjectAdapterHelper.Instance.FillData(ORMapping.GetMappingInfo(typeof(AUSchemaCategory)).TableName, conditions, this.GetConnectionName(),
                                                                   reader =>
                    {
                        ORMapping.DataReaderToCollection(result, reader);
                    });
                }
            });

            return(result);
        }
		private void BuildCondition(QueryCondition qc)
		{
			WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();
			if (this.deepOption == 1)
			{
				builder.AppendCondition("C.ContainerID", this.scope.ID);
			}
			else
			{
				if (deepOption == 2)
				{
					builder.AppendItem("C.ContainerID", this.scope.ID, "<>");
				}
			}
			builder.NormalFor("C.Status").NormalFor("S.Status").NormalFor("SM.Status").NormalFor("AUS.Status");
			var timeBulder1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("C.");
			var timeBulder2 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("S.");
			var time3 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("AUS.");
			var time4 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("SM.");

			var conditionClause = new ConnectiveSqlClauseCollection(builder, timeBulder1, timeBulder2, time3, time4).ToSqlString(TSqlBuilder.Instance);

			if (string.IsNullOrEmpty(qc.WhereClause) == false)
				qc.WhereClause += " AND (" + conditionClause + ")";
			else
				qc.WhereClause = conditionClause;
		}