示例#1
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxSetting.
        /// </summary>
        /// <returns> A new GreyFoxSetting object reflecting the cloned GreyFoxSetting object.</returns>
        /// <param name="isolation">Placeholders are used to isolate the GreyFoxSetting from its children.</param>
        public GreyFoxSetting Copy(bool isolation)
        {
            GreyFoxSetting greyFoxSetting = new GreyFoxSetting();

            CopyTo(greyFoxSetting, isolation);
            return(greyFoxSetting);
        }
示例#2
0
 /// <summary>
 /// Deep copies the current GreyFoxSetting to another instance of GreyFoxSetting.
 /// </summary>
 /// <param name="GreyFoxSetting">The GreyFoxSetting to copy to.</param>
 /// <param name="isolation">Placeholders are used to isolate the GreyFoxSetting from its children.</param>
 public void CopyTo(GreyFoxSetting greyFoxSetting, bool isolation)
 {
     greyFoxSetting.iD            = iD;
     greyFoxSetting.isPlaceHolder = isPlaceHolder;
     greyFoxSetting.isSynced      = isSynced;
     greyFoxSetting.name          = name;
     greyFoxSetting.settingValue  = settingValue;
     if (parent != null)
     {
         if (isolation)
         {
             greyFoxSetting.parent = parent.NewPlaceHolder();
         }
         else
         {
             greyFoxSetting.parent = parent.Copy(false);
         }
     }
     if (modifyRole != null)
     {
         if (isolation)
         {
             greyFoxSetting.modifyRole = modifyRole.NewPlaceHolder();
         }
         else
         {
             greyFoxSetting.modifyRole = modifyRole.Copy(false);
         }
     }
     greyFoxSetting.isSystemSetting = isSystemSetting;
 }
示例#3
0
        private static void fillParameters(Database database, DbCommand dbCommand, GreyFoxSetting greyFoxSetting)
        {
            #region General

            addParameter(database, dbCommand, "@Name", DbType.String, greyFoxSetting.name);
            addParameter(database, dbCommand, "@SettingValue", DbType.String, greyFoxSetting.settingValue);
            if (greyFoxSetting.parent == null)
            {
                addParameter(database, dbCommand, "@ParentID", DbType.Int32, DBNull.Value);
            }
            else
            {
                addParameter(database, dbCommand, "@ParentID", DbType.Int32, greyFoxSetting.parent.ID);
            }
            if (greyFoxSetting.modifyRole == null)
            {
                addParameter(database, dbCommand, "@ModifyRoleID", DbType.Int32, DBNull.Value);
            }
            else
            {
                addParameter(database, dbCommand, "@ModifyRoleID", DbType.Int32, greyFoxSetting.modifyRole.ID);
            }
            addParameter(database, dbCommand, "@IsSystemSetting", DbType.Boolean, greyFoxSetting.isSystemSetting);

            #endregion
        }
示例#4
0
        /// <summary>
        /// Makes a deep copy of the current GreyFoxSetting.
        /// </summary>
        /// <returns> A new GreyFoxSetting object reflecting the cloned GreyFoxSetting object.</returns>
        public GreyFoxSetting Copy()
        {
            GreyFoxSetting greyFoxSetting = new GreyFoxSetting();

            CopyTo(greyFoxSetting);
            return(greyFoxSetting);
        }
示例#5
0
        public static GreyFoxSetting GetSetting(GreyFoxSetting parent, string key)
        {
            GreyFoxSettingManager    settingManager;
            GreyFoxSettingCollection settingCollection;

            settingManager = new GreyFoxSettingManager();

            if (parent == null)
            {
                settingCollection = settingManager.GetCollection("Name='" +
                                                                 key + "'", string.Empty, null);
            }
            else
            {
                settingCollection = settingManager.GetCollection("ParentID=" +
                                                                 parent.ID.ToString() +
                                                                 " AND Name='" +
                                                                 key + "'", string.Empty, null);
            }

            if (settingCollection.Count == 1)
            {
                return(settingCollection[0]);
            }
            else
            {
                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Inserts a GreyFoxSetting into the database. All children should have been
        /// saved to the database before insertion. New children will not be
        /// related to this object in the database.
        /// </summary>
        /// <param name="_GreyFoxSetting">The GreyFoxSetting to insert into the database.</param>
        internal static int _insert(GreyFoxSetting greyFoxSetting)
        {
            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            OleDbCommand    dbCommand    = new OleDbCommand();

            dbCommand.Connection  = dbConnection;
            dbCommand.CommandText = "INSERT INTO sysGlobal_Settings (Name," +
                                    "Value," +
                                    "ModifyRoleID) VALUES (" +
                                    "inName," +
                                    "inValue," +
                                    "inModifyRoleID);";

            fillParameters(dbCommand, greyFoxSetting);

            dbConnection.Open();
            dbCommand.ExecuteNonQuery();
            dbCommand.CommandText = "SELECT @@IDENTITY AS IDVal";
            int id = (int)dbCommand.ExecuteScalar();

            dbConnection.Close();
            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }
            return(id);
        }
示例#7
0
        internal static int _update(GreyFoxSetting greyFoxSetting)
        {
            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            OleDbCommand    dbCommand    = new OleDbCommand();

            dbCommand.Connection  = dbConnection;
            dbCommand.CommandText = "UPDATE sysGlobal_Settings SET Name=inName," +
                                    "Value=inValue," +
                                    "ModifyRoleID=inModifyRoleID WHERE GreyFoxSettingID=inGreyFoxSettingID";

            fillParameters(dbCommand, greyFoxSetting);

            dbCommand.Parameters.Add("inGreyFoxSettingID", OleDbType.Integer).Value = greyFoxSetting.iD;
            dbConnection.Open();

            // Abandon remaining updates if no rows have been updated by returning false immediately.
            if (dbCommand.ExecuteNonQuery() == 0)
            {
                return(-1);
            }

            dbConnection.Close();

            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }

            return(greyFoxSetting.iD);
        }
示例#8
0
        public static GreyFoxSetting ParseFromReader(OleDbDataReader r, int idOffset, int dataOffset)
        {
            GreyFoxSetting greyFoxSetting = new GreyFoxSetting();

            FillFromReader(greyFoxSetting, r, idOffset, dataOffset);
            return(greyFoxSetting);
        }
示例#9
0
        internal static int _update(GreyFoxSetting greyFoxSetting)
        {
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            dbCommand = database.GetSqlStringCommand("UPDATE sysGlobal_Settings SET Name=@Name," +
                                                     "SettingValue=@SettingValue," +
                                                     "ParentID=@ParentID," +
                                                     "ModifyRoleID=@ModifyRoleID," +
                                                     "IsSystemSetting=@IsSystemSetting WHERE GreyFoxSettingID=@GreyFoxSettingID;");

            fillParameters(database, dbCommand, greyFoxSetting);
            database.AddInParameter(dbCommand, "GreyFoxSettingID", DbType.Int32, greyFoxSetting.iD);
            // Abandon remaining updates if no rows have been updated by returning false immediately.
            if (database.ExecuteNonQuery(dbCommand) == 0)
            {
                return(-1);
            }

            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }

            return(greyFoxSetting.iD);
        }
示例#10
0
        /// <summary>
        /// Duplicates GreyFoxSetting object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new GreyFoxSetting object reflecting the replicated GreyFoxSetting object.</returns>
        public GreyFoxSetting Duplicate()
        {
            GreyFoxSetting clonedGreyFoxSetting = this.Clone();

            // Insert must be called after children are replicated!
            clonedGreyFoxSetting.iD       = GreyFoxSettingManager._insert(clonedGreyFoxSetting);
            clonedGreyFoxSetting.isSynced = true;
            return(clonedGreyFoxSetting);
        }
示例#11
0
        public static GreyFoxSetting NewPlaceHolder(int iD)
        {
            GreyFoxSetting greyFoxSetting = new GreyFoxSetting();

            greyFoxSetting.iD            = iD;
            greyFoxSetting.isPlaceHolder = true;
            greyFoxSetting.isSynced      = true;
            return(greyFoxSetting);
        }
示例#12
0
 private static void cacheStore(GreyFoxSetting greyFoxSetting)
 {
     CatchWebCache();
     if (_webCache == null)
     {
         return;
     }
     _webCache.Insert("GFX_GreyFoxSetting_" + greyFoxSetting.ID.ToString(), greyFoxSetting.Copy(true), null, DateTime.MaxValue, TimeSpan.FromSeconds(1800), CacheItemPriority.Normal, null);
 }
示例#13
0
        public bool Equals(GreyFoxSetting greyFoxSetting)
        {
            if (greyFoxSetting == null)
            {
                return(false);
            }

            return(this.iD == greyFoxSetting.iD);
        }
示例#14
0
        public void Remove(GreyFoxSetting value)
        {
            OnCollectionChanged(EventArgs.Empty);
            int index = IndexOf(value);

            if (index == -1)
            {
                throw(new Exception("GreyFoxSetting not found in collection."));
            }
            RemoveAt(index);
        }
示例#15
0
        /// <summary>
        /// Inserts a GreyFoxSetting into the database. All children should have been
        /// saved to the database before insertion. New children will not be
        /// related to this object in the database.
        /// </summary>
        /// <param name="_GreyFoxSetting">The GreyFoxSetting to insert into the database.</param>
        internal static int _insert(GreyFoxSetting greyFoxSetting)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO sysGlobal_Settings " +
                    "(" +
                    "Name," +
                    "SettingValue," +
                    "ParentID," +
                    "ModifyRoleID," +
                    "IsSystemSetting) VALUES (" +
                    "@Name," +
                    "@SettingValue," +
                    "@ParentID," +
                    "@ModifyRoleID," +
                    "@IsSystemSetting);";

            if (database.ConnectionStringWithoutCredentials.StartsWith("provider=microsoft.jet.oledb.4.0"))
            {
                // Microsoft Access
                // Connection must remain open for IDENTITY to return correct value,
                // therefore use the dbCommand object's Connection directly to control
                // connection state.
                dbCommand = database.GetSqlStringCommand(query);
                fillParameters(database, dbCommand, greyFoxSetting);
                dbCommand.Connection = database.CreateConnection();
                dbCommand.Connection.Open();
                dbCommand.ExecuteNonQuery();
                dbCommand.CommandText = "SELECT @@IDENTITY AS LastID";
                id = (int)dbCommand.ExecuteScalar();
                dbCommand.Connection.Close();
            }
            else
            {
                //// Microsoft SQL Server
                dbCommand = database.GetSqlStringCommand(query + " SELECT @LastID = SCOPE_IDENTITY();");
                fillParameters(database, dbCommand, greyFoxSetting);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }
            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }
            return(id);
        }
示例#16
0
 public int IndexOf(GreyFoxSetting value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (GreyFoxSettingArray[x].Equals(value))
             {
                 return(x);
             }
         }
         return(-1);
     }
 }
示例#17
0
        private static void fillParameters(OleDbCommand command, GreyFoxSetting greyFoxSetting)
        {
            #region General

            command.Parameters.Add("inName", OleDbType.VarChar).Value  = greyFoxSetting.name;
            command.Parameters.Add("inValue", OleDbType.VarChar).Value = greyFoxSetting.value;
            if (greyFoxSetting.modifyRole == null)
            {
                command.Parameters.Add("inModifyRoleID", OleDbType.Integer).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("inModifyRoleID", OleDbType.Integer).Value = greyFoxSetting.modifyRole.ID;
            }
            #endregion
        }
示例#18
0
        /// <summary>
        /// Clones GreyFoxSetting object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new GreyFoxSetting object reflecting the replicated GreyFoxSetting object.</returns>
        public GreyFoxSetting Clone()
        {
            GreyFoxSetting clonedGreyFoxSetting = new GreyFoxSetting();

            clonedGreyFoxSetting.iD       = iD;
            clonedGreyFoxSetting.isSynced = isSynced;
            clonedGreyFoxSetting.name     = name;
            clonedGreyFoxSetting.value    = value;

            if (modifyRole != null)
            {
                clonedGreyFoxSetting.modifyRole = modifyRole;
            }

            return(clonedGreyFoxSetting);
        }
示例#19
0
        internal static bool _fill(GreyFoxSetting greyFoxSetting)
        {
            // Clone item from cache.
            if (cacheEnabled)
            {
                object cachedObject = cacheFind(greyFoxSetting.iD);
                if (cachedObject != null)
                {
                    ((GreyFoxSetting)cachedObject).CopyTo(greyFoxSetting, true);
                    return(greyFoxSetting.isSynced);
                }
            }

            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;

            query = new StringBuilder("SELECT ");
            query.Append(string.Join(",", InnerJoinFields));
            query.Append(" FROM sysGlobal_Settings WHERE GreyFoxSettingID=");
            query.Append(greyFoxSetting.iD);
            query.Append(";");

            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
            IDataReader r = database.ExecuteReader(dbCommand);

            if (!r.Read())
            {
                throw(new Exception(string.Format("Cannot find GreyFoxSettingID '{0}'.",
                                                  greyFoxSetting.iD)));
            }

            FillFromReader(greyFoxSetting, r, 0, 1);

            // Microsoft DAAB still needs to have the reader closed.
            r.Close();

            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }

            return(true);
        }
示例#20
0
        /// <summary>
        /// Fills the {0} from a OleIDataReader.
        /// </summary>
        public static void FillFromReader(GreyFoxSetting greyFoxSetting, IDataReader r, int idOffset, int dataOffset)
        {
            greyFoxSetting.iD            = r.GetInt32(idOffset);
            greyFoxSetting.isSynced      = true;
            greyFoxSetting.isPlaceHolder = false;

            greyFoxSetting.name         = r.GetString(0 + dataOffset);
            greyFoxSetting.settingValue = r.GetString(1 + dataOffset);
            if (!r.IsDBNull(2 + dataOffset) && r.GetInt32(2 + dataOffset) > 0)
            {
                greyFoxSetting.parent = GreyFoxSetting.NewPlaceHolder(r.GetInt32(2 + dataOffset));
            }
            if (!r.IsDBNull(3 + dataOffset) && r.GetInt32(3 + dataOffset) > 0)
            {
                greyFoxSetting.modifyRole = GreyFoxRole.NewPlaceHolder(r.GetInt32(3 + dataOffset));
            }
            greyFoxSetting.isSystemSetting = r.GetBoolean(4 + dataOffset);
        }
示例#21
0
 public int Add(GreyFoxSetting value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > GreyFoxSettingArray.GetUpperBound(0) + 1)
         {
             GreyFoxSetting[] tempGreyFoxSettingArray = new GreyFoxSetting[count * 2];
             Array.Copy(GreyFoxSettingArray, tempGreyFoxSettingArray, count - 1);
             GreyFoxSettingArray = tempGreyFoxSettingArray;
         }
         GreyFoxSettingArray[count - 1] = value;
     }
     return(count - 1);
 }
示例#22
0
        internal static bool _fill(GreyFoxSetting greyFoxSetting)
        {
            // Clone item from cache.
            if (cacheEnabled)
            {
                GreyFoxSetting cachedGreyFoxSetting = cacheFind(greyFoxSetting.iD);
                if (cachedGreyFoxSetting != null)
                {
                    cachedGreyFoxSetting.CopyTo(greyFoxSetting, true);
                    return(greyFoxSetting.isSynced);
                }
            }

            StringBuilder query = new StringBuilder("SELECT ");

            query.Append(string.Join(",", InnerJoinFields));
            query.Append(" FROM sysGlobal_Settings WHERE GreyFoxSettingID=");
            query.Append(greyFoxSetting.iD);
            query.Append(";");

            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            OleDbCommand    dbCommand    = new OleDbCommand(query.ToString(), dbConnection);

            dbConnection.Open();
            OleDbDataReader r = dbCommand.ExecuteReader(CommandBehavior.SingleRow);

            if (!r.Read())
            {
                throw(new Exception(string.Format("Cannot find GreyFoxSettingID '{0}'.",
                                                  greyFoxSetting.iD)));
            }

            FillFromReader(greyFoxSetting, r, 0, 1);

            r.Close();
            dbConnection.Close();
            // Store greyFoxSetting in cache.
            if (cacheEnabled)
            {
                cacheStore(greyFoxSetting);
            }
            return(true);
        }
示例#23
0
        /// <summary>
        /// Fills the {0} from a OleDbDataReader.
        /// </summary>
        public static void FillFromReader(GreyFoxSetting greyFoxSetting, OleDbDataReader r, int idOffset, int dataOffset)
        {
            greyFoxSetting.iD            = r.GetInt32(idOffset);
            greyFoxSetting.isSynced      = true;
            greyFoxSetting.isPlaceHolder = false;

            //
            // Parse Children From Database
            //
            if (!r.IsDBNull(0 + dataOffset) && r.GetInt32(0 + dataOffset) > 0)
            {
                greyFoxSetting.modifyRole = GreyFoxRole.NewPlaceHolder(r.GetInt32(0 + dataOffset));
            }

            //
            // Parse Fields From Database
            //
            greyFoxSetting.name  = r.GetString(1 + dataOffset);
            greyFoxSetting.value = r.GetString(2 + dataOffset);
        }
示例#24
0
        /// <summary>
        /// Deep copies the current GreyFoxSetting to another instance of GreyFoxSetting.
        /// </summary>
        /// <param name="GreyFoxSetting">The GreyFoxSetting to copy to.</param>
        /// <param name="isolation">Placeholders are used to isolate the GreyFoxSetting from its children.</param>
        public void CopyTo(GreyFoxSetting greyFoxSetting, bool isolation)
        {
            greyFoxSetting.iD            = iD;
            greyFoxSetting.isPlaceHolder = isPlaceHolder;
            greyFoxSetting.isSynced      = isSynced;
            greyFoxSetting.name          = name;
            greyFoxSetting.value         = value;

            if (modifyRole != null)
            {
                if (isolation)
                {
                    greyFoxSetting.modifyRole = modifyRole.NewPlaceHolder();
                }
                else
                {
                    greyFoxSetting.modifyRole = modifyRole.Copy(false);
                }
            }
        }
示例#25
0
 public void Insert(int index, GreyFoxSetting value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > GreyFoxSettingArray.GetUpperBound(0) + 1)
         {
             GreyFoxSetting[] tempGreyFoxSettingArray = new GreyFoxSetting[count * 2];
             Array.Copy(GreyFoxSettingArray, tempGreyFoxSettingArray, count - 1);
             GreyFoxSettingArray = tempGreyFoxSettingArray;
         }
         for (int x = index + 1; x == count - 2; x++)
         {
             GreyFoxSettingArray[x] = GreyFoxSettingArray[x - 1];
         }
         GreyFoxSettingArray[index] = value;
     }
 }
示例#26
0
        /// <summary>
        /// Clones GreyFoxSetting object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new GreyFoxSetting object reflecting the replicated GreyFoxSetting object.</returns>
        public GreyFoxSetting Clone()
        {
            GreyFoxSetting clonedGreyFoxSetting = new GreyFoxSetting();

            clonedGreyFoxSetting.iD              = iD;
            clonedGreyFoxSetting.isSynced        = isSynced;
            clonedGreyFoxSetting.name            = name;
            clonedGreyFoxSetting.settingValue    = settingValue;
            clonedGreyFoxSetting.isSystemSetting = isSystemSetting;


            if (parent != null)
            {
                clonedGreyFoxSetting.parent = parent;
            }

            if (modifyRole != null)
            {
                clonedGreyFoxSetting.modifyRole = modifyRole;
            }

            return(clonedGreyFoxSetting);
        }
示例#27
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(GreyFoxSetting greyFoxSetting)
 {
     return(this.iD - greyFoxSetting.iD);
 }
示例#28
0
        private static void cacheStore(GreyFoxSetting greyFoxSetting)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add("sysGlobal_Settings_" + greyFoxSetting.iD.ToString(), greyFoxSetting);
        }
示例#29
0
        public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags)
        {
            StringBuilder            query;
            Database                 database;
            DbCommand                dbCommand;
            IDataReader              r;
            GreyFoxSettingCollection greyFoxSettingCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("GreyFoxSetting.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int parentOffset           = -1;
            int parentParentOffset     = -1;
            int parentModifyRoleOffset = -1;
            int modifyRoleOffset       = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.Parent:
                        for (int i = 0; i <= GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Parent.");
                            query.Append(GreyFoxSettingManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentOffset    = innerJoinOffset;
                        innerJoinOffset = parentOffset + GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case GreyFoxSettingFlags.ParentParent:
                        for (int i = 0; i <= GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Parent_Parent.");
                            query.Append(GreyFoxSettingManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentParentOffset = innerJoinOffset;
                        innerJoinOffset    = parentParentOffset + GreyFoxSettingManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case GreyFoxSettingFlags.ParentModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Parent_ModifyRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        parentModifyRoleOffset = innerJoinOffset;
                        innerJoinOffset        = parentModifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case GreyFoxSettingFlags.ModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("ModifyRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        modifyRoleOffset = innerJoinOffset;
                        innerJoinOffset  = modifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("sysGlobal_Settings AS GreyFoxSetting");
            }
            else
            {
                query.Append(" FROM sysGlobal_Settings AS GreyFoxSetting");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.Parent:
                        query.Append(" LEFT JOIN sysGlobal_Settings AS Parent ON GreyFoxSetting.ParentID = Parent.GreyFoxSettingID)");
                        break;

                    case GreyFoxSettingFlags.ParentParent:
                        query.Append(" LEFT JOIN sysGlobal_Settings AS Parent_Parent ON Parent.ParentID = Parent_Parent.GreyFoxSettingID)");
                        break;

                    case GreyFoxSettingFlags.ParentModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS Parent_ModifyRole ON Parent.ModifyRoleID = Parent_ModifyRole.GreyFoxRoleID)");
                        break;

                    case GreyFoxSettingFlags.ModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS ModifyRole ON GreyFoxSetting.ModifyRoleID = ModifyRole.GreyFoxRoleID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            greyFoxSettingCollection = new GreyFoxSettingCollection();

            while (r.Read())
            {
                GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1);

                // Fill Parent
                if (parentOffset != -1 && !r.IsDBNull(parentOffset))
                {
                    GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent, r, parentOffset, parentOffset + 1);

                    // Fill
                    if (parentParentOffset != -1 && !r.IsDBNull(parentParentOffset))
                    {
                        GreyFoxSettingManager.FillFromReader(greyFoxSetting.parent.Parent, r, parentParentOffset, parentParentOffset + 1);
                    }

                    // Fill
                    if (parentModifyRoleOffset != -1 && !r.IsDBNull(parentModifyRoleOffset))
                    {
                        GreyFoxRoleManager.FillFromReader(greyFoxSetting.parent.ModifyRole, r, parentModifyRoleOffset, parentModifyRoleOffset + 1);
                    }
                }

                // Fill ModifyRole
                if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1);
                }

                greyFoxSettingCollection.Add(greyFoxSetting);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            return(greyFoxSettingCollection);
        }
示例#30
0
        public GreyFoxSettingCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxSettingFlags[] optionFlags)
        {
            StringBuilder query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }
            foreach (string columnName in InnerJoinFields)
            {
                query.Append("sysGlobal_Settings.");
                query.Append(columnName);
                query.Append(",");
            }

            int innerJoinOffset  = InnerJoinFields.GetUpperBound(0) + 1;
            int modifyRoleOffset = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.ModifyRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("sysGlobal_Roles.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        modifyRoleOffset = innerJoinOffset;
                        innerJoinOffset  = modifyRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("sysGlobal_Settings");
            }
            else
            {
                query.Append(" FROM sysGlobal_Settings ");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case GreyFoxSettingFlags.ModifyRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles ON sysGlobal_Settings.ModifyRoleID = sysGlobal_Roles.GreyFoxRoleID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            OleDbConnection dbConnection = new OleDbConnection(connectionString);
            OleDbCommand    dbCommand    = new OleDbCommand(query.ToString(), dbConnection);

            dbConnection.Open();

                        #if DEBUG
            OleDbDataReader r;
            try
            {
                r = dbCommand.ExecuteReader();
            }
            catch (Exception e)
            {
                throw(new Exception(e.Message + " --- Query: " + query.ToString()));
            }
                        #else
            OleDbDataReader r = dbCommand.ExecuteReader();
                        #endif

            GreyFoxSettingCollection greyFoxSettingCollection = new GreyFoxSettingCollection();

            while (r.Read())
            {
                GreyFoxSetting greyFoxSetting = ParseFromReader(r, 0, 1);

                // Fill ModifyRole
                if (modifyRoleOffset != -1 && !r.IsDBNull(modifyRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(greyFoxSetting.modifyRole, r, modifyRoleOffset, modifyRoleOffset + 1);
                }

                greyFoxSettingCollection.Add(greyFoxSetting);
            }

            r.Close();
            dbConnection.Close();

            return(greyFoxSettingCollection);
        }