Exemple #1
0
        ///<summary>Updates one PhoneComp 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(PhoneComp phoneComp, PhoneComp oldPhoneComp)
        {
            string command = "";

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

            if (!useExistingPK && isRandomKeys)
            {
                phoneComp.PhoneCompNum = ReplicationServers.GetKeyNoCache("phonecomp", "PhoneCompNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "PhoneCompNum,";
            }
            command += "PhoneExt,ComputerName) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(phoneComp.PhoneCompNum) + ",";
            }
            command +=
                POut.Int(phoneComp.PhoneExt) + ","
                + "'" + POut.String(phoneComp.ComputerName) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                phoneComp.PhoneCompNum = Db.NonQ(command, true, "PhoneCompNum", "phoneComp");
            }
            return(phoneComp.PhoneCompNum);
        }
Exemple #4
0
        ///<summary>Inserts one PhoneComp into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(PhoneComp phoneComp, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                phoneComp.PhoneCompNum = ReplicationServers.GetKey("phonecomp", "PhoneCompNum");
            }
            string command = "INSERT INTO phonecomp (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PhoneCompNum,";
            }
            command += "PhoneExt,ComputerName) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(phoneComp.PhoneCompNum) + ",";
            }
            command +=
                POut.Int(phoneComp.PhoneExt) + ","
                + "'" + POut.String(phoneComp.ComputerName) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                phoneComp.PhoneCompNum = Db.NonQ(command, true, "PhoneCompNum", "phoneComp");
            }
            return(phoneComp.PhoneCompNum);
        }
Exemple #5
0
        ///<summary>Updates one PhoneComp in the database.</summary>
        public static void Update(PhoneComp phoneComp)
        {
            string command = "UPDATE phonecomp SET "
                             + "PhoneExt    =  " + POut.Int(phoneComp.PhoneExt) + ", "
                             + "ComputerName= '" + POut.String(phoneComp.ComputerName) + "' "
                             + "WHERE PhoneCompNum = " + POut.Long(phoneComp.PhoneCompNum);

            Db.NonQ(command);
        }
Exemple #6
0
 ///<summary>Returns true if Update(PhoneComp,PhoneComp) 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(PhoneComp phoneComp, PhoneComp oldPhoneComp)
 {
     if (phoneComp.PhoneExt != oldPhoneComp.PhoneExt)
     {
         return(true);
     }
     if (phoneComp.ComputerName != oldPhoneComp.ComputerName)
     {
         return(true);
     }
     return(false);
 }
Exemple #7
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <PhoneComp> TableToList(DataTable table)
        {
            List <PhoneComp> retVal = new List <PhoneComp>();
            PhoneComp        phoneComp;

            foreach (DataRow row in table.Rows)
            {
                phoneComp = new PhoneComp();
                phoneComp.PhoneCompNum = PIn.Long(row["PhoneCompNum"].ToString());
                phoneComp.PhoneExt     = PIn.Int(row["PhoneExt"].ToString());
                phoneComp.ComputerName = PIn.String(row["ComputerName"].ToString());
                retVal.Add(phoneComp);
            }
            return(retVal);
        }
Exemple #8
0
 ///<summary>Inserts one PhoneComp into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(PhoneComp phoneComp)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(phoneComp, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             phoneComp.PhoneCompNum = DbHelper.GetNextOracleKey("phonecomp", "PhoneCompNum");                  //Cacheless method
         }
         return(InsertNoCache(phoneComp, true));
     }
 }
 ///<summary>Inserts one PhoneComp into the database.  Returns the new priKey.</summary>
 public static long Insert(PhoneComp phoneComp)
 {
     return(Insert(phoneComp, false));
 }