///<summary>Updates one PatRestriction 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(PatRestriction patRestriction, PatRestriction oldPatRestriction)
        {
            string command = "";

            if (patRestriction.PatNum != oldPatRestriction.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(patRestriction.PatNum) + "";
            }
            if (patRestriction.PatRestrictType != oldPatRestriction.PatRestrictType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatRestrictType = " + POut.Int((int)patRestriction.PatRestrictType) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE patrestriction SET " + command
                      + " WHERE PatRestrictionNum = " + POut.Long(patRestriction.PatRestrictionNum);
            Db.NonQ(command);
            return(true);
        }
        ///<summary>Inserts one PatRestriction into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(PatRestriction patRestriction, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                patRestriction.PatRestrictionNum = ReplicationServers.GetKey("patrestriction", "PatRestrictionNum");
            }
            string command = "INSERT INTO patrestriction (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PatRestrictionNum,";
            }
            command += "PatNum,PatRestrictType) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(patRestriction.PatRestrictionNum) + ",";
            }
            command +=
                POut.Long(patRestriction.PatNum) + ","
                + POut.Int((int)patRestriction.PatRestrictType) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                patRestriction.PatRestrictionNum = Db.NonQ(command, true, "PatRestrictionNum", "patRestriction");
            }
            return(patRestriction.PatRestrictionNum);
        }
        ///<summary>Inserts one PatRestriction into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(PatRestriction patRestriction, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO patrestriction (";

            if (!useExistingPK && isRandomKeys)
            {
                patRestriction.PatRestrictionNum = ReplicationServers.GetKeyNoCache("patrestriction", "PatRestrictionNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "PatRestrictionNum,";
            }
            command += "PatNum,PatRestrictType) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(patRestriction.PatRestrictionNum) + ",";
            }
            command +=
                POut.Long(patRestriction.PatNum) + ","
                + POut.Int((int)patRestriction.PatRestrictType) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                patRestriction.PatRestrictionNum = Db.NonQ(command, true, "PatRestrictionNum", "patRestriction");
            }
            return(patRestriction.PatRestrictionNum);
        }
示例#4
0
 ///<summary>Inserts one PatRestriction into the database.  Returns the new priKey.</summary>
 public static long Insert(PatRestriction patRestriction)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         patRestriction.PatRestrictionNum = DbHelper.GetNextOracleKey("patrestriction", "PatRestrictionNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(patRestriction, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     patRestriction.PatRestrictionNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(patRestriction, false));
     }
 }
        ///<summary>Updates one PatRestriction in the database.</summary>
        public static void Update(PatRestriction patRestriction)
        {
            string command = "UPDATE patrestriction SET "
                             + "PatNum           =  " + POut.Long(patRestriction.PatNum) + ", "
                             + "PatRestrictType  =  " + POut.Int((int)patRestriction.PatRestrictType) + " "
                             + "WHERE PatRestrictionNum = " + POut.Long(patRestriction.PatRestrictionNum);

            Db.NonQ(command);
        }
 ///<summary>Returns true if Update(PatRestriction,PatRestriction) 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(PatRestriction patRestriction, PatRestriction oldPatRestriction)
 {
     if (patRestriction.PatNum != oldPatRestriction.PatNum)
     {
         return(true);
     }
     if (patRestriction.PatRestrictType != oldPatRestriction.PatRestrictType)
     {
         return(true);
     }
     return(false);
 }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <PatRestriction> TableToList(DataTable table)
        {
            List <PatRestriction> retVal = new List <PatRestriction>();
            PatRestriction        patRestriction;

            foreach (DataRow row in table.Rows)
            {
                patRestriction = new PatRestriction();
                patRestriction.PatRestrictionNum = PIn.Long(row["PatRestrictionNum"].ToString());
                patRestriction.PatNum            = PIn.Long(row["PatNum"].ToString());
                patRestriction.PatRestrictType   = (OpenDentBusiness.PatRestrict)PIn.Int(row["PatRestrictType"].ToString());
                retVal.Add(patRestriction);
            }
            return(retVal);
        }
示例#8
0
 ///<summary>Inserts one PatRestriction into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(PatRestriction patRestriction)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(patRestriction, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             patRestriction.PatRestrictionNum = DbHelper.GetNextOracleKey("patrestriction", "PatRestrictionNum");                  //Cacheless method
         }
         return(InsertNoCache(patRestriction, true));
     }
 }
 ///<summary>Inserts one PatRestriction into the database.  Returns the new priKey.</summary>
 public static long Insert(PatRestriction patRestriction)
 {
     return(Insert(patRestriction, false));
 }