Exemplo n.º 1
0
        public static int CompareDBTable(DBTable x, DBTable y)
        {
            if (x == y)
            {
                return(0);
            }
            if (x.Type != y.Type)
            {
                if (x.Type == DBTableType.Table)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
            var xpars = new List <DBTable>();

            x.GetAllParentTables(xpars);
            var ypars = new List <DBTable>();

            y.GetAllParentTables(ypars);
            var xchil = new List <DBTable>();

            x.GetAllChildTables(xchil);
            var ychil = new List <DBTable>();

            y.GetAllChildTables(ychil);

            if (xpars.Contains(y))
            {
                return(1);
            }
            else if (ypars.Contains(x))
            {
                return(-1);
            }
            else
            {
                var merge = (List <DBTable>)ListHelper.AND(xpars, ypars, null);
                if (merge.Count > 0)
                {
                    int r = xpars.Count.CompareTo(ypars.Count);
                    if (r != 0)
                    {
                        return(r);
                    }
                }
                // foreach(DBTable xp in xpars)
                //     if(xp.GetChildTables())
            }

            if (xchil.Contains(y))
            {
                return(-1);
            }
            else if (ychil.Contains(x))
            {
                return(1);
            }
            else
            {
                List <DBTable> merge = (List <DBTable>)ListHelper.AND(xchil, ychil, null);
                if (merge.Count > 0)
                {
                    int r = xchil.Count.CompareTo(ychil.Count);
                    if (r != 0)
                    {
                        return(r);
                    }
                }
                // foreach(DBTable xp in xpars)
                //     if(xp.GetChildTables())
            }
            return(string.Compare(x.Name, y.Name, StringComparison.Ordinal));
        }