/// <summary>
        /// This is to update the reference number field of a given database table
        /// <param name="parameter">The RNParameter object that contains the first, second, and third reference numbers</param>
        /// <param name="strTableName">The table name that will receive the reference numbers</param>
        /// <param name="strKeyName">The field name of the primary key or any field of reference in the given database table</param>
        /// <param name="strKeyValue">The value of the primary key or any field of reference in the given database table</param>
        /// </summary>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="System.Exception"/>
        public void UpdateReference(RNParameters p, string strTableName, string strKeyName, string strKeyValue)
        {
            if (strTableName == null || strTableName.Length <= 0)
            {
                throw new ArgumentNullException();
            }
            if (strKeyName == null || strKeyName.Length <= 0)
            {
                throw new ArgumentNullException();
            }
            if (strKeyValue == null || strKeyValue.Length <= 0)
            {
                throw new ArgumentNullException();
            }
            try
            {
                string strUpdateReferenceNumber = "UPDATE " + strTableName + " SET FirstReference=@FirstReference, ";
                strUpdateReferenceNumber += "SecondReference=@SecondReference, ThirdReference=@ThirdReference) WHERE ";
                strUpdateReferenceNumber += strKeyName + "=@KeyValue";

                SqlParameter[] Parameter = {
                                               new SqlParameter("@FirstReference", p.FirstReference),
                                               new SqlParameter("@SecondReference", p.SecondReference),
                                               new SqlParameter("@ThirdReference", p.ThirdReference),
                                               new SqlParameter("@KeyValue", strKeyValue)
                                           };

                d.ExecuteNonQuery(strUpdateReferenceNumber, Parameter);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// This is to insert the reference number into a given database table
        /// <param name="parameter">The RNParameter object that contains the first, second, and third reference numbers</param>
        /// <param name="strTableName">The table name that will receive the reference numbers</param>
        /// </summary>
        /// <returns>The primary key of the created entry</returns>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="System.Exception"/>
        public int InsertReference(RNParameters parameter, string strTableName)
        {
            if (strTableName == null || strTableName.Length <= 0)
            {
                throw new ArgumentNullException();
            }
            try
            {
                string strSubmitReferenceNumber = "INSERT INTO " + strTableName + " (FirstReference, SecondReference, ThirdReference) ";
                strSubmitReferenceNumber += "VALUES (@FirstReference, @SecondReference, @ThirdReference)";

                SqlParameter[] Parameter = {
                                               new SqlParameter("@FirstReference", parameter.FirstReference),
                                               new SqlParameter("@SecondReference", parameter.SecondReference),
                                               new SqlParameter("@ThirdReference", parameter.ThirdReference)
                                           };

                return d.ReturnIndex(strSubmitReferenceNumber, Parameter);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// This is to determine if a reference number is unique in a given database table
        /// <param name="parameter">The RNParameter object that contains the first, second, and third reference numbers</param>
        /// <param name="strTableName">The table name that will receive the reference numbers</param>
        /// </summary>
        /// <returns>A boolean variable</returns>
        /// <exception cref="System.ArgumentNullException"/>
        /// <exception cref="System.Exception"/>
        public bool IsUniqueReference(RNParameters parameter, string strTableName)
        {
            if (strTableName == null || strTableName.Length <= 0)
            {
                throw new ArgumentNullException();
            }
            try
            {
                bool IsUniqueReference = false;
                string strIsUniqueReference = "SELECT FirstReference, SecondReference, ThirdReference FROM " + strTableName + " ";
                strIsUniqueReference += "WHERE FirstReference=@FirstReference OR SecondReference=@SecondReference OR ThirdReference=@ThirdReference";

                SqlParameter[] Parameter = {
                                               new SqlParameter("@FirstReference", parameter.FirstReference),
                                               new SqlParameter("@SecondReference", parameter.SecondReference),
                                               new SqlParameter("@ThirdReference", parameter.ThirdReference)
                                           };

                if (d.IsExisting(strIsUniqueReference, Parameter) == false)
                {
                    IsUniqueReference = true;
                }
                return IsUniqueReference;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 /// <summary>
 /// <para>This is to create a BPI reference number for over-the-counter payments. The algorithm is as follows:</para>
 /// <para>(aMMaa-bbDDb-ccccc) Three sets of five numeric characters, each separated by a dash.</para>
 /// <para>Let MM = current month, DD = current day, aMMaa = A, bbDDb = B, ccccc = C;</para>
 /// <para>Range:</para>
 /// <para>MM = 11-22; a1 = 1-4; a2,a3 = 0-9;</para>
 /// <para>DD = 14-44; b1 = 5-9; b2,b3 = 0-9;</para>
 /// <para>Formula:</para>
 /// <para>A /= B /= C;</para>
 /// <para>C = [(A + B) / 3] + 10003</para>
 /// </summary>
 /// <returns>An RNParameters object</returns>
 /// <exception cref="System.Exception"/>
 public RNParameters CreateReference()
 {
     try
     {
         Random r = new Random();
         RNParameters p = new RNParameters();
         int a1, a23, a4, a5, b1, b2, b34, b5;
         a1 = r.Next(1, 5);
         a23 = (Convert.ToInt32(DateTime.Now.Month)) + 10;
         a4 = r.Next(0, 10);
         a5 = r.Next(0, 10);
         b1 = r.Next(5, 10);
         b2 = r.Next(0, 10);
         b34 = (Convert.ToInt32(DateTime.Now.Day)) + 13;
         b5 = r.Next(0, 10);
         p.FirstReference = Convert.ToInt32(a1.ToString() + a23.ToString() + a4.ToString() + a5.ToString());
         p.SecondReference = Convert.ToInt32(b1.ToString() + b2.ToString() + b34.ToString() + b5.ToString());
         p.ThirdReference = (((p.FirstReference + p.SecondReference) / 3) + 10003);
         p.ReferenceNumber = p.FirstReference.ToString() + "-" + p.SecondReference.ToString() + "-" + p.ThirdReference.ToString();
         return p;
     }
     catch (Exception e)
     {
         throw e;
     }
 }