Exemplo n.º 1
0
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        /// <returns>[To be supplied.]</returns>
        public override string ToString()
        {
            if (!this.recordWasLoadedFromDB)
            {
                throw new ArgumentException("No record was loaded from the database. The DisplayName is not available.");
            }

            if (this.displayName == null)
            {
                bool alreadyOpened = false;

                Params.spS_Customers_Display Param = new Params.spS_Customers_Display(true);

                switch (this.lastKnownConnectionType)
                {
                case Bob.DataClasses.ConnectionType.ConnectionString:
                    Param.SetUpConnection(this.connectionString);
                    break;

                case Bob.DataClasses.ConnectionType.SqlConnection:
                    Param.SetUpConnection(this.sqlConnection);
                    alreadyOpened = (this.sqlConnection.State == System.Data.ConnectionState.Open);
                    break;

                case Bob.DataClasses.ConnectionType.SqlTransaction:
                    Param.SetUpConnection(this.sqlTransaction);
                    break;
                }

                Param.Param_CustomerID = this.col_CustomerID;

                System.Data.SqlClient.SqlDataReader sqlDataReader = null;
                SPs.spS_Customers_Display           Sp            = new SPs.spS_Customers_Display(false);
                if (Sp.Execute(ref Param, out sqlDataReader))
                {
                    if (sqlDataReader.Read())
                    {
                        if (!sqlDataReader.IsDBNull(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex))
                        {
                            if (sqlDataReader.GetFieldType(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex) == typeof(string))
                            {
                                this.displayName = sqlDataReader.GetString(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex);
                            }
                            else
                            {
                                this.displayName = sqlDataReader.GetValue(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex).ToString();
                            }
                        }
                    }

                    if (sqlDataReader != null && !sqlDataReader.IsClosed)
                    {
                        sqlDataReader.Close();
                    }

                    CloseConnection(Sp.Connection, alreadyOpened);
                }
                else
                {
                    if (sqlDataReader != null && !sqlDataReader.IsClosed)
                    {
                        sqlDataReader.Close();
                    }

                    CloseConnection(Sp.Connection, alreadyOpened);

                    throw new Bob.DataClasses.CustomException(Param, "Bob.BusinessComponents.Customer", "ToString");
                }
            }

            return(this.displayName);
        }
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        public void Refresh()
        {
            internalRecords = new System.Collections.ArrayList();

            bool alreadyOpened = false;

            Params.spS_Customers_Display Param = new Params.spS_Customers_Display(true);
            Param.CommandTimeOut = this.selectCollectionCommandTimeOut;
            switch (this.lastKnownConnectionType)
            {
            case Bob.DataClasses.ConnectionType.ConnectionString:
                Param.SetUpConnection(this.connectionString);
                break;

            case Bob.DataClasses.ConnectionType.SqlConnection:
                Param.SetUpConnection(this.sqlConnection);
                alreadyOpened = (this.sqlConnection.State == System.Data.ConnectionState.Open);
                break;

            case Bob.DataClasses.ConnectionType.SqlTransaction:
                Param.SetUpConnection(this.sqlTransaction);
                break;
            }

            if (!this.col_TitleId.IsNull)
            {
                Param.Param_TitleId = this.col_TitleId;
            }

            System.Data.SqlClient.SqlDataReader sqlDataReader = null;
            SPs.spS_Customers_Display           Sp            = new SPs.spS_Customers_Display(false);
            if (Sp.Execute(ref Param, out sqlDataReader))
            {
                while (sqlDataReader.Read())
                {
                    Customer record = null;

                    switch (this.lastKnownConnectionType)
                    {
                    case Bob.DataClasses.ConnectionType.ConnectionString:
                        record = new Customer(this.connectionString, sqlDataReader.GetSqlInt32(SPs.spS_Customers_Display.Resultset1.Fields.Column_ID1.ColumnIndex));
                        break;

                    case Bob.DataClasses.ConnectionType.SqlConnection:
                        record = new Customer(this.sqlConnection, sqlDataReader.GetSqlInt32(SPs.spS_Customers_Display.Resultset1.Fields.Column_ID1.ColumnIndex));
                        break;

                    case Bob.DataClasses.ConnectionType.SqlTransaction:
                        record = new Customer(this.sqlTransaction, sqlDataReader.GetSqlInt32(SPs.spS_Customers_Display.Resultset1.Fields.Column_ID1.ColumnIndex));
                        break;
                    }


                    record.UpdateCommandTimeOut = this.updateCommandTimeOut;
                    record.SelectCommandTimeOut = this.selectCommandTimeOut;

                    if (sqlDataReader.GetFieldType(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex) == typeof(string))
                    {
                        record.displayName = sqlDataReader.GetString(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex);
                    }
                    else
                    {
                        record.displayName = sqlDataReader.GetValue(SPs.spS_Customers_Display.Resultset1.Fields.Column_Display.ColumnIndex).ToString();
                    }

                    internalRecords.Add(record);
                }

                if (sqlDataReader != null && !sqlDataReader.IsClosed)
                {
                    sqlDataReader.Close();
                }

                CloseConnection(Sp.Connection, alreadyOpened);

                this.recordsAreLoaded = true;
            }
            else
            {
                if (sqlDataReader != null && !sqlDataReader.IsClosed)
                {
                    sqlDataReader.Close();
                }

                CloseConnection(Sp.Connection, alreadyOpened);

                this.recordsAreLoaded = false;
                throw new Bob.DataClasses.CustomException(Param, "Bob.BusinessComponents.Customers", "Refresh");
            }
        }