예제 #1
0
        ///<summary>Updates one AlertRead in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(AlertRead alertRead, AlertRead oldAlertRead)
        {
            string command = "";

            if (alertRead.AlertItemNum != oldAlertRead.AlertItemNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AlertItemNum = " + POut.Long(alertRead.AlertItemNum) + "";
            }
            if (alertRead.UserNum != oldAlertRead.UserNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserNum = " + POut.Long(alertRead.UserNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE alertread SET " + command
                      + " WHERE AlertReadNum = " + POut.Long(alertRead.AlertReadNum);
            Db.NonQ(command);
            return(true);
        }
예제 #2
0
 ///<summary>Inserts one AlertRead into the database.  Returns the new priKey.</summary>
 public static long Insert(AlertRead alertRead)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         alertRead.AlertReadNum = DbHelper.GetNextOracleKey("alertread", "AlertReadNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(alertRead, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     alertRead.AlertReadNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(alertRead, false));
     }
 }
예제 #3
0
        ///<summary>Inserts one AlertRead into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(AlertRead alertRead, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO alertread (";

            if (!useExistingPK && isRandomKeys)
            {
                alertRead.AlertReadNum = ReplicationServers.GetKeyNoCache("alertread", "AlertReadNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "AlertReadNum,";
            }
            command += "AlertItemNum,UserNum) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(alertRead.AlertReadNum) + ",";
            }
            command +=
                POut.Long(alertRead.AlertItemNum) + ","
                + POut.Long(alertRead.UserNum) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                alertRead.AlertReadNum = Db.NonQ(command, true, "AlertReadNum", "alertRead");
            }
            return(alertRead.AlertReadNum);
        }
예제 #4
0
        ///<summary>Inserts one AlertRead into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(AlertRead alertRead, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                alertRead.AlertReadNum = ReplicationServers.GetKey("alertread", "AlertReadNum");
            }
            string command = "INSERT INTO alertread (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "AlertReadNum,";
            }
            command += "AlertItemNum,UserNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(alertRead.AlertReadNum) + ",";
            }
            command +=
                POut.Long(alertRead.AlertItemNum) + ","
                + POut.Long(alertRead.UserNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                alertRead.AlertReadNum = Db.NonQ(command, true, "AlertReadNum", "alertRead");
            }
            return(alertRead.AlertReadNum);
        }
예제 #5
0
        ///<summary>Updates one AlertRead in the database.</summary>
        public static void Update(AlertRead alertRead)
        {
            string command = "UPDATE alertread SET "
                             + "AlertItemNum=  " + POut.Long(alertRead.AlertItemNum) + ", "
                             + "UserNum     =  " + POut.Long(alertRead.UserNum) + " "
                             + "WHERE AlertReadNum = " + POut.Long(alertRead.AlertReadNum);

            Db.NonQ(command);
        }
예제 #6
0
 ///<summary>Returns true if Update(AlertRead,AlertRead) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(AlertRead alertRead, AlertRead oldAlertRead)
 {
     if (alertRead.AlertItemNum != oldAlertRead.AlertItemNum)
     {
         return(true);
     }
     if (alertRead.UserNum != oldAlertRead.UserNum)
     {
         return(true);
     }
     return(false);
 }
예제 #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AlertRead> TableToList(DataTable table)
        {
            List <AlertRead> retVal = new List <AlertRead>();
            AlertRead        alertRead;

            foreach (DataRow row in table.Rows)
            {
                alertRead = new AlertRead();
                alertRead.AlertReadNum = PIn.Long(row["AlertReadNum"].ToString());
                alertRead.AlertItemNum = PIn.Long(row["AlertItemNum"].ToString());
                alertRead.UserNum      = PIn.Long(row["UserNum"].ToString());
                retVal.Add(alertRead);
            }
            return(retVal);
        }
예제 #8
0
 ///<summary>Inserts one AlertRead into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AlertRead alertRead)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(alertRead, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             alertRead.AlertReadNum = DbHelper.GetNextOracleKey("alertread", "AlertReadNum");                  //Cacheless method
         }
         return(InsertNoCache(alertRead, true));
     }
 }
예제 #9
0
 ///<summary>Inserts one AlertRead into the database.  Returns the new priKey.</summary>
 public static long Insert(AlertRead alertRead)
 {
     return(Insert(alertRead, false));
 }