Example #1
0
        private void UpdateRecordInDatabase()
        {
            Params.spU_JobPartType Param = new Params.spU_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;
            }

            Param.Param_JobPartTypeId = this.currentID;

            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.spU_JobPartType SP = new SPs.spU_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 update this record:\r\n\r\n" + Param.SqlException.Message, "Error");
                }
                else
                {
                    throw new Bob.DataClasses.CustomException(Param, "Bob.Windows.Forms.WinForm_JobPartType", "UpdateRecordInDatabase");
                }
            }
        }
Example #2
0
        /// <summary>
        /// [To be supplied.]
        /// </summary>
        public void Update()
        {
            if (!this.recordWasLoadedFromDB)
            {
                throw new ArgumentException("No record was loaded from the database. No update is possible.");
            }

            bool ChangesHaveBeenMade = false;

            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_DescriptionWasUpdated);
            ChangesHaveBeenMade = (ChangesHaveBeenMade || col_GeneralUnitCostWasUpdated);

            if (!ChangesHaveBeenMade)
            {
                return;
            }

            bool alreadyOpened = false;

            Params.spU_JobPartType Param = new Params.spU_JobPartType(true);
            Param.CommandTimeOut = this.updateCommandTimeOut;
            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 = this.col_JobPartTypeId;

            if (this.col_DescriptionWasUpdated)
            {
                Param.Param_Description = this.col_Description;
                Param.Param_ConsiderNull_Description = true;
            }
            else
            {
                Param.Param_Description = SqlString.Null;
                Param.Param_ConsiderNull_Description = false;
            }

            if (this.col_GeneralUnitCostWasUpdated)
            {
                Param.Param_GeneralUnitCost = this.col_GeneralUnitCost;
                Param.Param_ConsiderNull_GeneralUnitCost = true;
            }
            else
            {
                Param.Param_GeneralUnitCost = SqlMoney.Null;
                Param.Param_ConsiderNull_GeneralUnitCost = false;
            }

            SPs.spU_JobPartType Sp = new SPs.spU_JobPartType(false);
            if (Sp.Execute(ref Param))
            {
                this.col_DescriptionWasUpdated     = false;
                this.col_GeneralUnitCostWasUpdated = false;
            }
            else
            {
                throw new Bob.DataClasses.CustomException(Param, "Bob.BusinessComponents.JobPartType_Record", "Update");
            }
            CloseConnection(Sp.Connection, alreadyOpened);
        }