public static void RemoveCancellation(Cancellation canc) { try { string query = "DELETE Cancellation WHERE CancellationID = " + canc.CancellationId; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Löschen des Stornos.\n\n"; errmsg += "DatabaseHandler.RemoveCancellation(canc): " + ex.ToString(); throw new Exception(errmsg); } }
public static void SaveCancellation(Cancellation canc) { try { string query = "UPDATE [Cancellation] SET UserID = " + canc.User.UserID + ", ArticleID = " + canc.Article.ArticleID + ", ArticleCount = " + canc.Count + ", Created = '" + canc.Created + "'" + " WHERE CancellationID = " + canc.CancellationId; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Speichern der Änderungen des Stornos.\n\n"; errmsg += "DatabaseHandler.SaveCancellation(canc): " + ex.ToString(); throw new Exception(errmsg); } }
public static Cancellation NewCancellation(CancellationTemplate cancTemplate) { Cancellation result = null; try { string query = "INSERT INTO Cancellation (UserID, ArticleID, ArticleCount) VALUES (" + cancTemplate.User.UserID + "," + cancTemplate.Article.ArticleID + "," + cancTemplate.Count + "); "+ "SELECT * FROM Cancellation WHERE CancellationID = SCOPE_IDENTITY();"; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { result = new Cancellation( Convert.ToInt32(reader["CancellationID"]), GetUser(Convert.ToInt32(reader["UserID"])), GetArticle(Convert.ToInt32(reader["ArticleID"])), Convert.ToInt32(reader["ArticleCount"]), Convert.ToDateTime(reader["Created"]) ); } connection.Close(); } catch (Exception ex) { string errmsg = "Fehler beim Erstellen des Stornos.\n\n"; errmsg += "DatabaseHandler.NewCancellation(cancTemplate): " + ex.ToString(); throw new Exception(errmsg); } if (result == null) throw new Exception("Fehler beim Erstellen des Stornos. Das Speichern konnte nicht verifiziert werden.\n\nDatabaseHandler.NewCancellation(cancTemplate)"); return result; }