private void UpdateRecordInDatabase() { Params.spU_Job Param = new Params.spU_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; } Param.Param_JobId = this.currentID; 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.spU_Job SP = new SPs.spU_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 update this record:\r\n\r\n" + Param.SqlException.Message, "Error"); } else { throw new Bob.DataClasses.CustomException(Param, "Bob.Windows.Forms.WinForm_Job", "UpdateRecordInDatabase"); } } }
/// <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_PriceWasUpdated); ChangesHaveBeenMade = (ChangesHaveBeenMade || col_StartDateWasUpdated); ChangesHaveBeenMade = (ChangesHaveBeenMade || col_EndDateWasUpdated); ChangesHaveBeenMade = (ChangesHaveBeenMade || col_CustomerIdWasUpdated); if (!ChangesHaveBeenMade) { return; } bool alreadyOpened = false; Params.spU_Job Param = new Params.spU_Job(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_JobId = this.col_JobId; 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_PriceWasUpdated) { Param.Param_Price = this.col_Price; Param.Param_ConsiderNull_Price = true; } else { Param.Param_Price = SqlMoney.Null; Param.Param_ConsiderNull_Price = false; } if (this.col_StartDateWasUpdated) { Param.Param_StartDate = this.col_StartDate; Param.Param_ConsiderNull_StartDate = true; } else { Param.Param_StartDate = SqlDateTime.Null; Param.Param_ConsiderNull_StartDate = false; } if (this.col_EndDateWasUpdated) { Param.Param_EndDate = this.col_EndDate; Param.Param_ConsiderNull_EndDate = true; } else { Param.Param_EndDate = SqlDateTime.Null; Param.Param_ConsiderNull_EndDate = false; } if (this.col_CustomerIdWasUpdated) { Param.Param_CustomerId = this.col_CustomerId; Param.Param_ConsiderNull_CustomerId = true; } else { Param.Param_CustomerId = SqlInt32.Null; Param.Param_ConsiderNull_CustomerId = false; } SPs.spU_Job Sp = new SPs.spU_Job(false); if (Sp.Execute(ref Param)) { this.col_DescriptionWasUpdated = false; this.col_PriceWasUpdated = false; this.col_StartDateWasUpdated = false; this.col_EndDateWasUpdated = false; this.col_CustomerIdWasUpdated = false; } else { throw new Bob.DataClasses.CustomException(Param, "Bob.BusinessComponents.Job_Record", "Update"); } CloseConnection(Sp.Connection, alreadyOpened); }