Ejemplo n.º 1
0
        ///<summary>Inserts one TreatPlanAttach into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(TreatPlanAttach treatPlanAttach, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO treatplanattach (";

            if (!useExistingPK && isRandomKeys)
            {
                treatPlanAttach.TreatPlanAttachNum = ReplicationServers.GetKeyNoCache("treatplanattach", "TreatPlanAttachNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "TreatPlanAttachNum,";
            }
            command += "TreatPlanNum,ProcNum,Priority) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(treatPlanAttach.TreatPlanAttachNum) + ",";
            }
            command +=
                POut.Long(treatPlanAttach.TreatPlanNum) + ","
                + POut.Long(treatPlanAttach.ProcNum) + ","
                + POut.Long(treatPlanAttach.Priority) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                treatPlanAttach.TreatPlanAttachNum = Db.NonQ(command, true, "TreatPlanAttachNum", "treatPlanAttach");
            }
            return(treatPlanAttach.TreatPlanAttachNum);
        }
Ejemplo n.º 2
0
 ///<summary>Inserts one TreatPlanAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(TreatPlanAttach treatPlanAttach)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         treatPlanAttach.TreatPlanAttachNum = DbHelper.GetNextOracleKey("treatplanattach", "TreatPlanAttachNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(treatPlanAttach, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     treatPlanAttach.TreatPlanAttachNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(treatPlanAttach, false));
     }
 }
Ejemplo n.º 3
0
        ///<summary>Inserts one TreatPlanAttach into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(TreatPlanAttach treatPlanAttach, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                treatPlanAttach.TreatPlanAttachNum = ReplicationServers.GetKey("treatplanattach", "TreatPlanAttachNum");
            }
            string command = "INSERT INTO treatplanattach (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "TreatPlanAttachNum,";
            }
            command += "TreatPlanNum,ProcNum,Priority) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(treatPlanAttach.TreatPlanAttachNum) + ",";
            }
            command +=
                POut.Long(treatPlanAttach.TreatPlanNum) + ","
                + POut.Long(treatPlanAttach.ProcNum) + ","
                + POut.Long(treatPlanAttach.Priority) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                treatPlanAttach.TreatPlanAttachNum = Db.NonQ(command, true, "TreatPlanAttachNum", "treatPlanAttach");
            }
            return(treatPlanAttach.TreatPlanAttachNum);
        }
Ejemplo n.º 4
0
        ///<summary>Updates one TreatPlanAttach in the database.</summary>
        public static void Update(TreatPlanAttach treatPlanAttach)
        {
            string command = "UPDATE treatplanattach SET "
                             + "TreatPlanNum      =  " + POut.Long(treatPlanAttach.TreatPlanNum) + ", "
                             + "ProcNum           =  " + POut.Long(treatPlanAttach.ProcNum) + ", "
                             + "Priority          =  " + POut.Long(treatPlanAttach.Priority) + " "
                             + "WHERE TreatPlanAttachNum = " + POut.Long(treatPlanAttach.TreatPlanAttachNum);

            Db.NonQ(command);
        }
Ejemplo n.º 5
0
 ///<summary>Inserts one TreatPlanAttach into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(TreatPlanAttach treatPlanAttach)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(treatPlanAttach, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             treatPlanAttach.TreatPlanAttachNum = DbHelper.GetNextOracleKey("treatplanattach", "TreatPlanAttachNum");                  //Cacheless method
         }
         return(InsertNoCache(treatPlanAttach, true));
     }
 }
Ejemplo n.º 6
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <TreatPlanAttach> TableToList(DataTable table)
        {
            List <TreatPlanAttach> retVal = new List <TreatPlanAttach>();
            TreatPlanAttach        treatPlanAttach;

            foreach (DataRow row in table.Rows)
            {
                treatPlanAttach = new TreatPlanAttach();
                treatPlanAttach.TreatPlanAttachNum = PIn.Long(row["TreatPlanAttachNum"].ToString());
                treatPlanAttach.TreatPlanNum       = PIn.Long(row["TreatPlanNum"].ToString());
                treatPlanAttach.ProcNum            = PIn.Long(row["ProcNum"].ToString());
                treatPlanAttach.Priority           = PIn.Long(row["Priority"].ToString());
                retVal.Add(treatPlanAttach);
            }
            return(retVal);
        }
Ejemplo n.º 7
0
 ///<summary>Returns true if Update(TreatPlanAttach,TreatPlanAttach) 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(TreatPlanAttach treatPlanAttach, TreatPlanAttach oldTreatPlanAttach)
 {
     if (treatPlanAttach.TreatPlanNum != oldTreatPlanAttach.TreatPlanNum)
     {
         return(true);
     }
     if (treatPlanAttach.ProcNum != oldTreatPlanAttach.ProcNum)
     {
         return(true);
     }
     if (treatPlanAttach.Priority != oldTreatPlanAttach.Priority)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
        ///<summary>Updates one TreatPlanAttach 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(TreatPlanAttach treatPlanAttach, TreatPlanAttach oldTreatPlanAttach)
        {
            string command = "";

            if (treatPlanAttach.TreatPlanNum != oldTreatPlanAttach.TreatPlanNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "TreatPlanNum = " + POut.Long(treatPlanAttach.TreatPlanNum) + "";
            }
            if (treatPlanAttach.ProcNum != oldTreatPlanAttach.ProcNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ProcNum = " + POut.Long(treatPlanAttach.ProcNum) + "";
            }
            if (treatPlanAttach.Priority != oldTreatPlanAttach.Priority)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Priority = " + POut.Long(treatPlanAttach.Priority) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE treatplanattach SET " + command
                      + " WHERE TreatPlanAttachNum = " + POut.Long(treatPlanAttach.TreatPlanAttachNum);
            Db.NonQ(command);
            return(true);
        }
Ejemplo n.º 9
0
 ///<summary>Inserts one TreatPlanAttach into the database.  Returns the new priKey.</summary>
 public static long Insert(TreatPlanAttach treatPlanAttach)
 {
     return(Insert(treatPlanAttach, false));
 }