private void AddRecordInDatabase() { Params.spI_Title Param = new Params.spI_Title(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_Title.Text.Trim() != String.Empty) { Param.Param_Title = (System.Data.SqlTypes.SqlString)Control_Title.GetSqlTypesValue; } SPs.spI_Title SP = new SPs.spI_Title(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_Title", "AddRecordInDatabase"); } } }
/// <summary> /// [To be supplied.] /// </summary> /// <param name="record">[To be supplied.]</param> /// <returns>[To be supplied.]</returns> public IBusinessComponentRecord Add(IBusinessComponentRecord record) { Title recordToAdd = record as Title; if (recordToAdd == null) { throw new ArgumentException("Invalid record type. Must be 'Bob.BusinessComponents.Title'.", "record"); } bool alreadyOpened = false; Params.spI_Title Param = new Params.spI_Title(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_TitleId = recordToAdd.TitleId; Param.Param_Title = recordToAdd.TitleDescription; SPs.spI_Title Sp = new SPs.spI_Title(false); if (Sp.Execute(ref Param)) { Title newRecord = null; switch (this.lastKnownConnectionType) { case Bob.DataClasses.ConnectionType.ConnectionString: newRecord = new Title(this.connectionString, Param.Param_TitleId); break; case Bob.DataClasses.ConnectionType.SqlConnection: newRecord = new Title(this.sqlConnection, Param.Param_TitleId); break; case Bob.DataClasses.ConnectionType.SqlTransaction: newRecord = new Title(this.sqlTransaction, Param.Param_TitleId); 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.Titles", "Add"); } }