Example #1
0
        /// <summary>
        /// Initializes the control. You need to specify how to connect to the SQL Server database.
        /// You also need to supply the 'spS_JobPart' stored procedure parameters.
        /// </summary>
        /// <param name="connectionString">A valid connection string to the database.</param>
        /// <param name="valueMember">name of the field to be used as a primary key.</param>
        /// <param name="displayMember">name of the field to be used for the content display.</param>
        /// <param name="param_JobPartId">Value for the parameter @JobPartId.</param>
        /// <param name="param_JobId">Value for the parameter @JobId.</param>
        /// <param name="param_JobPartTypeId">Value for the parameter @JobPartTypeId.</param>
        public void Initialize(string connectionString, string valueMember, string displayMember, System.Data.SqlTypes.SqlInt32 param_JobPartId, System.Data.SqlTypes.SqlInt32 param_JobId, System.Data.SqlTypes.SqlInt32 param_JobPartTypeId)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString", "connectionString can be an empty string but can not be null.");
            }

            this.connectionString        = connectionString;
            this.LastKnownConnectionType = Bob.DataClasses.ConnectionType.ConnectionString;

#if OLYMARS_DEBUG
            object olymarsDebugCheck = System.Configuration.ConfigurationSettings.AppSettings["OlymarsDebugCheck"];
            if (olymarsDebugCheck == null || (string)olymarsDebugCheck == "True")
            {
                string DebugConnectionString = connectionString;

                if (DebugConnectionString.Length == 0)
                {
                    DebugConnectionString = Bob.DataClasses.Information.GetConnectionStringFromConfigurationFile;
                }

                if (DebugConnectionString.Length == 0)
                {
                    DebugConnectionString = Bob.DataClasses.Information.GetConnectionStringFromRegistry;
                }

                if (DebugConnectionString.Length != 0)
                {
                    System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(DebugConnectionString);

                    sqlConnection.Open();

                    System.Data.SqlClient.SqlCommand sqlCommand = sqlConnection.CreateCommand();

                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    sqlCommand.CommandText = "Select sysobjects.schema_ver from sysobjects where sysobjects.name = 'spS_JobPart'";

                    int CurrentRevision = (int)sqlCommand.ExecuteScalar();

                    sqlConnection.Close();

                    int OriginalRevision = ((Bob.DataClasses.OlymarsInformationAttribute)System.Attribute.GetCustomAttribute(this.GetType(), typeof(Bob.DataClasses.OlymarsInformationAttribute), false)).SqlObjectDependancyRevision;
                    if (CurrentRevision != OriginalRevision)
                    {
                        throw new System.InvalidOperationException(System.String.Format("OLYMARS: This code is not in sync anymore with [{0}]. It was generated when [{0}] version was: {2}. Current [{0}] version is: {1}{3}{3}You can either regenerate the code for this class so that it will be based on the new version or edit the configuration file of the class caller application and paste the following code:{3}{3}<?xml version=\"1.0\" encoding=\"utf-8\" ?>{3}<configuration>{3}\t<appSettings>{3}\t\t<add key=\"OlymarsDebugCheck\" value=\"False\" />{3}\t</appSettings>{3}</configuration>{3}{3}You will need to reload the caller application if it is a Windows Forms based application.", "spS_JobPart", CurrentRevision, OriginalRevision, System.Environment.NewLine));
                    }
                }
            }
#endif

            this.valueMember   = valueMember;
            this.displayMember = displayMember;
            this.tableName     = "spS_JobPart";

            this.param_JobPartId     = param_JobPartId;
            this.param_JobId         = param_JobId;
            this.param_JobPartTypeId = param_JobPartTypeId;
        }
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        /// <param name="connectionString">Connection string to be used when accessing the database.</param>
        /// <param name="col_CustomerID">[To be supplied.]</param>
        public Customer(string connectionString, System.Data.SqlTypes.SqlInt32 col_CustomerID)
        {
#if OLYMARS_DEBUG
            object olymarsDebugCheck = System.Configuration.ConfigurationSettings.AppSettings["OlymarsDebugCheck"];
            if (olymarsDebugCheck == null || (string)olymarsDebugCheck == "True")
            {
                string DebugConnectionString = connectionString;

                if (DebugConnectionString == System.String.Empty)
                {
                    DebugConnectionString = Bob.DataClasses.Information.GetConnectionStringFromConfigurationFile;
                }

                if (DebugConnectionString == System.String.Empty)
                {
                    DebugConnectionString = Bob.DataClasses.Information.GetConnectionStringFromRegistry;
                }

                if (DebugConnectionString != String.Empty)
                {
                    System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(DebugConnectionString);

                    sqlConnection.Open();

                    System.Data.SqlClient.SqlCommand sqlCommand = sqlConnection.CreateCommand();

                    sqlCommand.CommandType = System.Data.CommandType.Text;
                    sqlCommand.CommandText = "Select sysobjects.schema_ver from sysobjects where sysobjects.name = 'Customers'";

                    int CurrentRevision = (int)sqlCommand.ExecuteScalar();

                    sqlConnection.Close();

                    int OriginalRevision = ((Bob.DataClasses.OlymarsInformationAttribute)System.Attribute.GetCustomAttribute(this.GetType(), typeof(Bob.DataClasses.OlymarsInformationAttribute), false)).SqlObjectDependancyRevision;
                    if (CurrentRevision != OriginalRevision)
                    {
                        throw new System.InvalidOperationException(System.String.Format("OLYMARS: This code is not in sync anymore with [{0}]. It was generated when [{0}] version was: {2}. Current [{0}] version is: {1}", "Customers", CurrentRevision, OriginalRevision));
                    }
                }
            }
#endif

            this.recordWasLoadedFromDB = true;
            this.recordIsLoaded        = false;

            this.connectionString        = connectionString;
            this.lastKnownConnectionType = Bob.DataClasses.ConnectionType.ConnectionString;

            this.col_CustomerID = col_CustomerID;
        }
        /// <summary>
        /// Allows you to add a new record in the Title table.
        /// </summary>
        /// <param name="caller">The IWin32Window this form will display in front of.</param>
        /// <param name="formTitle">Title of this form.</param>
        /// <param name="sqlConnection">A valid System.Data.SqlClient.SqlConnection.</param>
        public void AddNewRecord(System.Windows.Forms.IWin32Window caller, string formTitle, System.Data.SqlClient.SqlConnection sqlConnection)
        {
            this.Text = formTitle;

            this.lastKnownConnectionType = Bob.DataClasses.ConnectionType.SqlConnection;
            this.sqlConnection           = sqlConnection;

            RequestForeignTables();
            EmptyControls();

            this.Control_Title.HandleTextChanged(null, null);

            Check_cmdOK_Button(null);

            ProcessHiddenAndDisabledControlStatus(true);

            this.ShowDialog(caller);
        }
        /// <summary>
        /// Creates a new instance of the SqlDataAdapter_JobPartType class.
        /// This constructor will automatically pre-configure the SqlDataAdapter.
        /// </summary>
        /// <param name="sqlTransaction">A valid System.Data.SqlClient.SqlTransaction to the database.</param>
        public SqlDataAdapter_JobPartType(System.Data.SqlClient.SqlTransaction sqlTransaction)
        {
            if (sqlTransaction == null || sqlTransaction.Connection == null)
            {
                throw new ArgumentNullException("sqlTransaction", "Invalid transaction!");
            }

            this.sqlTransaction          = sqlTransaction;
            this.lastKnownConnectionType = Bob.DataClasses.ConnectionType.SqlTransaction;

#if OLYMARS_DEBUG
            object olymarsDebugCheck = System.Configuration.ConfigurationSettings.AppSettings["OlymarsDebugCheck"];
            if (olymarsDebugCheck == null || (string)olymarsDebugCheck == "True")
            {
                bool NotAlreadyOpened = false;
                if (sqlTransaction.Connection.State == System.Data.ConnectionState.Closed)
                {
                    NotAlreadyOpened = true;
                    sqlTransaction.Connection.Open();
                }

                System.Data.SqlClient.SqlCommand sqlCommand = sqlTransaction.Connection.CreateCommand();

                sqlCommand.CommandType = System.Data.CommandType.Text;
                sqlCommand.CommandText = "Select sysobjects.schema_ver from sysobjects where sysobjects.name = 'JobPartType'";
                sqlCommand.Transaction = sqlTransaction;

                int CurrentRevision = (int)sqlCommand.ExecuteScalar();

                if (NotAlreadyOpened)
                {
                    sqlTransaction.Connection.Close();
                }

                int OriginalRevision = ((Bob.DataClasses.OlymarsInformationAttribute)System.Attribute.GetCustomAttribute(this.GetType(), typeof(Bob.DataClasses.OlymarsInformationAttribute), false)).SqlObjectDependancyRevision;
                if (CurrentRevision != OriginalRevision)
                {
                    throw new System.InvalidOperationException(System.String.Format("OLYMARS: This code is not in sync anymore with [{0}]. It was generated when [{0}] version was: {2}. Current [{0}] version is: {1}{3}{3}You can either regenerate the code for this class so that it will be based on the new version or edit the configuration file of the class caller application and paste the following code:{3}{3}<?xml version=\"1.0\" encoding=\"utf-8\" ?>{3}<configuration>{3}\t<appSettings>{3}\t\t<add key=\"OlymarsDebugCheck\" value=\"False\" />{3}\t</appSettings>{3}</configuration>{3}{3}You will need to reload the caller application if it is a Windows Forms based application.", "JobPartType", CurrentRevision, OriginalRevision, System.Environment.NewLine));
                }
            }
#endif

            this.Configure("JobPartType");
        }
Example #5
0
        /// <summary>
        /// Allows you to add a new record in the JobPartType table.
        /// </summary>
        /// <param name="caller">The IWin32Window this form will display in front of.</param>
        /// <param name="formTitle">Title of this form.</param>
        /// <param name="connectionString">A valid connection string.</param>
        public void AddNewRecord(System.Windows.Forms.IWin32Window caller, string formTitle, string connectionString)
        {
            this.Text = formTitle;

            this.lastKnownConnectionType = Bob.DataClasses.ConnectionType.ConnectionString;
            this.connectionString        = connectionString;

            RequestForeignTables();
            EmptyControls();

            this.Control_Description.HandleTextChanged(null, null);
            this.Control_GeneralUnitCost.HandleTextChanged(null, null);

            Check_cmdOK_Button(null);

            ProcessHiddenAndDisabledControlStatus(true);

            this.ShowDialog(caller);
        }
        /// <summary>
        /// Allows you to update an existing record from the Title table.
        /// </summary>
        /// <param name="caller">The IWin32Window this form will display in front of.</param>
        /// <param name="formTitle">Title of this form.</param>
        /// <param name="sqlConnection">A valid System.Data.SqlClient.SqlConnection.</param>
        /// <param name="id">Primary key of the record to update.</param>
        /// <returns>
        /// Returns True if the record was found. Returns False otherwise
        /// (no form is displayed in this case).
        /// </returns>
        public bool EditExistingRecord(System.Windows.Forms.IWin32Window caller, string formTitle, System.Data.SqlClient.SqlConnection sqlConnection, System.Data.SqlTypes.SqlInt32 id)
        {
            this.Text = formTitle;

            this.lastKnownConnectionType = Bob.DataClasses.ConnectionType.SqlConnection;
            this.sqlConnection           = sqlConnection;
            this.currentID = id;

            RequestForeignTables();
            EmptyControls();

            if (!RefreshCurrentRecord())
            {
                return(false);
            }

            Check_cmdOK_Button(null);

            ProcessHiddenAndDisabledControlStatus(false);

            this.ShowDialog(caller);

            return(true);
        }