예제 #1
0
        /// <summary>
        /// Tests the connection to the database
        /// </summary>
        internal bool TestDatabaseConnection()
        {
            // initial value
            bool connected = false;

            // locals
            string methodName = "TestDatabaseConnection";
            string objectName = "$safeprojectname$.Controller.System.SystemController";

            try
            {
                // Create Delegate For DataOperation
                ApplicationController.DataOperationMethod testDataConnection = this.DataBridge.DataOperations.SystemMethods.TestDataConnection;

                // Create null parameters object (not needed for this, but you have to have it to call the method).
                List <PolymorphicObject> parameters = null;

                // Perform DataOperation
                PolymorphicObject connectedObject = this.DataBridge.PerformDataOperation(methodName, objectName, testDataConnection, parameters);

                // If method returned "true" value.
                if (connectedObject.Boolean.Value == NullableBooleanEnum.True)
                {
                    // set connected to true.
                    connected = true;
                }
            }
            catch (Exception error)
            {
                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // Create Error
                    DataConnectionFailedException dataConnectionError = new DataConnectionFailedException(methodName, objectName, error);

                    // Log the current error
                    this.ErrorProcessor.LogError(methodName, objectName, dataConnectionError);
                }
            }

            // return value
            return(connected);
        }
예제 #2
0
        /// <summary>
        /// This method Executes a Non Query StoredProcedure
        /// </summary>
        public PolymorphicObject ExecuteNonQuery(string procedureName, SqlParameter[] sqlParameters)
        {
            // initial value
            PolymorphicObject returnValue = new PolymorphicObject();

            // locals
            List <PolymorphicObject> parameters = new List <PolymorphicObject>();

            // create the parameters
            PolymorphicObject procedureNameParameter = new PolymorphicObject();
            PolymorphicObject sqlParametersParameter = new PolymorphicObject();

            // if the procedureName exists
            if (!String.IsNullOrEmpty(procedureName))
            {
                // Create an instance of the SystemMethods object
                SystemMethods systemMethods = new SystemMethods();

                // setup procedureNameParameter
                procedureNameParameter.Name = "ProcedureName";
                procedureNameParameter.Text = procedureName;

                // setup sqlParametersParameter
                sqlParametersParameter.Name        = "SqlParameters";
                sqlParametersParameter.ObjectValue = sqlParameters;

                // Add these parameters to the parameters
                parameters.Add(procedureNameParameter);
                parameters.Add(sqlParametersParameter);

                // get the dataConnector
                DataAccessComponent.DataManager.DataConnector dataConnector = GetDataConnector();

                // Execute the query
                returnValue = systemMethods.ExecuteNonQuery(parameters, dataConnector);
            }

            // return value
            return(returnValue);
        }
예제 #3
0
        /// <summary>
        /// Tests the connection to the database
        /// </summary>
        internal PolymorphicObject TestDataConnection(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // Initial Value
            PolymorphicObject returnObject = new PolymorphicObject();

            // Create returnObject.Boolean
            returnObject.Boolean = new NullableBoolean();

            // If the data connection is connected
            if ((dataConnector != null) && (dataConnector.Connected == true))
            {
                // Set Boolean To True
                returnObject.Boolean.Value = NullableBooleanEnum.True;
            }
            else
            {
                // Raise Error Data Connection Not Available
                throw new Exception("The database connection is not available.");
            }

            // return value
            return(returnObject);
        }
예제 #4
0
        /// <summary>
        /// Performs an operation that required a connection to the database.
        /// This method uses a delegate to execute the method so that this is the
        /// only place in the application a connection to the database is opened.
        /// </summary>
        internal PolymorphicObject PerformDataOperation(string methodName, string objectName, ApplicationController.DataOperationMethod dataMethod, List <PolymorphicObject> parameters)
        {
            // Initial Value
            PolymorphicObject returnObject = null;

            // local
            bool dataConnectionNotAvailable = false;

            try
            {
                // set the last exception to null
                this.Exception = null;

                // Connect To Database
                this.LoginManager.ConnectToDatabase(this.DataManager);

                // Testing only
                string connectionString = this.DataManager.DataConnector.ConnectionString;

                // if connected
                if (this.DataManager.DataConnector.Connected)
                {
                    // verify dataMethod exists
                    if (dataMethod != null)
                    {
                        // Invoke Method
                        returnObject = dataMethod(parameters, this.DataManager.DataConnector);
                    }
                }
                else
                {
                    // set dataConnectionNotAvailable to true
                    dataConnectionNotAvailable = true;

                    // Raise Error Data Connection Not Available
                    throw new Exception("The database connection is not available.");
                }
            }
            catch (Exception error)
            {
                // Set exception
                this.Exception = error;

                // If ErrorProcessor exists
                if (this.ErrorProcessor != null)
                {
                    // If this is a dataConnection not available error.
                    if (dataConnectionNotAvailable)
                    {
                        // Create Error for data connection failed
                        DataConnectionFailedException dataConnectionError = new DataConnectionFailedException(methodName, objectName, error);

                        // Log the current dataConnectionError
                        this.ErrorProcessor.LogError(methodName, objectName, dataConnectionError);
                    }
                    else
                    {
                        // Log the exception
                        this.ErrorProcessor.LogError(methodName, objectName, error);
                    }
                }
            }
            finally
            {
                // Close Connection To Database
                this.DataManager.DataConnector.Close();
            }

            // return value
            return(returnObject);
        }
예제 #5
0
        /// <summary>
        /// This method is used to execute a query that does not return a value.
        /// To call this method, you must set following:
        /// </summary>
        /// <param name="parameters">The parameters must be set to call this method.
        /// 1. 'ProcedureName' - The String value must be set for this parameter.
        /// 2. 'SqlParameters' (Optional) - If the stored procedure to be called requires parameters
        /// then you must pass in the SqlParameters[] array as this parameter.
        /// It does not matter the order of these parameters.
        /// </param>
        /// <param name="dataConnector">The database connection to use to execute this procedure.</param>
        /// A successful will call will set returnValue.Boolean to true (executed)
        /// In the event the procedure does not execute (returnValue.Boolean = false)
        /// check the following:
        /// returnValue.Name   = 'Error" - Will be set to error
        /// returnValue.Text   = Will be set to the Exception.ToString();
        /// returnValue.Object = Will Contain the Exception that occurred.
        public PolymorphicObject ExecuteNonQuery(List <PolymorphicObject> parameters, DataConnector dataConnector)
        {
            // initial value
            PolymorphicObject returnValue = new PolymorphicObject();

            // Set to false
            returnValue.Boolean = new NullableBoolean(false);

            // locals
            bool executed = false;

            try
            {
                // If the data connection is connected
                if ((dataConnector != null) && (dataConnector.Connected == true))
                {
                    // Create a StoredProcedure
                    StoredProcedure storedProcedure = new StoredProcedure();

                    // Create a StoredProcedure object
                    storedProcedure.ProcedureName = FindProcedureName(parameters);

                    // Set the Parameters for the StoredProcedure
                    storedProcedure.Parameters = FindSqlParameters(parameters);

                    // if the ProcedureName is set
                    if (!String.IsNullOrEmpty(storedProcedure.ProcedureName))
                    {
                        // Create an instance of the DataHelper
                        DataHelper dataHelper = new DataHelper();

                        // Perform an update
                        executed = dataHelper.UpdateRecord(storedProcedure, dataConnector);

                        // set the return value
                        returnValue.Boolean = new NullableBoolean(executed);
                    }
                }
                else
                {
                    // Raise Error Data Connection Not Available
                    throw new Exception("The database connection is not available.");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                string err = error.ToString();

                // Set the text of the
                returnValue.Name = "Error";

                // Set the text for the returnValue
                returnValue.Text = err;

                // set the return value
                returnValue.ObjectValue = error;
            }

            // return value
            return(returnValue);
        }