Beispiel #1
0
        private static StringBuilder BuildSqlClause(WfMatrixQueryParamCollection queryParams)
        {
            var matrixIdParam = queryParams.Find(p => p.QueryName == DB_FIELD_MATRIX_ID);

            string inSqlClause = string.Empty;

            foreach (var para in queryParams)
            {
                if (para == matrixIdParam)
                {
                    continue;  //|| string.IsNullOrEmpty(para.QueryValue) 空值也作为条件
                }
                inSqlClause = BuilderSubSqlClause(para, matrixIdParam.QueryValue, inSqlClause);
            }

            StringBuilder result = new StringBuilder(SELECT_SQL_CLAUSE);

            WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

            builder.AppendItem("R." + matrixIdParam.QueryName, matrixIdParam.QueryValue);
            builder.AppendTenantCode("R.TENANT_CODE");

            result.Append(builder.ToSqlString(TSqlBuilder.Instance));

            if (!string.IsNullOrEmpty(inSqlClause))
            {
                result.AppendFormat(" AND R.{0} IN ({1})", DB_FIELD_MATRIX_ROW_ID, inSqlClause);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 按照矩阵维度和维度值查询
        /// </summary>
        /// <param name="queryParams"></param>
        /// <returns></returns>
        public WfMatrix Query(WfMatrixQueryParamCollection queryParams)
        {
            var matrixIdParam = queryParams.Find(p => p.QueryName == DB_FIELD_MATRIX_ID);

            if (matrixIdParam == null)
            {
                throw new ArgumentException("参数至少包括要查询的矩阵ID");
            }

            var matrixCollection = Load(p => p.AppendItem(matrixIdParam.QueryName, matrixIdParam.QueryValue));

            if (matrixCollection.Count == 0)
            {
                return(null);
            }

            var result = matrixCollection.First();

            var selectClause = BuildSqlClause(queryParams);
            var ds           = DbHelper.RunSqlReturnDS(selectClause.ToString());

            result.Loaded = false;
            result.Rows.CopyFrom(ds.Tables[0].DefaultView);
            result.Loaded = true;

            return(result);
        }