Example #1
0
        /// <summary>
        /// separate osql to multi paths
        /// </summary>
        /// <param name="fullItems"></param>
        /// <param name="dsDomain"></param>
        /// <returns></returns>
        protected List <List <InternalBookmarkItem> > GetPaths(ref GenOsqlParamInfo paramInfo,
                                                               List <InternalBookmarkItem> fullItems, DSDomain dsDomain)
        {
            List <List <InternalBookmarkItem> > paths = new List <List <InternalBookmarkItem> >();

            #region calculate used table indexes
            Dictionary <int, List <InternalBookmarkItem> > usedTableIndexes = new Dictionary <int, List <InternalBookmarkItem> >();
            List <int> sortedTableIndexes = new List <int>();
            foreach (InternalBookmarkItem ibmItem in fullItems)
            {
                if (!usedTableIndexes.ContainsKey(ibmItem.TableIndex))
                {
                    usedTableIndexes.Add(ibmItem.TableIndex, new List <InternalBookmarkItem>());
                    sortedTableIndexes.Add(ibmItem.TableIndex);
                }

                usedTableIndexes[ibmItem.TableIndex].Add(ibmItem);
            }
            if (!usedTableIndexes.ContainsKey(0))
            {
                usedTableIndexes.Add(0, new List <InternalBookmarkItem>());
                sortedTableIndexes.Add(0);
            }
            sortedTableIndexes = sortedTableIndexes.OrderBy(c => c).ToList();
            #endregion

            #region get paths
            string whereClauseName                    = "WhereClause";
            Dictionary <int, bool> checker            = new Dictionary <int, bool>();
            List <DSRelationRow>   dsRelationRows     = dsDomain.TableRelations.Rows.Items;
            DSRelationRow          dsWhereRelationRow = dsRelationRows.FirstOrDefault(
                c => whereClauseName.Equals(c.Name, StringComparison.OrdinalIgnoreCase));
            string whereRelations = BitHelper.ToBinaryFormat(dsWhereRelationRow.Data, true);
            whereRelations = BaseMarkupUtilities.ReverseString(whereRelations);
            foreach (DSRelationRow dsRelationRow in dsRelationRows)
            {
                if (whereClauseName.Equals(dsRelationRow.Name, StringComparison.OrdinalIgnoreCase))
                {
                    paramInfo.DSWhereClauseRelationRow = dsRelationRow;
                    continue;
                }

                List <InternalBookmarkItem> path = new List <InternalBookmarkItem>();
                string relations = BitHelper.ToBinaryFormat(dsRelationRow.Data, true);
                relations = BaseMarkupUtilities.ReverseString(relations);
                bool hasTable = false;
                foreach (int tableIndex in sortedTableIndexes)
                {
                    int index = tableIndex;
                    if (relations.Length > index && relations[index] == '1')
                    {
                        path.AddRange(usedTableIndexes[tableIndex]);
                        if (!checker.ContainsKey(tableIndex))
                        {
                            hasTable = true;
                            checker.Add(tableIndex, true);
                        }
                    }
                }

                if (hasTable)
                {
                    int parentTableIndex = GetParentTableInexInJoinClause(dsWhereRelationRow, dsRelationRow);
                    if (!usedTableIndexes.ContainsKey(parentTableIndex))
                    {
                        usedTableIndexes.Add(parentTableIndex, new List <InternalBookmarkItem>());
                    }
                    InternalBookmarkItem ibmItem = usedTableIndexes[parentTableIndex].FirstOrDefault(
                        c => c.TableIndex == parentTableIndex && c.DSIconType == DSIconType.Field);
                    if (ibmItem == null)
                    {
                        DSTreeView firstField = paramInfo.DomainInfo.Fields.Values.FirstOrDefault(
                            c => c.TableIndex == parentTableIndex && c.Type == DSIconType.Field);
                        if (firstField != null)
                        {
                            ibmItem = new InternalBookmarkItem()
                            {
                                BizName    = firstField.Text,
                                ItemType   = "Field",
                                JavaName   = firstField.JavaClause,
                                Key        = Guid.NewGuid().ToString(),
                                OrderNo    = 1,
                                TableIndex = parentTableIndex,
                                TechName   = firstField.TechName,
                                Type       = XsltType.Select
                            };

                            usedTableIndexes[parentTableIndex].Insert(0, ibmItem);
                            path.Insert(0, ibmItem);
                        }
                    }

                    paths.Add(path);
                }
            }
            #endregion

            return(paths);
        }
Example #2
0
        protected void GenWhereClause(ref GenOsqlParamInfo paramInfo)
        {
            if (paramInfo.WhereClauses == null)
            {
                paramInfo.WhereClauses = new List <string>();
            }
            if (paramInfo.JWhereClauses == null)
            {
                paramInfo.JWhereClauses = new List <string>();
            }
            if (paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins == null ||
                paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins.Count == 0)
            {
                paramInfo.WhereClauses.Add(paramInfo.DomainInfo.DSDomainData.WhereClause.Clause);
                paramInfo.JWhereClauses.Add(paramInfo.DomainInfo.DSDomainData.WhereClause.JavaClause);
            }
            else
            {
                paramInfo.DSWhereClauseRelationRow = null;
                string whereClause  = string.Empty;
                string jWhereClause = string.Empty;
                string logicType    = string.Empty;
                bool   hasRootJoin  = false;
                foreach (DSJoin dsJoin in paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins)
                {
                    string usedTables = BitHelper.ToBinaryFormat(dsJoin.Tables.Data, true);
                    usedTables = BaseMarkupUtilities.ReverseString(usedTables);
                    bool isUseDSJoin = true;

                    #region check use or no
                    for (int index = 0; index < usedTables.Length; index++)
                    {
                        if (usedTables[index] == '1')
                        {
                            if (!paramInfo.SelectedTableIndexes.Contains(index))
                            {
                                isUseDSJoin = false;
                                break;
                            }
                        }
                    }
                    if (!isUseDSJoin)
                    {
                        continue;
                    }
                    #endregion

                    #region build where clause
                    if ("and".Equals(dsJoin.LogicType, StringComparison.OrdinalIgnoreCase) ||
                        "or".Equals(dsJoin.LogicType, StringComparison.OrdinalIgnoreCase))
                    {
                        if (!hasRootJoin)
                        {
                            whereClause  = dsJoin.LogicType + " " + dsJoin.Condition + " " + whereClause;
                            jWhereClause = dsJoin.LogicType + " " + dsJoin.JavaCondition + " " + jWhereClause;
                        }
                        else
                        {
                            whereClause  = whereClause + " " + dsJoin.LogicType + " " + dsJoin.Condition;
                            jWhereClause = jWhereClause + " " + dsJoin.LogicType + " " + dsJoin.JavaCondition;
                        }
                        logicType = dsJoin.LogicType;
                    }
                    else
                    {
                        whereClause  = dsJoin.Condition + " " + whereClause;
                        jWhereClause = dsJoin.JavaCondition + " " + jWhereClause;
                        hasRootJoin  = true;
                    }
                    #endregion

                    #region mark used for gen from clause
                    if (paramInfo.DSWhereClauseRelationRow == null)
                    {
                        paramInfo.DSWhereClauseRelationRow = dsJoin.Tables.Clone();
                    }
                    else
                    {
                        paramInfo.DSWhereClauseRelationRow.OrRow(dsJoin.Tables);
                    }
                    #endregion
                }

                if (!hasRootJoin && !string.IsNullOrWhiteSpace(logicType))
                {
                    whereClause  = whereClause.Substring(logicType.Length);
                    jWhereClause = jWhereClause.Substring(logicType.Length);
                }
                paramInfo.WhereClauses.Add(whereClause);
                paramInfo.JWhereClauses.Add(jWhereClause);
                if (paramInfo.DSWhereClauseRelationRow == null)
                {
                    DSRelationRow templateRow = paramInfo.DomainInfo.DSDomainData.WhereClause.DSJoins[0].Tables;
                    paramInfo.DSWhereClauseRelationRow = templateRow.Clone();
                    for (int index = 0; index < paramInfo.DSWhereClauseRelationRow.Data.Count; index++)
                    {
                        paramInfo.DSWhereClauseRelationRow.Data[index] = paramInfo.DSWhereClauseRelationRow.Data[index] & 0;
                    }
                    foreach (int tableIndex in paramInfo.SelectedTableIndexes)
                    {
                        int index = (tableIndex / 64) + (tableIndex % 64 != 0 ? 1 : 0);
                        index--;
                        if (index >= 0 && index < paramInfo.DSWhereClauseRelationRow.Data.Count)
                        {
                            int position = tableIndex % 64;
                            paramInfo.DSWhereClauseRelationRow.Data[index] =
                                paramInfo.DSWhereClauseRelationRow.TurnOnBit(paramInfo.DSWhereClauseRelationRow.Data[index], position);
                        }
                    }
                }
            }
        }