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

            CopyTo(dbContentRating, isolation);
            return(dbContentRating);
        }
Ejemplo n.º 2
0
        private static void fillParameters(Database database, DbCommand dbCommand, DbContentRating dbContentRating)
        {
            #region _system

            addParameter(database, dbCommand, "CreateDate", DbType.Date, dbContentRating.createDate);
            addParameter(database, dbCommand, "ModifyDate", DbType.Date, dbContentRating.modifyDate);

            #endregion

            #region General

            addParameter(database, dbCommand, "Name", DbType.String, dbContentRating.name);
            addParameter(database, dbCommand, "Description", DbType.String, dbContentRating.description);
            addParameter(database, dbCommand, "IconUrl", DbType.String, dbContentRating.iconUrl);
            if (dbContentRating.requiredRole == null)
            {
                addParameter(database, dbCommand, "RequiredRoleID", DbType.Int32, DBNull.Value);
            }
            else
            {
                addParameter(database, dbCommand, "RequiredRoleID", DbType.Int32, dbContentRating.requiredRole.ID);
            }

            #endregion
        }
Ejemplo n.º 3
0
        public static DbContentRating ParseFromReader(IDataReader r, int idOffset, int dataOffset)
        {
            DbContentRating dbContentRating = new DbContentRating();

            FillFromReader(dbContentRating, r, idOffset, dataOffset);
            return(dbContentRating);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Makes a deep copy of the current DbContentRating.
        /// </summary>
        /// <returns> A new DbContentRating object reflecting the cloned DbContentRating object.</returns>
        public DbContentRating Copy()
        {
            DbContentRating dbContentRating = new DbContentRating();

            CopyTo(dbContentRating);
            return(dbContentRating);
        }
Ejemplo n.º 5
0
        internal static int _update(DbContentRating dbContentRating)
        {
            Database  database;
            DbCommand dbCommand;

            // Set Modify Date to Now
            dbContentRating.ModifyDate = DateTime.Now.ToUniversalTime();

            database = DatabaseFactory.CreateDatabase();

            dbCommand = database.GetSqlStringCommand("UPDATE kitCms_Ratings SET CreateDate=@CreateDate," +
                                                     "ModifyDate=@ModifyDate," +
                                                     "Name=@Name," +
                                                     "Description=@Description," +
                                                     "IconUrl=@IconUrl," +
                                                     "RequiredRoleID=@RequiredRoleID WHERE DbContentRatingID=@DbContentRatingID;");

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

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

            return(dbContentRating.iD);
        }
Ejemplo n.º 6
0
        public bool Equals(DbContentRating dbContentRating)
        {
            if (dbContentRating == null)
            {
                return(false);
            }

            return(this.iD == dbContentRating.iD);
        }
Ejemplo n.º 7
0
        public static DbContentRating NewPlaceHolder(int iD)
        {
            DbContentRating dbContentRating = new DbContentRating();

            dbContentRating.iD            = iD;
            dbContentRating.isPlaceHolder = true;
            dbContentRating.isSynced      = true;
            return(dbContentRating);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Duplicates DbContentRating object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new DbContentRating object reflecting the replicated DbContentRating object.</returns>
        public DbContentRating Duplicate()
        {
            DbContentRating clonedDbContentRating = this.Clone();

            // Insert must be called after children are replicated!
            clonedDbContentRating.iD       = DbContentRatingManager._insert(clonedDbContentRating);
            clonedDbContentRating.isSynced = true;
            return(clonedDbContentRating);
        }
Ejemplo n.º 9
0
        public void Remove(DbContentRating value)
        {
            OnCollectionChanged(EventArgs.Empty);
            int index = IndexOf(value);

            if (index == -1)
            {
                throw(new Exception("DbContentRating not found in collection."));
            }
            RemoveAt(index);
        }
Ejemplo n.º 10
0
 public int IndexOf(DbContentRating value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (DbContentRatingArray[x].Equals(value))
             {
                 return(x);
             }
         }
         return(-1);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Fills the {0} from a OleIDataReader.
        /// </summary>
        public static void FillFromReader(DbContentRating dbContentRating, IDataReader r, int idOffset, int dataOffset)
        {
            dbContentRating.iD            = r.GetInt32(idOffset);
            dbContentRating.isSynced      = true;
            dbContentRating.isPlaceHolder = false;

            dbContentRating.createDate  = r.GetDateTime(0 + dataOffset);
            dbContentRating.modifyDate  = r.GetDateTime(1 + dataOffset);
            dbContentRating.name        = r.GetString(2 + dataOffset);
            dbContentRating.description = r.GetString(3 + dataOffset);
            dbContentRating.iconUrl     = r.GetString(4 + dataOffset);
            if (!r.IsDBNull(5 + dataOffset) && r.GetInt32(5 + dataOffset) > 0)
            {
                dbContentRating.requiredRole = GreyFoxRole.NewPlaceHolder(r.GetInt32(5 + dataOffset));
            }
        }
Ejemplo n.º 12
0
 public int Add(DbContentRating value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > DbContentRatingArray.GetUpperBound(0) + 1)
         {
             DbContentRating[] tempDbContentRatingArray = new DbContentRating[count * 2];
             Array.Copy(DbContentRatingArray, tempDbContentRatingArray, count - 1);
             DbContentRatingArray = tempDbContentRatingArray;
         }
         DbContentRatingArray[count - 1] = value;
     }
     return(count - 1);
 }
Ejemplo n.º 13
0
        internal static bool _fill(DbContentRating dbContentRating)
        {
            // Clone item from cache.
            if (cacheEnabled)
            {
                object cachedObject = cacheFind(dbContentRating.iD);
                if (cachedObject != null)
                {
                    ((DbContentRating)cachedObject).CopyTo(dbContentRating, true);
                    return(dbContentRating.isSynced);
                }
            }

            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;

            query = new StringBuilder("SELECT ");
            query.Append(string.Join(",", InnerJoinFields));
            query.Append(" FROM kitCms_Ratings WHERE DbContentRatingID=");
            query.Append(dbContentRating.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 DbContentRatingID '{0}'.",
                                                  dbContentRating.iD)));
            }

            FillFromReader(dbContentRating, r, 0, 1);

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

            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Inserts a DbContentRating 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="_DbContentRating">The DbContentRating to insert into the database.</param>
        internal static int _insert(DbContentRating dbContentRating)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            // Set Create Date to Now
            dbContentRating.CreateDate = DateTime.Now.ToUniversalTime();

            // Set Modify Date to Now
            dbContentRating.ModifyDate = DateTime.Now.ToUniversalTime();

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitCms_Ratings" +
                    "(," +
                    "CreateDate," +
                    "ModifyDate," +
                    "Name," +
                    "Description," +
                    "IconUrl," +
                    "RequiredRoleID) VALUES (," +
                    "@CreateDate," +
                    "@ModifyDate," +
                    "@Name," +
                    "@Description," +
                    "@IconUrl," +
                    "@RequiredRoleID);";

            dbCommand = database.GetSqlStringCommand(query);
            fillParameters(database, dbCommand, dbContentRating);
            database.ExecuteNonQuery(dbCommand);
            dbCommand = database.GetSqlStringCommand("SELECT @@IDENTITY AS IDVal");
            id        = (int)database.ExecuteScalar(dbCommand);
            // Store dbContentRating in cache.
            if (cacheEnabled)
            {
                cacheStore(dbContentRating);
            }
            return(id);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Clones DbContentRating object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new DbContentRating object reflecting the replicated DbContentRating object.</returns>
        public DbContentRating Clone()
        {
            DbContentRating clonedDbContentRating = new DbContentRating();

            clonedDbContentRating.iD          = iD;
            clonedDbContentRating.isSynced    = isSynced;
            clonedDbContentRating.createDate  = createDate;
            clonedDbContentRating.modifyDate  = modifyDate;
            clonedDbContentRating.name        = name;
            clonedDbContentRating.description = description;
            clonedDbContentRating.iconUrl     = iconUrl;


            if (requiredRole != null)
            {
                clonedDbContentRating.requiredRole = requiredRole;
            }

            return(clonedDbContentRating);
        }
Ejemplo n.º 16
0
 public void Insert(int index, DbContentRating value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > DbContentRatingArray.GetUpperBound(0) + 1)
         {
             DbContentRating[] tempDbContentRatingArray = new DbContentRating[count * 2];
             Array.Copy(DbContentRatingArray, tempDbContentRatingArray, count - 1);
             DbContentRatingArray = tempDbContentRatingArray;
         }
         for (int x = index + 1; x == count - 2; x++)
         {
             DbContentRatingArray[x] = DbContentRatingArray[x - 1];
         }
         DbContentRatingArray[index] = value;
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Deep copies the current DbContentRating to another instance of DbContentRating.
        /// </summary>
        /// <param name="DbContentRating">The DbContentRating to copy to.</param>
        /// <param name="isolation">Placeholders are used to isolate the DbContentRating from its children.</param>
        public void CopyTo(DbContentRating dbContentRating, bool isolation)
        {
            dbContentRating.iD            = iD;
            dbContentRating.isPlaceHolder = isPlaceHolder;
            dbContentRating.isSynced      = isSynced;
            dbContentRating.createDate    = createDate;
            dbContentRating.modifyDate    = modifyDate;
            dbContentRating.name          = name;
            dbContentRating.description   = description;
            dbContentRating.iconUrl       = iconUrl;

            if (requiredRole != null)
            {
                if (isolation)
                {
                    dbContentRating.requiredRole = requiredRole.NewPlaceHolder();
                }
                else
                {
                    dbContentRating.requiredRole = requiredRole.Copy(false);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Inserts a DbContentRating 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="_DbContentRating">The DbContentRating to insert into the database.</param>
        internal static int _insert(DbContentRating dbContentRating)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            // Set Create Date to Now
            dbContentRating.CreateDate = DateTime.Now.ToUniversalTime();

            // Set Modify Date to Now
            dbContentRating.ModifyDate = DateTime.Now.ToUniversalTime();

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitCms_Ratings " +
                    "(" +
                    "CreateDate," +
                    "ModifyDate," +
                    "Name," +
                    "Description," +
                    "IconUrl," +
                    "RequiredRoleID) VALUES (" +
                    "@CreateDate," +
                    "@ModifyDate," +
                    "@Name," +
                    "@Description," +
                    "@IconUrl," +
                    "@RequiredRoleID);";

            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, dbContentRating);
                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, dbContentRating);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }
            // Store dbContentRating in cache.
            if (cacheEnabled)
            {
                cacheStore(dbContentRating);
            }
            return(id);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Deep copies the current DbContentRating to another instance of DbContentRating.
 /// This method does not provide isolated copies; use overriden method for this feature.
 /// </summary>
 /// <param name="DbContentRating">The DbContentRating to copy to.</param>
 public void CopyTo(DbContentRating dbContentRating)
 {
     CopyTo(dbContentRating, false);
 }
Ejemplo n.º 20
0
 public bool Contains(DbContentRating value)
 {
     return(IndexOf(value) != -1);
 }
Ejemplo n.º 21
0
        private static void cacheStore(DbContentRating dbContentRating)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add("kitCms_Ratings_" + dbContentRating.iD.ToString(), dbContentRating);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Compares the object's ID to another object's ID.
        /// </summary>
        int IComparable.CompareTo(object obj)
        {
            DbContentRating dbContentRating = (DbContentRating)obj;

            return(this.iD - dbContentRating.iD);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(DbContentRating dbContentRating)
 {
     return(this.iD - dbContentRating.iD);
 }
Ejemplo n.º 24
0
        public DbContentRatingCollection GetCollection(int topCount, string whereClause, string sortClause, params DbContentRatingFlags[] optionFlags)
        {
            StringBuilder             query;
            Database                  database;
            DbCommand                 dbCommand;
            IDataReader               r;
            DbContentRatingCollection dbContentRatingCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

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

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

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

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DbContentRatingFlags.RequiredRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequiredRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requiredRoleOffset = innerJoinOffset;
                        innerJoinOffset    = requiredRoleOffset + 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("kitCms_Ratings AS DbContentRating");
            }
            else
            {
                query.Append(" FROM kitCms_Ratings AS DbContentRating");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DbContentRatingFlags.RequiredRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS RequiredRole ON DbContentRating.RequiredRoleID = RequiredRole.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

            dbContentRatingCollection = new DbContentRatingCollection();

            while (r.Read())
            {
                DbContentRating dbContentRating = ParseFromReader(r, 0, 1);

                // Fill RequiredRole
                if (requiredRoleOffset != -1 && !r.IsDBNull(requiredRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(dbContentRating.requiredRole, r, requiredRoleOffset, requiredRoleOffset + 1);
                }

                dbContentRatingCollection.Add(dbContentRating);
            }

            return(dbContentRatingCollection);
        }
Ejemplo n.º 25
0
        private static void cacheStore(DbContentRating dbContentRating)
        {
            CacheManager cache = CacheFactory.GetCacheManager("DbContentRating");

            cache.Add(dbContentRating.iD.ToString(), dbContentRating);
        }