private bool RetrieveParameters(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, ref System.Data.SqlClient.SqlCommand sqlCommand)
        {
            try {
                if (sqlCommand.Parameters["@RETURN_VALUE"].Value != System.DBNull.Value)
                {
                    parameters.internal_Set_RETURN_VALUE((System.Int32)sqlCommand.Parameters["@RETURN_VALUE"].Value);
                }
                else
                {
                    parameters.internal_Set_RETURN_VALUE(System.Data.SqlTypes.SqlInt32.Null);
                }

                return(true);
            }

            catch (System.Data.SqlClient.SqlException sqlException) {
                parameters.internal_UpdateExceptionInformation(sqlException);
                return(false);
            }

            catch (System.Exception exception) {
                parameters.internal_UpdateExceptionInformation(exception);
                return(false);
            }
        }
        private bool DeclareParameters(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, ref System.Data.SqlClient.SqlCommand sqlCommand)
        {
            try {
                System.Data.SqlClient.SqlParameter sqlParameter;

                sqlParameter            = new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4);
                sqlParameter.Direction  = System.Data.ParameterDirection.ReturnValue;
                sqlParameter.IsNullable = true;
                sqlParameter.Value      = System.DBNull.Value;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter           = new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.UniqueIdentifier, 16);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                if (parameters.internal_Param_ProductID_UseDefaultValue)
                {
                    sqlParameter.Value = null;
                }
                else if (!parameters.Param_ProductID.IsNull)
                {
                    sqlParameter.Value = parameters.Param_ProductID;
                }
                else
                {
                    sqlParameter.IsNullable = true;
                    sqlParameter.Value      = System.DBNull.Value;
                }
                sqlCommand.Parameters.Add(sqlParameter);


                return(true);
            }

            catch (System.Data.SqlClient.SqlException sqlException) {
                parameters.internal_UpdateExceptionInformation(sqlException);
                return(false);
            }

            catch (System.Exception exception) {
                parameters.internal_UpdateExceptionInformation(exception);
                return(false);
            }
        }
        /// <summary>
        /// This method allows you to execute the [spS_xProductQuantityPerOrder] stored procedure and retrieve back the data
        /// populated in a DataSet (System.Data.DataSet).
        /// </summary>
        /// <param name="parameters">
        /// Contains all the necessary information to execute correctly the stored procedure, i.e.
        /// the database connection to use and all the necessary input parameters to be supplied
        /// for this stored procedure execution. After the execution, this object will allow you
        /// to retrieve back the stored procedure return value and all the output parameters.
        /// </param>
        /// <param name="dataset">
        /// Will be populated with the data after execution.
        /// </param>
        /// <param name="tableName">
        /// Will be the based name of the table in the database.
        /// </param>
        /// <param name="startRecord">The zero-based record number to start with.</param>
        /// <param name="maxRecords">The maximum number of records to retrieve.</param>
        /// <returns>True if the call was successful. Otherwise, it returns False.</returns>
        public bool Execute(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, ref System.Data.DataSet dataset, string tableName, int startRecord, int maxRecords)
        {
            System.Data.SqlClient.SqlCommand     sqlCommand     = null;
            System.Data.SqlClient.SqlDataAdapter sqlDataAdapter = null;
            System.Boolean returnStatus           = false;
            System.Boolean connectionMustBeClosed = true;

            try {
                if (dataset == null)
                {
                    dataset = new System.Data.DataSet();
                }
                ResetParameter(ref parameters);

                parameters.internal_SetErrorSource(ErrorSource.ConnectionInitialization);
                returnStatus = InitializeConnection(ref parameters, out sqlCommand, ref connectionMustBeClosed);
                if (!returnStatus)
                {
                    return(false);
                }

                parameters.internal_SetErrorSource(ErrorSource.ParametersSetting);
                returnStatus = DeclareParameters(ref parameters, ref sqlCommand);
                if (!returnStatus)
                {
                    return(false);
                }

                parameters.internal_SetErrorSource(ErrorSource.QueryExecution);
                sqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
                sqlDataAdapter.SelectCommand = sqlCommand;

                if (startRecord == -1)
                {
                    sqlDataAdapter.Fill(dataset, tableName);
                }
                else
                {
                    sqlDataAdapter.Fill(dataset, startRecord, maxRecords, tableName);
                }
                sqlDataAdapter.Dispose();

                parameters.internal_SetErrorSource(ErrorSource.ParametersRetrieval);
                returnStatus = RetrieveParameters(ref parameters, ref sqlCommand);
            }

            catch (System.Data.SqlClient.SqlException sqlException) {
                dataset = null;
                parameters.internal_UpdateExceptionInformation(sqlException);
                returnStatus = false;

                if (this.throwExceptionOnExecute)
                {
                    throw sqlException;
                }
            }

            catch (System.Exception exception) {
                dataset = null;
                parameters.internal_UpdateExceptionInformation(exception);
                returnStatus = false;
                parameters.internal_SetErrorSource(ErrorSource.Other);

                if (this.throwExceptionOnExecute)
                {
                    throw exception;
                }
            }

            finally {
                if (sqlCommand != null)
                {
                    sqlCommand.Dispose();
                }

                if (parameters.SqlTransaction == null)
                {
                    if (this.sqlConnection != null && connectionMustBeClosed && this.sqlConnection.State == System.Data.ConnectionState.Open)
                    {
                        this.sqlConnection.Close();
                        this.sqlConnection.Dispose();
                    }
                }

                if (returnStatus)
                {
                    parameters.internal_SetErrorSource(ErrorSource.NoError);
                }
                else
                {
                    if (this.throwExceptionOnExecute)
                    {
                        if (parameters.SqlException != null)
                        {
                            throw parameters.SqlException;
                        }
                        else
                        {
                            throw parameters.OtherException;
                        }
                    }
                }
            }
            return(returnStatus);
        }
 /// <summary>
 /// This method allows you to execute the [spS_xProductQuantityPerOrder] stored procedure and retrieve back the data
 /// populated in a DataSet (System.Data.DataSet).
 /// </summary>
 /// <param name="parameters">
 /// Contains all the necessary information to execute correctly the stored procedure, i.e.
 /// the database connection to use and all the necessary input parameters to be supplied
 /// for this stored procedure execution. After the execution, this object will allow you
 /// to retrieve back the stored procedure return value and all the output parameters.
 /// </param>
 /// <param name="dataset">
 /// Will be populated with the data after execution.
 /// </param>
 /// <param name="tableName">
 /// Will be the based name of the table in the database.
 /// </param>
 /// <returns>True if the call was successful. Otherwise, it returns False.</returns>
 public bool Execute(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, ref System.Data.DataSet dataset, string tableName)
 {
     return(Execute(ref parameters, ref dataset, tableName, -1, -1));
 }
 /// <summary>
 /// This method allows you to execute the [spS_xProductQuantityPerOrder] stored procedure and retrieve back the data
 /// populated in a DataSet (System.Data.DataSet).
 /// </summary>
 /// <param name="parameters">
 /// Contains all the necessary information to execute correctly the stored procedure, i.e.
 /// the database connection to use and all the necessary input parameters to be supplied
 /// for this stored procedure execution. After the execution, this object will allow you
 /// to retrieve back the stored procedure return value and all the output parameters.
 /// </param>
 /// <param name="dataset">
 /// Will be populated with the data after execution. The table based name used will be: 'spS_xProductQuantityPerOrder'.
 /// </param>
 /// <param name="startRecord">The zero-based record number to start with.</param>
 /// <param name="maxRecords">The maximum number of records to retrieve.</param>
 /// <returns>True if the call was successful. Otherwise, it returns False.</returns>
 public bool Execute(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, ref System.Data.DataSet dataset, int startRecord, int maxRecords)
 {
     return(Execute(ref parameters, ref dataset, "spS_xProductQuantityPerOrder", startRecord, maxRecords));
 }
        /// <summary>
        /// This method allows you to execute the [spS_xProductQuantityPerOrder] stored procedure and retrieve back the data
        /// accessible via a SqlDataReader (System.Data.SqlClient.SqlDataReader).
        /// </summary>
        /// <param name="parameters">
        /// Contains all the necessary information to execute correctly the stored procedure, i.e.
        /// the database connection to use and all the necessary input parameters to be supplied
        /// for this stored procedure execution. After the execution, this object will allow you
        /// to retrieve back the stored procedure return value and all the output parameters.
        /// </param>
        /// <param name="sqlDataReader">
        /// Will be created after execution. Don't forget to close it after usage.
        /// </param>
        /// <param name="commandBehavior">
        /// One of the CommandBehavior values.
        /// </param>
        /// <returns>True if the call was successful. Otherwise, it returns False.</returns>
        public bool Execute(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, out System.Data.SqlClient.SqlDataReader sqlDataReader, System.Data.CommandBehavior commandBehavior)
        {
            System.Data.SqlClient.SqlCommand sqlCommand = null;
            System.Boolean returnStatus           = false;
            System.Boolean connectionMustBeClosed = true;

            try {
                sqlDataReader = null;
                ResetParameter(ref parameters);

                parameters.internal_SetErrorSource(ErrorSource.ConnectionInitialization);
                returnStatus = InitializeConnection(ref parameters, out sqlCommand, ref connectionMustBeClosed);
                if (!returnStatus)
                {
                    return(false);
                }

                parameters.internal_SetErrorSource(ErrorSource.ParametersSetting);
                returnStatus = DeclareParameters(ref parameters, ref sqlCommand);
                if (!returnStatus)
                {
                    return(false);
                }

                parameters.internal_SetErrorSource(ErrorSource.QueryExecution);
                sqlDataReader = sqlCommand.ExecuteReader(commandBehavior);

                parameters.internal_Set_ReturnValue_Available(false);

                parameters.internal_Set_SqlDataReader(ref sqlDataReader);
                parameters.internal_Set_SqlCommand(ref sqlCommand);
            }

            catch (System.Data.SqlClient.SqlException sqlException) {
                sqlDataReader = null;
                parameters.internal_UpdateExceptionInformation(sqlException);
                returnStatus = false;

                if (this.throwExceptionOnExecute)
                {
                    throw sqlException;
                }
            }

            catch (System.Exception exception) {
                sqlDataReader = null;
                parameters.internal_UpdateExceptionInformation(exception);
                returnStatus = false;
                parameters.internal_SetErrorSource(ErrorSource.Other);

                if (this.throwExceptionOnExecute)
                {
                    throw exception;
                }
            }

            finally {
                if (sqlCommand != null)
                {
                    sqlCommand.Dispose();
                }

                // We do not close the SqlConnection because the SqlReader object needs it.
                // It is the responsability of the caller to close it by calling: SqlDataReader.Close();

                if (returnStatus)
                {
                    parameters.internal_SetErrorSource(ErrorSource.NoError);
                }
                else
                {
                    if (this.throwExceptionOnExecute)
                    {
                        if (parameters.SqlException != null)
                        {
                            throw parameters.SqlException;
                        }
                        else
                        {
                            throw parameters.OtherException;
                        }
                    }
                }
            }
            return(returnStatus);
        }
 /// <summary>
 /// This method allows you to execute the [spS_xProductQuantityPerOrder] stored procedure and retrieve back the data
 /// accessible via a SqlDataReader (System.Data.SqlClient.SqlDataReader).
 /// </summary>
 /// <param name="parameters">
 /// Contains all the necessary information to execute correctly the stored procedure, i.e.
 /// the database connection to use and all the necessary input parameters to be supplied
 /// for this stored procedure execution. After the execution, this object will allow you
 /// to retrieve back the stored procedure return value and all the output parameters.
 /// </param>
 /// <param name="sqlDataReader">
 /// Will be created after execution. Don't forget to close it after usage.
 /// </param>
 /// <returns>True if the call was successful. Otherwise, it returns False.</returns>
 public bool Execute(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, out System.Data.SqlClient.SqlDataReader sqlDataReader)
 {
     return(Execute(ref parameters, out sqlDataReader, System.Data.CommandBehavior.Default));
 }
        private bool InitializeConnection(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters, out System.Data.SqlClient.SqlCommand sqlCommand, ref bool connectionMustBeClosed)
        {
            try {
                this.sqlConnection     = null;
                sqlCommand             = null;
                connectionMustBeClosed = true;

                if (parameters.ConnectionType == ConnectionType.None)
                {
                    throw new InvalidOperationException("No connection information was supplied. Consider calling the 'SetUpConnection' method of the OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder object before doing this call.");
                }

                if (parameters.ConnectionType == ConnectionType.SqlConnection && parameters.SqlConnection == null)
                {
                    throw new InvalidOperationException("No connection information was supplied (SqlConnection == null). Consider calling the 'SetUpConnection' method of the OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder object before doing this call.");
                }

                if (parameters.ConnectionType == ConnectionType.SqlTransaction && parameters.SqlTransaction == null)
                {
                    throw new InvalidOperationException("No connection information was supplied (SqlTransaction == null). Consider calling the 'SetUpConnection' method of the OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder object before doing this call.");
                }

                switch (parameters.ConnectionType)
                {
                case ConnectionType.ConnectionString:

                    string connectionString;

                    if (parameters.ConnectionString.Length == 0)
                    {
                        connectionString = Information.GetConnectionStringFromConfigurationFile;
                        if (connectionString.Length == 0)
                        {
                            connectionString = Information.GetConnectionStringFromRegistry;
                        }
                    }

                    else
                    {
                        connectionString = parameters.ConnectionString;
                    }

                    if (connectionString.Length == 0)
                    {
                        throw new System.InvalidOperationException("No connection information was supplied (ConnectionString == \"\")! (OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder)");
                    }

                    parameters.internal_SetErrorSource(ErrorSource.ConnectionOpening);
                    this.sqlConnection = new System.Data.SqlClient.SqlConnection(connectionString);
                    this.sqlConnection.Open();

                    sqlCommand = sqlConnection.CreateCommand();
                    break;

                case ConnectionType.SqlConnection:

                    sqlConnection = parameters.SqlConnection;

                    if (this.sqlConnection.State != System.Data.ConnectionState.Open)
                    {
                        this.sqlConnection.Open();
                    }
                    else
                    {
                        connectionMustBeClosed = false;
                    }
                    sqlCommand = sqlConnection.CreateCommand();
                    break;

                case ConnectionType.SqlTransaction:

                    sqlCommand         = new System.Data.SqlClient.SqlCommand();
                    this.sqlConnection = parameters.SqlTransaction.Connection;
                    if (this.sqlConnection == null)
                    {
                        throw new InvalidOperationException("The transaction is no longer valid.");
                    }

                    if (this.sqlConnection.State != System.Data.ConnectionState.Open)
                    {
                        this.sqlConnection.Open();
                    }
                    else
                    {
                        connectionMustBeClosed = false;
                    }
                    sqlCommand.Connection  = sqlConnection;
                    sqlCommand.Transaction = parameters.SqlTransaction;                                             break;
                }

                sqlCommand.CommandTimeout = parameters.CommandTimeOut;
                sqlCommand.CommandType    = System.Data.CommandType.StoredProcedure;
                sqlCommand.CommandText    = "spS_xProductQuantityPerOrder";

                return(true);
            }

            catch (System.Data.SqlClient.SqlException sqlException) {
                sqlConnection = null;
                sqlCommand    = null;
                parameters.internal_UpdateExceptionInformation(sqlException);
                return(false);
            }

            catch (System.Exception exception) {
                sqlConnection = null;
                sqlCommand    = null;
                parameters.internal_UpdateExceptionInformation(exception);
                return(false);
            }
        }
 private void ResetParameter(ref OlymarsDemo.DataClasses.Parameters.spS_xProductQuantityPerOrder parameters)
 {
     parameters.internal_Set_RETURN_VALUE(System.Data.SqlTypes.SqlInt32.Null);
 }