/// <summary>
        /// Adds the passed Parameter Key (Name) and Value to the Parameter Table.
        /// </summary>
        /// <param name="parameterName">
        /// The Name (Key) of the parameter.  Will be used to find the Parameter Value in the Parameter Table.
        /// </param>
        /// <param name="parameterValue">
        /// The Value that is to be stored for the passed Parameter Key.
        /// </param>
        /// <param name="parameterEncrypted">
        /// Boolean indicator of the whether or not the Parameter Value should be encrypted in the Parameter Table.
        /// IF the value is set to "TRUE", the value will be encrypted.
        /// </param>
        /// <returns>
        /// TRUE - If the Parameter Key and Value pair was successfully added to the Parameter Table.
        /// FALSE - If the Parameter Key and Value pair was NOT successfully added to the Parameter Table. 
        /// </returns>
        public bool WriteParameter(string parameterName, string parameterValue, bool parameterEncrypted)
        {
            EncryptionManager encryptionManager     = null;
              string            insertValue           = null;
              string            sqlStatement          = null;
              SqlCommand        parameterWriteCommand = null;
              int               rowsAffected          = -9999;

              try
              {
            //  Make sure a Valid Parameter Name was passed to this routine.  If not, exit.
            if (parameterName.Length == 0)
            {
              //  Return a "FALSE" to the calling routine to indicate that this process failed.
              return false;
            }

            //  If the Parameter Value is to be encrypted, encrypt it.
            if (parameterEncrypted)
            {
              //  Instantiate an Encryption Manager Class.
              encryptionManager = new EncryptionManager();

              //  Encrypt the Parameter Value and set the encrypted string to be the value that will be inserted
              //  into the Parameter Table.
              insertValue = encryptionManager.EncryptString(parameterValue, "sombra1");

            }
            else
            {

              //  Set the clear text Parameter Value as the string that will be inserted into the Parameter Table.
              insertValue = parameterValue;

            }

            //  Make sure there is a valid connection to the Parameter Table before moving on.
            if (!ValidConnection())
            {
              //  Return a "FALSE" to the calling routine to indicate that this process failed.
              return false;
            }

            //  Check to make sure that the Parameter does not already exist in the Parameter Table.  If it does,
            //  fail this process.
            if (ParameterExists(parameterName))
            {
              //  Return a "FALSE" to the calling routine to indicate that this process failed.
              return false;
            }

            //  Build the SQLStatement that will be used to insert the Parameter into the Parameter Table.
            if (parameterEncrypted)
            {

              //  Determine if the "Parameter_Encrypted" Field exists in the Parameter Table. If so, populate
              //  it accordingly.
              if (EncryptionFieldExists())
              {
            //  Build the SQL Statement that will insert the Parameter into the Parameter Table and populate
            //  the Parameter Encrypted Table with a "1" to indicate that the parameter is encrypted.
            sqlStatement = "INSERT "
                         + "INTO " + _parameterTableName + " "
                         + "(Parameter_Name, Parameter_Value, Parameter_Encrypted) "
                         + "VALUES('" + parameterName + "', '" + insertValue + "', 1)";
              }
              else
              {
            //  Build the SQL Statement that will insert the Parameter into the Parameter Table.  The
            //  Parameter_Encrypted Field will not be populated since it does not exist in the Parameter Table.
            sqlStatement = "INSERT "
                         + "INTO " + _parameterTableName + " "
                         + "(Parameter_Name, Parameter_Value) "
                         + "VALUES('" + parameterName + "', '" + insertValue + "')";
              }

            }
            else
            {

              //  Determine if the "Parameter_Encrypted" Field exists in the Parameter Table. If so, populate
              //  it accordingly.
              if (EncryptionFieldExists())
              {
            //  Build the SQL Statement that will insert the Parameter into the Parameter Table and populate
            //  the Parameter Encrypted Table with a "0" to indicate that the parameter is not encrypted.
            sqlStatement = "INSERT "
                         + "INTO " + _parameterTableName + " "
                         + "(Parameter_Name, Parameter_Value, Parameter_Encrypted) "
                         + "VALUES('" + parameterName + "', '" + insertValue + "', 0)";
              }
              else
              {
            //  Build the SQL Statement that will insert the Parameter into the Parameter Table.  The
            //  Parameter_Encrypted Field will not be populated since it does not exist in the Parameter Table.
            sqlStatement = "INSERT "
                         + "INTO " + _parameterTableName + " "
                         + "(Parameter_Name, Parameter_Value) "
                         + "VALUES('" + parameterName + "', '" + insertValue + "')";
              }

            }

            //  Create the Command Object that will be used to Write the Parameter to the Parameter Table.
            parameterWriteCommand = new SqlCommand();
            parameterWriteCommand.Connection = _parameterDatabaseConnection;
            parameterWriteCommand.CommandText = sqlStatement;

            //  Write the Parameter to the Parameter Table.
            rowsAffected = parameterWriteCommand.ExecuteNonQuery();

            //  Close the Command Object since it is no longer needed.
            parameterWriteCommand.Dispose();

            //  Determine if the Parameter was written to the Parameter Table correctly.
            if (rowsAffected > 0)
            {

              //  Return a "TRUE" to the calling routine to indicate that this process succeeded.
              return true;

            }
            else
            {

              //  Return a "FALSE" to the calling routine to indicate that this process FAILED.
              return true;

            }

              }
              catch
              {
            //  Return FALSE to the calling routine to indicate that this process failed.
            return false;

              }
        }
예제 #2
0
        } //  ModifyParameter

        /// <summary>
        /// Replaces the Parameter Value associated with the passed Key in the Parameter Table with the new value
        /// passed to the function.
        /// </summary>
        /// <param name="parameterName">
        /// The name (key) of the parameter whose value is to be modified.
        /// </param>
        /// <param name="parameterValue">
        /// The new Parameter Value that is to replace the existing Value in the Parameter Table.
        /// </param>
        /// <param name="parameterEncrypted">
        /// An indicator of whether the Parameter Value should be encrypted in the Parameter Table.
        /// </param>
        /// <param name="newParameterName">
        /// The new parameter name if the name of the existing parameter is to be altered.
        /// </param>
        /// <returns>
        /// TRUE - If the Parameter Value was updated successfully.
        /// FALSE - If the parameter was not updated successfully.
        /// </returns>
        public bool ModifyParameter(string parameterName, string parameterValue, bool parameterEncrypted, string newParameterName)
        {
            EncryptionManager encryptionManager = null;
            string            insertValue       = null;
            int        encryptedIndicatorValue  = -9999;
            string     sqlStatement             = null;
            SqlCommand parameterModifyCommand   = null;
            int        rowsAffected             = -9999;

            try
            {
                //  Make sure a Valid Parameter Name was passed to this routine.  If not, exit.
                if (parameterName.Length == 0)
                {
                    //  Return a "FALSE" to the calling routine to indicate that this process failed.
                    return(false);
                }


                //  If the Parameter Value is to be encrypted, encrypt it.
                if (parameterEncrypted)
                {
                    //  Instantiate an Encryption Manager Class.
                    encryptionManager = new EncryptionManager();

                    //  Encrypt the Parameter Value and set the encrypted string to be the value that will be inserted
                    //  into the Parameter Table.
                    insertValue = encryptionManager.EncryptString(parameterValue, "sombra1");

                    //  Set the Parameter Encrypted Indicator Value to "1".
                    encryptedIndicatorValue = 1;
                }
                else
                {
                    //  Set the clear text Parameter Value as the string that will be inserted into the Parameter Table.
                    insertValue = parameterValue;

                    //  Set the Parameter Encrypted Indicator Value to "0".
                    encryptedIndicatorValue = 0;
                }


                //  Make sure there is a valid connection to the Parameter Table before moving on.
                if (!ValidConnection())
                {
                    //  Return a "FALSE" to the calling routine to indicate that this process failed.
                    return(false);
                }


                //  Check to make sure that the Parameter does exist in the Parameter Table.  If it does not,
                //  fail this process.
                if (!ParameterExists(parameterName))
                {
                    //  Return a "FALSE" to the calling routine to indicate that this process failed.
                    return(false);
                }


                //  Determine if the "Parameter_Encrypted" Field exists in the Parameter Table. If so, populate
                //  it accordingly.
                if (EncryptionFieldExists())
                {
                    //  Build the SQL Statement that will modify the Parameter in the Parameter Table.
                    sqlStatement = "UPDATE" + _parameterTableName + " "
                                   + "SET "
                                   + "Parameter_Name = '" + newParameterName + "', "
                                   + "Parameter_Value = '" + insertValue + "', "
                                   + "Parameter_Encrypted = " + encryptedIndicatorValue + " "
                                   + "WHERE Parameter_Name = '" + parameterName + "'";
                }
                else
                {
                    //  Build the SQL Statement that will modify the Parameter in the Parameter Table.  The
                    //  Parameter_Encrypted Field will not be populated since it does not exist in the Parameter Table.
                    sqlStatement = "UPDATE" + _parameterTableName + " "
                                   + "SET "
                                   + "Parameter_Name = '" + newParameterName + "', "
                                   + "Parameter_Value = '" + insertValue + "', "
                                   + "WHERE Parameter_Name = '" + parameterName + "'";
                }



                //  Create the Command Object that will be used to Write the Parameter to the Parameter Table.
                parameterModifyCommand             = new SqlCommand();
                parameterModifyCommand.Connection  = _parameterDatabaseConnection;
                parameterModifyCommand.CommandText = sqlStatement;


                //  Write the Parameter to the Parameter Table.
                rowsAffected = parameterModifyCommand.ExecuteNonQuery();


                //  Close the Command Object since it is no longer needed.
                parameterModifyCommand.Dispose();


                //  Determine if the Parameter was written to the Parameter Table correctly.
                if (rowsAffected > 0)
                {
                    //  Return a "TRUE" to the calling routine to indicate that this process succeeded.
                    return(true);
                }
                else
                {
                    //  Return a "FALSE" to the calling routine to indicate that this process FAILED.
                    return(true);
                }
            }
            catch
            {
                //  Return FALSE to teh calling routine to indicate that this process failed.
                return(false);
            }
        } //  ModifyParameter