private void btn_aanmaken_Click(object sender, EventArgs e) { bool actief = false; bool goedgekeurd = false; Location location = new Location(Convert.ToInt32(nud_X.Value), Convert.ToInt32(nud_Y.Value)); if (cb_typemissie.SelectedText == "SIN") { goedgekeurd = true; actief = true; } Missie newMissie = new Missie(tb_MissieNaam.Text, actief, tb_datumvertrek.Text, tb_datumvertrek.Text, goedgekeurd, location, cb_typemissie.SelectedText); if (administrator.AddMissie(newMissie)) { MessageBox.Show("Missie aangemaakt"); } else { MessageBox.Show("Er is iets Misgegaan"); } }
public static bool AddMissie(Missie m) { using (OracleConnection o = new OracleConnection(connstring)) { using (OracleCommand c = new OracleCommand()) { try { c.Connection = o; o.Open(); if (m as SIN_Missie != null) { c.CommandText = "INSERT INTO TMissie (Beschrijving, Locatie) VALUES ('" + m.Beschrijving + "', '" + m.Locatie + "')"; c.ExecuteNonQuery(); c.CommandText = "SELECT MAX(ID) FROM TMissie"; OracleDataReader dr = c.ExecuteReader(); if (dr.Read()) { c.CommandText = "INSERT INTO TMissie_SIN (ID, Datum, AantalPolitie) VALUES ('" + GetInt(dr[0]) + "', to_date('" + (m as SIN_Missie).Datum + "','DD-MM-RR HH24:MI:SS'), '" + (m as SIN_Missie).AantalPolitie + "')"; c.ExecuteNonQuery(); } } if (m as HOPE_Missie != null) { c.CommandText = "INSERT INTO TMissie (Beschrijving, Locatie) VALUES ('" + m.Beschrijving + "', '" + m.Locatie + "')"; c.ExecuteNonQuery(); c.CommandText = "SELECT MAX(ID) FROM TMissie"; OracleDataReader dr = c.ExecuteReader(); if (dr.Read()) { c.CommandText = "INSERT INTO TMissie_HOPE (ID, GoedkeuringUID, DatumVertrek, DatumTerug) VALUES ('" + GetInt(dr[0]) + "', '" + (m as HOPE_Missie).GoedkeuringUID + "', to_date('" + (m as HOPE_Missie).DatumVertrek + "','DD-MM-RR HH24:MI:SS'), to_date('" + (m as HOPE_Missie).DatumTerug + "','DD-MM-RR HH24:MI:SS'))"; c.ExecuteNonQuery(); } } return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; } finally { o.Close(); } } } }
public static bool UpdateMissie(Missie m) { using (OracleConnection o = new OracleConnection(connstring)) { using (OracleCommand c = new OracleCommand()) { try { c.Connection = o; o.Open(); c.CommandText = "UPDATE TMissie SET Beschrijving = '" + m.Beschrijving + "', Locatie = '" + m.Locatie + "' WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); if (m as SIN_Missie != null) { c.CommandText = "UPDATE TMissie_SIN SET Datum = to_date('" + (m as SIN_Missie).Datum + "','DD-MM-RR HH24:MI:SS'), AantalPolitie = '" + (m as SIN_Missie).AantalPolitie + "' WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); } if (m as HOPE_Missie != null) { c.CommandText = "UPDATE TMissie_HOPE SET GoedkeuringUID = '" + (m as HOPE_Missie).GoedkeuringUID + "', DatumVertrek = to_date('" + (m as HOPE_Missie).DatumVertrek + "','DD-MM-RR HH24:MI:SS'), DatumTerug = to_date('" + (m as HOPE_Missie).DatumTerug + "','DD-MM-RR HH24:MI:SS') WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); } return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; } finally { o.Close(); } } } }
public static bool DeleteMissie(Missie m) { using (OracleConnection o = new OracleConnection(connstring)) { using (OracleCommand c = new OracleCommand()) { try { c.Connection = o; o.Open(); if (m as SIN_Missie != null) { c.CommandText = "DELETE FROM TMissie_SIN WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); } if (m as HOPE_Missie != null) { c.CommandText = "DELETE FROM TMissie_HOPE WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); } c.CommandText = "DELETE FROM TMissie WHERE ID = '" + m.UID + "'"; c.ExecuteNonQuery(); return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; } finally { o.Close(); } } } }
public bool DeleteMissie(Missie m) { return DBConnect.DeleteMissie(m); }
public bool AddMissie(Missie m) { return DBConnect.AddMissie(m); }
public bool UpdateMissie(Missie m) { return DBConnect.UpdateMissie(m); }