protected void BtnVoegToe_Click(object sender, EventArgs e) { bool success = false; int parentCat = db.GetCategorieInfo(ddlSubcategorieVan.SelectedItem.ToString()).CategorieID; if(txtCategorienaam.Text != string.Empty && txtOmschrijving.Text != string.Empty) { Categorie newCat = new Categorie() { Omschrijving = txtOmschrijving.Text, Categorienaam = txtCategorienaam.Text, SubcategorieVan = parentCat }; success = db.AddNewCategory(newCat); } if (success) { Page.ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('De categorie is succesvol toegevoegd!');", true); Response.AddHeader("REFRESH", "0;URL=Home.aspx"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('De categorie kon niet toegevoegd worden. Probeer het opnieuw of contacteer de webmaster.');", true); Response.AddHeader("REFRESH", "0;URL=Home.aspx"); } }
public bool AddNewCategory(Categorie newCat) { bool success = false; int newCatId = 0; connection.Open(); OracleCommand command = new OracleCommand(); command.Connection = connection; command.CommandText = "SELECT MAX(CATEGORIEID) FROM CATEGORIE"; newCatId = (int)((decimal)command.ExecuteScalar() + 1); newCat.CategorieID = newCatId; command.CommandText = "INSERT INTO CATEGORIE VALUES (:id, :naam, :omschrijving, :parent)"; OracleParameter parID = new OracleParameter("id", newCat.CategorieID); OracleParameter parNaam = new OracleParameter("naam", newCat.Categorienaam); OracleParameter parOmschrijving = new OracleParameter("omschrijving", newCat.Omschrijving); OracleParameter parParent = new OracleParameter("parent", newCat.SubcategorieVan); command.Parameters.Add(parID); command.Parameters.Add(parNaam); command.Parameters.Add(parOmschrijving); command.Parameters.Add(parParent); try { if (command.ExecuteNonQuery() == 1) { success = true; } } catch (OracleException ex) { Console.WriteLine("Record is not inserted into the database table."); Console.WriteLine("Exception Message: " + ex.Message); Console.WriteLine("Exception Source: " + ex.Source); } finally { connection.Close(); } return success; }
public List<Verzamelobject> GetCategoryCollection(Categorie category) { List<Verzamelobject> objects = new List<Verzamelobject>(); connection.Open(); OracleCommand command = new OracleCommand("SELECT * FROM OBJECT WHERE CATEGORIEID = :catid", connection); OracleParameter parCatID = new OracleParameter("catid", category.CategorieID); command.Parameters.Add(parCatID); OracleDataReader reader; try { reader = command.ExecuteReader(); while (reader.Read()) { Verzamelobject newObject = new Verzamelobject(); newObject.ObjectID = (int)reader["OBJECTID"]; newObject.CategorieID = (int)reader["CATEGORIEID"]; newObject.Omschrijving = (string)reader["OMSCHRIJVING"]; if (reader["LAND"] != DBNull.Value) { newObject.Land = (string)reader["LAND"]; } else { newObject.Land = null; } newObject.DatumToegevoegd = (DateTime)reader["DATUMTOEGEVOEGD"]; newObject.LaatsteWijziging = (DateTime)reader["DATUMLAATSTEWIJZIGING"]; if (reader["IDENTIFICATIECODE"] != DBNull.Value) { newObject.Identificatiecode = (string)reader["IDENTIFICATIECODE"]; } else { newObject.Identificatiecode = null; } if (reader["JAARTAL"] != DBNull.Value) { newObject.Jaartal = (string)reader["JAARTAL"]; } else { newObject.Jaartal = null; } objects.Add(newObject); } connection.Close(); reader.Close(); return objects; } catch (OracleException ex) { Console.WriteLine("Record is not inserted into the database table."); Console.WriteLine("Exception Message: " + ex.Message); Console.WriteLine("Exception Source: " + ex.Source); return null; } }
public Categorie GetCategorieInfo(int iD) { OracleDataReader reader; connection.Open(); OracleCommand command = new OracleCommand("SELECT * FROM CATEGORIE WHERE CATEGORIEID = :id", connection); OracleParameter parCatID = new OracleParameter("id", iD); command.Parameters.Add(parCatID); reader = command.ExecuteReader(); reader.Read(); Categorie selectedCategory = new Categorie() { CategorieID = (int)reader["CATEGORIEID"], Categorienaam = (string)reader["CATEGORIENAAM"] }; if (reader["SUBCATEGORIEVAN"] != DBNull.Value) { selectedCategory.SubcategorieVan = (int)reader["SUBCATEGORIEVAN"]; } else { selectedCategory.SubcategorieVan = 0; } if (reader["OMSCHRIJVING"] != DBNull.Value) { selectedCategory.Omschrijving = (string)reader["OMSCHRIJVING"]; } else { selectedCategory.Omschrijving = string.Empty; } connection.Close(); reader.Close(); return selectedCategory; }
public bool VoegCategorieToe(Categorie nieuweCategorie) { return false; }