Example #1
0
        internal static bool _fill(DbContentComment dbContentComment)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;

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

            FillFromReader(dbContentComment, r, 0, 1);

            return(true);
        }
Example #2
0
        internal static int _update(DbContentComment dbContentComment)
        {
            Database  database;
            DbCommand dbCommand;

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

            database = DatabaseFactory.CreateDatabase();

            dbCommand = database.GetSqlStringCommand("UPDATE kitCms_Comments SET CreateDate=@CreateDate," +
                                                     "ModifyDate=@ModifyDate," +
                                                     "Name=@Name," +
                                                     "Email=@Email," +
                                                     "Url=@Url," +
                                                     "IP=@IP," +
                                                     "Body=@Body WHERE DbContentCommentID=@DbContentCommentID;");

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

            return(dbContentComment.iD);
        }
Example #3
0
        public static DbContentComment ParseFromReader(IDataReader r, int idOffset, int dataOffset)
        {
            DbContentComment dbContentComment = new DbContentComment();

            FillFromReader(dbContentComment, r, idOffset, dataOffset);
            return(dbContentComment);
        }
Example #4
0
        /// <summary>
        /// Makes a deep copy of the current DbContentComment.
        /// </summary>
        /// <returns> A new DbContentComment object reflecting the cloned DbContentComment object.</returns>
        /// <param name="isolation">Placeholders are used to isolate the DbContentComment from its children.</param>
        public DbContentComment Copy(bool isolation)
        {
            DbContentComment dbContentComment = new DbContentComment();

            CopyTo(dbContentComment, isolation);
            return(dbContentComment);
        }
Example #5
0
        /// <summary>
        /// Makes a deep copy of the current DbContentComment.
        /// </summary>
        /// <returns> A new DbContentComment object reflecting the cloned DbContentComment object.</returns>
        public DbContentComment Copy()
        {
            DbContentComment dbContentComment = new DbContentComment();

            CopyTo(dbContentComment);
            return(dbContentComment);
        }
Example #6
0
        /// <summary>
        /// Inserts a DbContentComment 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="_DbContentComment">The DbContentComment to insert into the database.</param>
        internal static int _insert(DbContentComment dbContentComment)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

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

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

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitCms_Comments " +
                    "(" +
                    "CreateDate," +
                    "ModifyDate," +
                    "Name," +
                    "Email," +
                    "Url," +
                    "IP," +
                    "Body) VALUES (" +
                    "@CreateDate," +
                    "@ModifyDate," +
                    "@Name," +
                    "@Email," +
                    "@Url," +
                    "@IP," +
                    "@Body);";

            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, dbContentComment);
                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, dbContentComment);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }
            return(id);
        }
Example #7
0
        public bool Equals(DbContentComment dbContentComment)
        {
            if (dbContentComment == null)
            {
                return(false);
            }

            return(this.iD == dbContentComment.iD);
        }
Example #8
0
        public static DbContentComment NewPlaceHolder(int iD)
        {
            DbContentComment dbContentComment = new DbContentComment();

            dbContentComment.iD            = iD;
            dbContentComment.isPlaceHolder = true;
            dbContentComment.isSynced      = true;
            return(dbContentComment);
        }
Example #9
0
        /// <summary>
        /// Duplicates DbContentComment object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new DbContentComment object reflecting the replicated DbContentComment object.</returns>
        public DbContentComment Duplicate()
        {
            DbContentComment clonedDbContentComment = this.Clone();

            // Insert must be called after children are replicated!
            clonedDbContentComment.iD       = DbContentCommentManager._insert(clonedDbContentComment);
            clonedDbContentComment.isSynced = true;
            return(clonedDbContentComment);
        }
Example #10
0
        public void Remove(DbContentComment value)
        {
            OnCollectionChanged(EventArgs.Empty);
            int index = IndexOf(value);

            if (index == -1)
            {
                throw(new Exception("DbContentComment not found in collection."));
            }
            RemoveAt(index);
        }
Example #11
0
 /// <summary>
 /// Deep copies the current DbContentComment to another instance of DbContentComment.
 /// </summary>
 /// <param name="DbContentComment">The DbContentComment to copy to.</param>
 /// <param name="isolation">Placeholders are used to isolate the DbContentComment from its children.</param>
 public void CopyTo(DbContentComment dbContentComment, bool isolation)
 {
     dbContentComment.iD            = iD;
     dbContentComment.isPlaceHolder = isPlaceHolder;
     dbContentComment.isSynced      = isSynced;
     dbContentComment.createDate    = createDate;
     dbContentComment.modifyDate    = modifyDate;
     dbContentComment.name          = name;
     dbContentComment.email         = email;
     dbContentComment.url           = url;
     dbContentComment.iP            = iP;
     dbContentComment.body          = body;
 }
Example #12
0
        /// <summary>
        /// Fills the {0} from a OleIDataReader.
        /// </summary>
        public static void FillFromReader(DbContentComment dbContentComment, IDataReader r, int idOffset, int dataOffset)
        {
            dbContentComment.iD            = r.GetInt32(idOffset);
            dbContentComment.isSynced      = true;
            dbContentComment.isPlaceHolder = false;

            dbContentComment.createDate = r.GetDateTime(0 + dataOffset);
            dbContentComment.modifyDate = r.GetDateTime(1 + dataOffset);
            dbContentComment.name       = r.GetString(2 + dataOffset);
            dbContentComment.email      = r.GetString(3 + dataOffset);
            dbContentComment.url        = r.GetString(4 + dataOffset);
            dbContentComment.iP         = r.GetString(5 + dataOffset);
            dbContentComment.body       = r.GetString(6 + dataOffset);
        }
Example #13
0
 public int IndexOf(DbContentComment value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (DbContentCommentArray[x].Equals(value))
             {
                 return(x);
             }
         }
         return(-1);
     }
 }
Example #14
0
        /// <summary>
        /// Clones DbContentComment object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new DbContentComment object reflecting the replicated DbContentComment object.</returns>
        public DbContentComment Clone()
        {
            DbContentComment clonedDbContentComment = new DbContentComment();

            clonedDbContentComment.iD         = iD;
            clonedDbContentComment.isSynced   = isSynced;
            clonedDbContentComment.createDate = createDate;
            clonedDbContentComment.modifyDate = modifyDate;
            clonedDbContentComment.name       = name;
            clonedDbContentComment.email      = email;
            clonedDbContentComment.url        = url;
            clonedDbContentComment.iP         = iP;
            clonedDbContentComment.body       = body;


            return(clonedDbContentComment);
        }
Example #15
0
 public int Add(DbContentComment value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > DbContentCommentArray.GetUpperBound(0) + 1)
         {
             DbContentComment[] tempDbContentCommentArray = new DbContentComment[count * 2];
             Array.Copy(DbContentCommentArray, tempDbContentCommentArray, count - 1);
             DbContentCommentArray = tempDbContentCommentArray;
         }
         DbContentCommentArray[count - 1] = value;
     }
     return(count - 1);
 }
Example #16
0
        private static void fillParameters(Database database, DbCommand dbCommand, DbContentComment dbContentComment)
        {
            #region _system

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

            #endregion

            #region New Folder

            addParameter(database, dbCommand, "Name", DbType.String, dbContentComment.name);
            addParameter(database, dbCommand, "Email", DbType.String, dbContentComment.email);
            addParameter(database, dbCommand, "Url", DbType.String, dbContentComment.url);
            addParameter(database, dbCommand, "IP", DbType.String, dbContentComment.iP);
            addParameter(database, dbCommand, "Body", DbType.String, dbContentComment.body);

            #endregion
        }
Example #17
0
 public void Insert(int index, DbContentComment value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > DbContentCommentArray.GetUpperBound(0) + 1)
         {
             DbContentComment[] tempDbContentCommentArray = new DbContentComment[count * 2];
             Array.Copy(DbContentCommentArray, tempDbContentCommentArray, count - 1);
             DbContentCommentArray = tempDbContentCommentArray;
         }
         for (int x = index + 1; x == count - 2; x++)
         {
             DbContentCommentArray[x] = DbContentCommentArray[x - 1];
         }
         DbContentCommentArray[index] = value;
     }
 }
Example #18
0
        /// <summary>
        /// Inserts a DbContentComment 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="_DbContentComment">The DbContentComment to insert into the database.</param>
        internal static int _insert(DbContentComment dbContentComment)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

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

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

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitCms_Comments" +
                    "(," +
                    "CreateDate," +
                    "ModifyDate," +
                    "Name," +
                    "Email," +
                    "Url," +
                    "IP," +
                    "Body) VALUES (," +
                    "@CreateDate," +
                    "@ModifyDate," +
                    "@Name," +
                    "@Email," +
                    "@Url," +
                    "@IP," +
                    "@Body);";

            dbCommand = database.GetSqlStringCommand(query);
            fillParameters(database, dbCommand, dbContentComment);
            database.ExecuteNonQuery(dbCommand);
            dbCommand = database.GetSqlStringCommand("SELECT @@IDENTITY AS IDVal");
            id        = (int)database.ExecuteScalar(dbCommand);
            return(id);
        }
Example #19
0
 /// <summary>
 /// Deep copies the current DbContentComment to another instance of DbContentComment.
 /// This method does not provide isolated copies; use overriden method for this feature.
 /// </summary>
 /// <param name="DbContentComment">The DbContentComment to copy to.</param>
 public void CopyTo(DbContentComment dbContentComment)
 {
     CopyTo(dbContentComment, false);
 }
Example #20
0
        public DbContentCommentCollection GetCollection(int topCount, string whereClause, string sortClause)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;
            DbContentCommentCollection dbContentCommentCollection;


            query = new StringBuilder("SELECT ");

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

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

            //
            // Remove trailing comma
            //
            query.Length--;
            query.Append(" FROM kitCms_Comments AS DbContentComment");
            //
            // 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

            dbContentCommentCollection = new DbContentCommentCollection();

            while (r.Read())
            {
                DbContentComment dbContentComment = ParseFromReader(r, 0, 1);

                dbContentCommentCollection.Add(dbContentComment);
            }

            return(dbContentCommentCollection);
        }
Example #21
0
        /// <summary>
        /// Compares the object's ID to another object's ID.
        /// </summary>
        int IComparable.CompareTo(object obj)
        {
            DbContentComment dbContentComment = (DbContentComment)obj;

            return(this.iD - dbContentComment.iD);
        }
Example #22
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(DbContentComment dbContentComment)
 {
     return(this.iD - dbContentComment.iD);
 }
Example #23
0
 public bool Contains(DbContentComment value)
 {
     return(IndexOf(value) != -1);
 }