예제 #1
0
        private void AddRecordInDatabase()
        {
            Params.spI_Job Param = new Params.spI_Job(false);

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

            case Bob.DataClasses.ConnectionType.SqlConnection:
                Param.SetUpConnection(this.sqlConnection);
                break;
            }

            if (Control_Description.Text.Trim() != String.Empty)
            {
                Param.Param_Description = (System.Data.SqlTypes.SqlString)Control_Description.GetSqlTypesValue;
            }

            if (Control_Price.Text.Trim() != String.Empty)
            {
                Param.Param_Price = (System.Data.SqlTypes.SqlMoney)Control_Price.GetSqlTypesValue;
            }

            if (Control_StartDate.Text.Trim() != String.Empty)
            {
                Param.Param_StartDate = (System.Data.SqlTypes.SqlDateTime)Control_StartDate.GetSqlTypesValue;
            }

            if (Control_EndDate.Text.Trim() != String.Empty)
            {
                Param.Param_EndDate = (System.Data.SqlTypes.SqlDateTime)Control_EndDate.GetSqlTypesValue;
            }

            if (Control_CustomerId.SelectedIndex != -1)
            {
                Param.Param_CustomerId = (System.Int32)Control_CustomerId.SelectedValue;
            }

            SPs.spI_Job SP = new SPs.spI_Job(false);

            if (SP.Execute(ref Param))
            {
                this.parameter       = Param;
                this.errorHasOccured = false;
            }
            else
            {
                this.errorHasOccured = true;
                if (Param.SqlException != null && Param.SqlException.Number == 2627)
                {
                    MessageBox.Show(this, "Unable to add this record:\r\n\r\n" + Param.SqlException.Message, "Error");
                }
                else
                {
                    throw new Bob.DataClasses.CustomException(Param, "Bob.Windows.Forms.WinForm_Job", "AddRecordInDatabase");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        /// <param name="record">[To be supplied.]</param>
        /// <returns>[To be supplied.]</returns>
        public IBusinessComponentRecord Add(IBusinessComponentRecord record)
        {
            Job_Record recordToAdd = record as Job_Record;

            if (recordToAdd == null)
            {
                throw new ArgumentException("Invalid record type. Must be 'Bob.BusinessComponents.Job_Record'.", "record");
            }

            switch (this.parentType)
            {
            case Job_CollectionParentType.Col_CustomerId:
                recordToAdd.Col_CustomerId = ((Customer)this.parent).CustomerID;
                break;
            }

            bool alreadyOpened = false;

            Params.spI_Job Param = new Params.spI_Job(true);
            Param.CommandTimeOut = this.insertCommandTimeOut;
            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_JobId       = recordToAdd.Col_JobId;
            Param.Param_Description = recordToAdd.Col_Description;
            Param.Param_Price       = recordToAdd.Col_Price;
            Param.Param_StartDate   = recordToAdd.Col_StartDate;
            Param.Param_EndDate     = recordToAdd.Col_EndDate;
            Param.Param_CustomerId  = recordToAdd.Col_CustomerId;

            SPs.spI_Job Sp = new SPs.spI_Job(false);
            if (Sp.Execute(ref Param))
            {
                Job_Record newRecord = null;

                switch (this.lastKnownConnectionType)
                {
                case Bob.DataClasses.ConnectionType.ConnectionString:
                    newRecord = new Job_Record(this.connectionString, Param.Param_JobId);
                    break;

                case Bob.DataClasses.ConnectionType.SqlConnection:
                    newRecord = new Job_Record(this.sqlConnection, Param.Param_JobId);
                    break;

                case Bob.DataClasses.ConnectionType.SqlTransaction:
                    newRecord = new Job_Record(this.sqlTransaction, Param.Param_JobId);
                    break;
                }

                CloseConnection(Sp.Connection, alreadyOpened);

                if (internalRecords != null)
                {
                    internalRecords.Add(newRecord);
                }

                if (this.addedRecords == null)
                {
                    this.addedRecords = new System.Collections.ArrayList();
                }
                this.addedRecords.Add(newRecord);

                return(newRecord);
            }
            else
            {
                throw new Bob.DataClasses.CustomException(Param, "Bob.BusinessComponents.Job_Collection", "Add");
            }
        }