Beispiel #1
0
        public string Create()
        {
            StringBuilder	strBuilder = new StringBuilder();

            if(this.OwnerObject.GetExtensions()!=null&&_AddExObjects)
            {
                _KeyUniquePrefix	=	this.OwnerObject.OwnerTable;
            }

            ArrayList	arrayExObjectList = new ArrayList();

            // Step 1. Create Common SQL Query [4/29/2004]
            CreateSQLQueryList();

            if(this.OwnerObject.GetExtensions()!=null&&_AddExObjects)
            {
                foreach(QObject	exObject in this.OwnerObject.GetExtensions())
                {
                    QMaker	exMaker	=	new QMaker(exObject, this.OwnerObject.OwnerTable,exObject.OwnerTable);

                    // 2006-12-12: Fix Language Problem
                    exMaker.Language = this.Language;

                    foreach(QField	exField	in this.Fields)
                    {
                        exMaker.Fields.Add(exObject.Fields[exField.Name]);
                    }

                    foreach(QField	exGroup	in this.Groups)
                    {
                        exMaker.Groups.Add(exObject.Fields[exGroup.Name]);
                    }

                    foreach(FilterCondition	exFilter	in this.Filters)
                    {
                        if(exFilter is SimpleFilterCondition)
                        {
                            SimpleFilterCondition tmpFilter = (SimpleFilterCondition)exFilter;
                            SimpleFilterCondition newFilter	=	new SimpleFilterCondition(exObject.Fields[tmpFilter.OwnerField.Name],"", tmpFilter.FilterType);
                            newFilter.InternalValue = tmpFilter.InternalValue;

                            if(tmpFilter.OwnerField.DBName!=null)
                            {
                                int iIndexOfKey = newFilter.InternalValue.IndexOf("@"+tmpFilter.OwnerField.DBName);
                                if(iIndexOfKey!=-1)
                                {
                                    newFilter.InternalValue = newFilter.InternalValue.Replace("@"+tmpFilter.OwnerField.DBName,"@"+newFilter.OwnerField.DBName);
                                }
                            }

                            exMaker.Filters.Add(newFilter);
                        }
                        else if(exFilter is IntervalFilterCondition)
                        {
                            IntervalFilterCondition tmpFilter = (IntervalFilterCondition)exFilter;
                            IntervalFilterCondition newFilter	=	new IntervalFilterCondition(exObject.Fields[tmpFilter.OwnerField.Name],tmpFilter.ValueLess, tmpFilter.ValueGreat);

                            exMaker.Filters.Add(newFilter);
                        }
                        else if(exFilter is ExtendedFilterCondition)
                        {
                            ExtendedFilterCondition tmpFilter = (ExtendedFilterCondition)exFilter;
                            ExtendedFilterCondition newFilter	=	new ExtendedFilterCondition(tmpFilter.Query, tmpFilter.Value);

                            exMaker.Filters.Add(newFilter);
                        }
                    }

                    arrayExObjectList.Add(exMaker);

            //					ArrayList	addonQuery = exMaker.CreateSQLQueryList();
            //
            //					for(int iIndex=1;iIndex<addonQuery.Count;iIndex++)
            //					{
            //						QSqlSelectList.Add(addonQuery[iIndex]);
            //					}
                }
            }

            // Add prev SQL Commands [5/7/2004]
            foreach(string PrevCommand in this.PrevSqlQuery)
            {
                strBuilder.Append(PrevCommand);
                strBuilder.Append("\r\n");
            }

            // Create SQL Command
            bool bRunFirst = true;

            foreach(QSqlSelectMaker sqlMaker in QSqlSelectList)
            {
                if(bRunFirst)
                    bRunFirst = false;
                else
                    //strBuilder.Append("\r\nUNION ALL\r\n");
                    strBuilder.Append("\r\nUNION\r\n");
                strBuilder.Append( sqlMaker.Create(this.OwnerObject.OwnerTable,this.Groups));
            }

            foreach(QMaker	exMaker in arrayExObjectList)
            {
                ArrayList	addonQuery = exMaker.CreateSQLQueryList();

                for(int iIndex=1;iIndex<addonQuery.Count;iIndex++)
                {
                    if(bRunFirst)
                        bRunFirst = false;
                    else
                        //strBuilder.Append("\r\nUNION ALL\r\n");
                        strBuilder.Append("\r\nUNION\r\n");

                    strBuilder.Append( ((QSqlSelectMaker)addonQuery[iIndex]).Create(exMaker.OwnerObject.OwnerTable,this.Groups));
                }
            }

            // Add order By Command [4/20/2004]
            if(OrderByFields.Count>0)
            {
                strBuilder.Append("\r\nORDER BY");

                bRunFirst = true;
                foreach(string OrderAlias in OrderByFields)
                {
                    if(bRunFirst)
                    {
                        bRunFirst = false;
                        strBuilder.Append(" ");
                    }
                    else
                        strBuilder.Append(" , ");

                    strBuilder.Append(OrderAlias);
                }
            }

            // Final step [4/20/2004]
            strBuilder.Append("\r\nFOR XML EXPLICIT");

            #if DEBUG
            System.Diagnostics.Trace.WriteLine(strBuilder.ToString());
            #endif

            return strBuilder.ToString();
        }
Beispiel #2
0
        public string Create()
        {
            StringBuilder strBuilder = new StringBuilder();

            if (this.OwnerObject.GetExtensions() != null && _AddExObjects)
            {
                _KeyUniquePrefix = this.OwnerObject.OwnerTable;
            }

            ArrayList arrayExObjectList = new ArrayList();

            // Step 1. Create Common SQL Query [4/29/2004]
            CreateSQLQueryList();

            if (this.OwnerObject.GetExtensions() != null && _AddExObjects)
            {
                foreach (QObject exObject in this.OwnerObject.GetExtensions())
                {
                    QMaker exMaker = new QMaker(exObject, this.OwnerObject.OwnerTable, exObject.OwnerTable);

                    // 2006-12-12: Fix Language Problem
                    exMaker.Language = this.Language;

                    foreach (QField exField in this.Fields)
                    {
                        exMaker.Fields.Add(exObject.Fields[exField.Name]);
                    }

                    foreach (QField exGroup in this.Groups)
                    {
                        exMaker.Groups.Add(exObject.Fields[exGroup.Name]);
                    }

                    foreach (FilterCondition exFilter        in this.Filters)
                    {
                        if (exFilter is SimpleFilterCondition)
                        {
                            SimpleFilterCondition tmpFilter = (SimpleFilterCondition)exFilter;
                            SimpleFilterCondition newFilter = new SimpleFilterCondition(exObject.Fields[tmpFilter.OwnerField.Name], "", tmpFilter.FilterType);
                            newFilter.InternalValue = tmpFilter.InternalValue;

                            if (tmpFilter.OwnerField.DBName != null)
                            {
                                int iIndexOfKey = newFilter.InternalValue.IndexOf("@" + tmpFilter.OwnerField.DBName);
                                if (iIndexOfKey != -1)
                                {
                                    newFilter.InternalValue = newFilter.InternalValue.Replace("@" + tmpFilter.OwnerField.DBName, "@" + newFilter.OwnerField.DBName);
                                }
                            }

                            exMaker.Filters.Add(newFilter);
                        }
                        else if (exFilter is IntervalFilterCondition)
                        {
                            IntervalFilterCondition tmpFilter = (IntervalFilterCondition)exFilter;
                            IntervalFilterCondition newFilter = new IntervalFilterCondition(exObject.Fields[tmpFilter.OwnerField.Name], tmpFilter.ValueLess, tmpFilter.ValueGreat);

                            exMaker.Filters.Add(newFilter);
                        }
                        else if (exFilter is ExtendedFilterCondition)
                        {
                            ExtendedFilterCondition tmpFilter = (ExtendedFilterCondition)exFilter;
                            ExtendedFilterCondition newFilter = new ExtendedFilterCondition(tmpFilter.Query, tmpFilter.Value);

                            exMaker.Filters.Add(newFilter);
                        }
                    }

                    arrayExObjectList.Add(exMaker);

//					ArrayList	addonQuery = exMaker.CreateSQLQueryList();
//
//					for(int iIndex=1;iIndex<addonQuery.Count;iIndex++)
//					{
//						QSqlSelectList.Add(addonQuery[iIndex]);
//					}
                }
            }

            // Add prev SQL Commands [5/7/2004]
            foreach (string PrevCommand in this.PrevSqlQuery)
            {
                strBuilder.Append(PrevCommand);
                strBuilder.Append("\r\n");
            }

            // Create SQL Command
            bool bRunFirst = true;

            foreach (QSqlSelectMaker sqlMaker in QSqlSelectList)
            {
                if (bRunFirst)
                {
                    bRunFirst = false;
                }
                else
                {
                    //strBuilder.Append("\r\nUNION ALL\r\n");
                    strBuilder.Append("\r\nUNION\r\n");
                }
                strBuilder.Append(sqlMaker.Create(this.OwnerObject.OwnerTable, this.Groups));
            }

            foreach (QMaker exMaker in arrayExObjectList)
            {
                ArrayList addonQuery = exMaker.CreateSQLQueryList();

                for (int iIndex = 1; iIndex < addonQuery.Count; iIndex++)
                {
                    if (bRunFirst)
                    {
                        bRunFirst = false;
                    }
                    else
                    {
                        //strBuilder.Append("\r\nUNION ALL\r\n");
                        strBuilder.Append("\r\nUNION\r\n");
                    }

                    strBuilder.Append(((QSqlSelectMaker)addonQuery[iIndex]).Create(exMaker.OwnerObject.OwnerTable, this.Groups));
                }
            }

            // Add order By Command [4/20/2004]
            if (OrderByFields.Count > 0)
            {
                strBuilder.Append("\r\nORDER BY");

                bRunFirst = true;
                foreach (string OrderAlias in OrderByFields)
                {
                    if (bRunFirst)
                    {
                        bRunFirst = false;
                        strBuilder.Append(" ");
                    }
                    else
                    {
                        strBuilder.Append(" , ");
                    }

                    strBuilder.Append(OrderAlias);
                }
            }

            // Final step [4/20/2004]
            strBuilder.Append("\r\nFOR XML EXPLICIT");

#if DEBUG
            System.Diagnostics.Trace.WriteLine(strBuilder.ToString());
#endif

            return(strBuilder.ToString());
        }