Esempio n. 1
0
        private void AddRecordInDatabase()
        {
            Params.spI_JobPartType Param = new Params.spI_JobPartType(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_GeneralUnitCost.Text.Trim() != String.Empty)
            {
                Param.Param_GeneralUnitCost = (System.Data.SqlTypes.SqlMoney)Control_GeneralUnitCost.GetSqlTypesValue;
            }

            SPs.spI_JobPartType SP = new SPs.spI_JobPartType(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_JobPartType", "AddRecordInDatabase");
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        /// <param name="record">[To be supplied.]</param>
        /// <returns>[To be supplied.]</returns>
        public IBusinessComponentRecord Add(IBusinessComponentRecord record)
        {
            JobPartType_Record recordToAdd = record as JobPartType_Record;

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

            bool alreadyOpened = false;

            Params.spI_JobPartType Param = new Params.spI_JobPartType(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_JobPartTypeId   = recordToAdd.Col_JobPartTypeId;
            Param.Param_Description     = recordToAdd.Col_Description;
            Param.Param_GeneralUnitCost = recordToAdd.Col_GeneralUnitCost;

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

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

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

                case Bob.DataClasses.ConnectionType.SqlTransaction:
                    newRecord = new JobPartType_Record(this.sqlTransaction, Param.Param_JobPartTypeId);
                    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.JobPartType_Collection", "Add");
            }
        }