/// <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_Cat_StrNameWasUpdated); if (!ChangesHaveBeenMade) { return; } bool alreadyOpened = false; Params.spU_tblCategory Param = new Params.spU_tblCategory(true); Param.CommandTimeOut = this.updateCommandTimeOut; switch (this.lastKnownConnectionType) { case OlymarsDemo.DataClasses.ConnectionType.ConnectionString: Param.SetUpConnection(this.connectionString); break; case OlymarsDemo.DataClasses.ConnectionType.SqlConnection: Param.SetUpConnection(this.sqlConnection); alreadyOpened = (this.sqlConnection.State == System.Data.ConnectionState.Open); break; case OlymarsDemo.DataClasses.ConnectionType.SqlTransaction: Param.SetUpConnection(this.sqlTransaction); break; } Param.Param_Cat_LngID = this.col_Cat_LngID; if (this.col_Cat_StrNameWasUpdated) { Param.Param_Cat_StrName = this.col_Cat_StrName; Param.Param_ConsiderNull_Cat_StrName = true; } else { Param.Param_Cat_StrName = SqlString.Null; Param.Param_ConsiderNull_Cat_StrName = false; } SPs.spU_tblCategory Sp = new SPs.spU_tblCategory(false); if (Sp.Execute(ref Param)) { this.col_Cat_StrNameWasUpdated = false; } else { throw new OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.BusinessComponents.Category", "Update"); } CloseConnection(Sp.Connection, alreadyOpened); }
private void UpdateRecordInDatabase() { Params.spU_tblCategory Param = new Params.spU_tblCategory(false); switch (this.lastKnownConnectionType) { case OlymarsDemo.DataClasses.ConnectionType.ConnectionString: Param.SetUpConnection(this.connectionString); break; case OlymarsDemo.DataClasses.ConnectionType.SqlConnection: Param.SetUpConnection(this.sqlConnection); break; } Param.Param_Cat_LngID = this.currentID; if (Control_Cat_StrName.Text.Trim() != String.Empty) { Param.Param_Cat_StrName = (System.Data.SqlTypes.SqlString)Control_Cat_StrName.GetSqlTypesValue; } SPs.spU_tblCategory SP = new SPs.spU_tblCategory(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 OlymarsDemo.DataClasses.CustomException(Param, "OlymarsDemo.Windows.Forms.WinForm_tblCategory", "UpdateRecordInDatabase"); } } }
public void Execute(WSInt32 Cat_LngID, WSString Cat_StrName, WSBoolean ConsiderNull_Cat_StrName) { Params.spU_tblCategory param = new Params.spU_tblCategory(true); param.SetUpConnection(string.Empty); if (Cat_LngID == null || Cat_LngID.UseNull) { param.Param_Cat_LngID = SqlInt32.Null; } else if (!Cat_LngID.UseDefault) { param.Param_Cat_LngID = Cat_LngID.Value; } if (Cat_StrName == null || Cat_StrName.UseNull) { param.Param_Cat_StrName = SqlString.Null; } else if (!Cat_StrName.UseDefault) { param.Param_Cat_StrName = Cat_StrName.Value; } if (ConsiderNull_Cat_StrName == null || ConsiderNull_Cat_StrName.UseNull) { param.Param_ConsiderNull_Cat_StrName = SqlBoolean.Null; } else if (!ConsiderNull_Cat_StrName.UseDefault) { param.Param_ConsiderNull_Cat_StrName = ConsiderNull_Cat_StrName.Value; } using (SPs.spU_tblCategory sp = new SPs.spU_tblCategory(true)) { sp.Execute(ref param); param.Dispose(); } }
public void Edit_Category(Tables.Category record) { Params.spU_tblCategory param = new Params.spU_tblCategory(false); param.SetUpConnection(string.Empty); param.Param_Cat_LngID = record.Col_Cat_LngID.Value; if (record.Col_Cat_StrName == null || record.Col_Cat_StrName.UseNull) { param.Param_ConsiderNull_Cat_StrName = true; param.Param_Cat_StrName = SqlString.Null; } else if (!record.Col_Cat_StrName.UseDefault) { param.Param_Cat_StrName = record.Col_Cat_StrName.Value; } using (SPs.spU_tblCategory sp = new SPs.spU_tblCategory(true)) { sp.Execute(ref param); param.Dispose(); } }
private void cmdUpdate_Click(object sender, System.EventArgs e) { if (!CheckValues()) { return; } if (Action == ActionEnum.Edit) { Params.spU_tblCategory Param = null; SPs.spU_tblCategory SP = null; Param = new Params.spU_tblCategory(); Param.SetUpConnection(ConnectionString); Param.Param_Cat_LngID = CurrentID; if (txt_Cat_StrName.Text.Trim() != String.Empty) { Param.Param_Cat_StrName = new System.Data.SqlTypes.SqlString(txt_Cat_StrName.Text); } SP = new SPs.spU_tblCategory(); if (SP.Execute(ref Param)) { if (ReturnURL.Visible) { Response.Redirect(String.Format("WebForm_tblCategory.aspx?Action=Edit&ID={0}&ReturnToUrl={1}&ReturnToDisplay={2}", CurrentID.ToString(), ReturnURL.NavigateUrl, ReturnURL.Text)); } else { Response.Redirect(String.Format("WebForm_tblCategory.aspx?Action=Edit&ID={0}", CurrentID.ToString())); } return; } else { if (Param.SqlException != null) { throw Param.SqlException; } if (Param.OtherException != null) { throw Param.OtherException; } } } else { Params.spI_tblCategory Param = null; SPs.spI_tblCategory SP = null; Param = new Params.spI_tblCategory(); Param.SetUpConnection(ConnectionString); if (txt_Cat_StrName.Text.Trim() != String.Empty) { Param.Param_Cat_StrName = new System.Data.SqlTypes.SqlString(txt_Cat_StrName.Text); } SP = new SPs.spI_tblCategory(); if (SP.Execute(ref Param)) { if (ReturnURL.Visible) { Response.Redirect(String.Format("WebForm_tblCategory.aspx?Action=Edit&ID={0}&ReturnToUrl={1}&ReturnToDisplay={2}", Param.Param_Cat_LngID.ToString(), ReturnURL.NavigateUrl, ReturnURL.Text)); } else { Response.Redirect(String.Format("WebForm_tblCategory.aspx?Action=Edit&ID={0}", Param.Param_Cat_LngID.ToString())); } return; } else { if (Param.SqlException != null) { throw Param.SqlException; } if (Param.OtherException != null) { throw Param.OtherException; } } } }