///<summary>Returns true if Update(FamAging,FamAging) 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(FamAging famAging, FamAging oldFamAging)
 {
     if (famAging.Bal_0_30 != oldFamAging.Bal_0_30)
     {
         return(true);
     }
     if (famAging.Bal_31_60 != oldFamAging.Bal_31_60)
     {
         return(true);
     }
     if (famAging.Bal_61_90 != oldFamAging.Bal_61_90)
     {
         return(true);
     }
     if (famAging.BalOver90 != oldFamAging.BalOver90)
     {
         return(true);
     }
     if (famAging.InsEst != oldFamAging.InsEst)
     {
         return(true);
     }
     if (famAging.BalTotal != oldFamAging.BalTotal)
     {
         return(true);
     }
     if (famAging.PayPlanDue != oldFamAging.PayPlanDue)
     {
         return(true);
     }
     return(false);
 }
        ///<summary>Inserts one FamAging into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(FamAging famAging, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                famAging.PatNum = ReplicationServers.GetKey("famaging", "PatNum");
            }
            string command = "INSERT INTO famaging (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PatNum,";
            }
            command += "Bal_0_30,Bal_31_60,Bal_61_90,BalOver90,InsEst,BalTotal,PayPlanDue) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(famAging.PatNum) + ",";
            }
            command +=
                "'" + POut.Double(famAging.Bal_0_30) + "',"
                + "'" + POut.Double(famAging.Bal_31_60) + "',"
                + "'" + POut.Double(famAging.Bal_61_90) + "',"
                + "'" + POut.Double(famAging.BalOver90) + "',"
                + "'" + POut.Double(famAging.InsEst) + "',"
                + "'" + POut.Double(famAging.BalTotal) + "',"
                + "'" + POut.Double(famAging.PayPlanDue) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                famAging.PatNum = Db.NonQ(command, true, "PatNum", "famAging");
            }
            return(famAging.PatNum);
        }
Exemple #3
0
 ///<summary>Inserts one FamAging into the database.  Returns the new priKey.</summary>
 public static long Insert(FamAging famAging)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         famAging.PatNum = DbHelper.GetNextOracleKey("famaging", "PatNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(famAging, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     famAging.PatNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(famAging, false));
     }
 }
        ///<summary>Updates one FamAging in the database.</summary>
        public static void Update(FamAging famAging)
        {
            string command = "UPDATE famaging SET "
                             + "Bal_0_30  = '" + POut.Double(famAging.Bal_0_30) + "', "
                             + "Bal_31_60 = '" + POut.Double(famAging.Bal_31_60) + "', "
                             + "Bal_61_90 = '" + POut.Double(famAging.Bal_61_90) + "', "
                             + "BalOver90 = '" + POut.Double(famAging.BalOver90) + "', "
                             + "InsEst    = '" + POut.Double(famAging.InsEst) + "', "
                             + "BalTotal  = '" + POut.Double(famAging.BalTotal) + "', "
                             + "PayPlanDue= '" + POut.Double(famAging.PayPlanDue) + "' "
                             + "WHERE PatNum = " + POut.Long(famAging.PatNum);

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

            foreach (DataRow row in table.Rows)
            {
                famAging            = new FamAging();
                famAging.PatNum     = PIn.Long(row["PatNum"].ToString());
                famAging.Bal_0_30   = PIn.Double(row["Bal_0_30"].ToString());
                famAging.Bal_31_60  = PIn.Double(row["Bal_31_60"].ToString());
                famAging.Bal_61_90  = PIn.Double(row["Bal_61_90"].ToString());
                famAging.BalOver90  = PIn.Double(row["BalOver90"].ToString());
                famAging.InsEst     = PIn.Double(row["InsEst"].ToString());
                famAging.BalTotal   = PIn.Double(row["BalTotal"].ToString());
                famAging.PayPlanDue = PIn.Double(row["PayPlanDue"].ToString());
                retVal.Add(famAging);
            }
            return(retVal);
        }
        ///<summary>Updates one FamAging 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(FamAging famAging, FamAging oldFamAging)
        {
            string command = "";

            if (famAging.Bal_0_30 != oldFamAging.Bal_0_30)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Bal_0_30 = '" + POut.Double(famAging.Bal_0_30) + "'";
            }
            if (famAging.Bal_31_60 != oldFamAging.Bal_31_60)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Bal_31_60 = '" + POut.Double(famAging.Bal_31_60) + "'";
            }
            if (famAging.Bal_61_90 != oldFamAging.Bal_61_90)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Bal_61_90 = '" + POut.Double(famAging.Bal_61_90) + "'";
            }
            if (famAging.BalOver90 != oldFamAging.BalOver90)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "BalOver90 = '" + POut.Double(famAging.BalOver90) + "'";
            }
            if (famAging.InsEst != oldFamAging.InsEst)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "InsEst = '" + POut.Double(famAging.InsEst) + "'";
            }
            if (famAging.BalTotal != oldFamAging.BalTotal)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "BalTotal = '" + POut.Double(famAging.BalTotal) + "'";
            }
            if (famAging.PayPlanDue != oldFamAging.PayPlanDue)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PayPlanDue = '" + POut.Double(famAging.PayPlanDue) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE famaging SET " + command
                      + " WHERE PatNum = " + POut.Long(famAging.PatNum);
            Db.NonQ(command);
            return(true);
        }
 ///<summary>Inserts one FamAging into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FamAging famAging)
 {
     return(InsertNoCache(famAging, false));
 }
 ///<summary>Inserts many FamAgings into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <FamAging> listFamAgings, bool useExistingPK)
 {
     if (!useExistingPK && PrefC.RandomKeys)
     {
         foreach (FamAging famAging in listFamAgings)
         {
             Insert(famAging);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         int           countRows  = 0;
         while (index < listFamAgings.Count)
         {
             FamAging      famAging = listFamAgings[index];
             StringBuilder sbRow    = new StringBuilder("(");
             bool          hasComma = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO famaging (");
                 if (useExistingPK)
                 {
                     sbCommands.Append("PatNum,");
                 }
                 sbCommands.Append("Bal_0_30,Bal_31_60,Bal_61_90,BalOver90,InsEst,BalTotal,PayPlanDue) VALUES ");
                 countRows = 0;
             }
             else
             {
                 hasComma = true;
             }
             if (useExistingPK)
             {
                 sbRow.Append(POut.Long(famAging.PatNum)); sbRow.Append(",");
             }
             sbRow.Append("'" + POut.Double(famAging.Bal_0_30) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.Bal_31_60) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.Bal_61_90) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.BalOver90) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.InsEst) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.BalTotal) + "'"); sbRow.Append(",");
             sbRow.Append("'" + POut.Double(famAging.PayPlanDue) + "'"); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount && countRows > 0)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 countRows++;
                 if (index == listFamAgings.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }