///<summary>Updates one UserGroupAttach 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(UserGroupAttach userGroupAttach, UserGroupAttach oldUserGroupAttach)
        {
            string command = "";

            if (userGroupAttach.UserNum != oldUserGroupAttach.UserNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserNum = " + POut.Long(userGroupAttach.UserNum) + "";
            }
            if (userGroupAttach.UserGroupNum != oldUserGroupAttach.UserGroupNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserGroupNum = " + POut.Long(userGroupAttach.UserGroupNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE usergroupattach SET " + command
                      + " WHERE UserGroupAttachNum = " + POut.Long(userGroupAttach.UserGroupAttachNum);
            Db.NonQ(command);
            return(true);
        }
        ///<summary>Inserts one UserGroupAttach into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(UserGroupAttach userGroupAttach, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                userGroupAttach.UserGroupAttachNum = ReplicationServers.GetKey("usergroupattach", "UserGroupAttachNum");
            }
            string command = "INSERT INTO usergroupattach (";

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

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

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

            foreach (DataRow row in table.Rows)
            {
                userGroupAttach = new UserGroupAttach();
                userGroupAttach.UserGroupAttachNum = PIn.Long(row["UserGroupAttachNum"].ToString());
                userGroupAttach.UserNum            = PIn.Long(row["UserNum"].ToString());
                userGroupAttach.UserGroupNum       = PIn.Long(row["UserGroupNum"].ToString());
                retVal.Add(userGroupAttach);
            }
            return(retVal);
        }
Esempio n. 8
0
 ///<summary>Inserts one UserGroupAttach into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(UserGroupAttach userGroupAttach)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(userGroupAttach, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             userGroupAttach.UserGroupAttachNum = DbHelper.GetNextOracleKey("usergroupattach", "UserGroupAttachNum");                  //Cacheless method
         }
         return(InsertNoCache(userGroupAttach, true));
     }
 }
 ///<summary>Inserts one UserGroupAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(UserGroupAttach userGroupAttach)
 {
     return(Insert(userGroupAttach, false));
 }