예제 #1
0
        private void AddCancellation()
        {
            int count;

            if (!int.TryParse(txtCount.Text, out count))
                throw new Exception("Die eingegebene Anzahl ist ungültig.");

            if (cmbArticle.SelectedItem == null)
                throw new Exception("Es muss ein Artikel ausgewählt werden.");

            templ = new CancellationTemplate();
            templ.Article = (Article)cmbArticle.SelectedItem;
            templ.User = (User)cmbUser.SelectedItem;
            templ.Count = count;

            Cancellation c = templ.Create();
            ((Profile)cmbProfile.SelectedItem).Cancellations.Add(c);

            cmbArticle.SelectedIndex = -1;
        }
예제 #2
0
        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;
        }