Example #1
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);
            }
        }
Example #2
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);
        }
Example #3
0
        public static GreyFoxSettingCollection GetSettings(string parentKey)
        {
            GreyFoxSettingManager settingManager =
                new GreyFoxSettingManager();
            GreyFoxSettingCollection settingCollection =
                settingManager.GetCollection("GreyFoxSetting.Name='" +
                                             parentKey + "'", "GreyFoxSetting.Name", GreyFoxSettingFlags.Parent);

            return(settingCollection);
        }
Example #4
0
        /// <summary>
        /// Ensures that the object's fields and children are
        /// pre-loaded before any updates or reads.
        /// </summary>
        public void EnsurePreLoad()
        {
            if (!isPlaceHolder)
            {
                return;
            }

            GreyFoxSettingManager._fill(this);
            isPlaceHolder = false;
        }
Example #5
0
        /// <summary>
        /// Saves the GreyFoxSetting object state to the database.
        /// </summary>
        public int Save()
        {
            if (isSynced)
            {
                return(iD);
            }

            if (iD == -1)
            {
                throw (new Exception("Invalid record; cannot be saved."));
            }
            if (iD == 0)
            {
                iD = GreyFoxSettingManager._insert(this);
            }
            else
            {
                GreyFoxSettingManager._update(this);
            }
            isSynced = iD != -1;
            return(iD);
        }
Example #6
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);
        }
Example #7
0
 /// <summary>
 /// Overwrites and existing GreyFoxSetting object in the database.
 /// </summary>
 public void Overwrite(int id)
 {
     iD = id;
     GreyFoxSettingManager._update(this);
     isSynced = true;
 }
Example #8
0
 public void Delete()
 {
     GreyFoxSettingManager._delete(this.iD);
 }
Example #9
0
 public GreyFoxSetting(int id)
 {
     this.iD  = id;
     isSynced = GreyFoxSettingManager._fill(this);
 }
Example #10
0
 public void Delete()
 {
     GreyFoxSettingManager._delete(this.iD);
     this.iD  = 0;
     isSynced = false;
 }