public void TheApp() { DBUtil utilitiy = new DBUtil(); City city1 = new City("8200", "Aarhus N", "Danmark"); utilitiy.AddCityDB(ref city1); // Tilføjer city1 til databasen Adresse adresse1 = new Adresse("Gyldenløvesgade", "6, 2 sal th", city1); utilitiy.AddAdresseDB(ref adresse1); // Tilføjer adresse1 til databasen Emailadresse email1 = new Emailadresse() { Email = "*****@*****.**", EmailID = 7 }; Operatoer operatør1 = new Operatoer() { Selskab = "TDC" }; Telefon telefon1 = new Telefon(20668161, operatør1); Note note1 = new Note() { Noten = "Studerende på AU", NoteID = 2 }; Person person1 = new Person("Simon", "Møller", "Hindkaer", "Mand", adresse1); utilitiy.AddPersonDB(ref person1); // Tilføjer person1 til databasen //utilitiy.AddEmailDB(ref email1); // Tilføjer email1 til databasen //utilitiy.AddTelefonDB(ref telefon1); // Tilføjer telefon1 til databasen //utilitiy.AddNoteDB(ref note1); // Tilføjer note1 til databasen //utilitiy.AddOperatoerDB(ref operatør1); // Tilføjer operatør1 til databasen //email1.Email = "*****@*****.**"; //utilitiy.UpdateEmailDB(ref email1); //Opdaterer email1 //utilitiy.DeleteAdresseDB(ref adresse1); // Sletter adresse1 //utilitiy.DeleteCityDB(ref city1); // Sletter city1 //utilitiy.DeleteEmailDB(ref email1); // Sletter email1 //utilitiy.DeleteTelefonDB(ref telefon1); // Sletter telefon1 //utilitiy.DeleteNoteDB(ref note1); // Sletter note1 //utilitiy.DeleteOperatoerDB(ref operatør1); // Sletter operatør1 //utilitiy.GetPerson(); // Viser alle personer i databasen //utilitiy.GetAdresse(); // Viser alle adresser i databasen //utilitiy.GetCity(); // Viser alle byer i databasen //utilitiy.GetEmail(); // Viser alle emails i databasen //utilitiy.GetTelefon(); // Viser alle telefoner i databasen //utilitiy.GetNoter(); // Viser alle noter i databasen //utilitiy.GetOperatoer(); // Viser alle operatører i databasen }
public void DeleteEmailadresse(ref Emailadresse ee) { string deleteString = @"DELETE FROM EmailAdresse WHERE (EmailID = @EmailID)"; using (SqlCommand cmd = new SqlCommand(deleteString, openConnection)) { cmd.Parameters.AddWithValue("@EmailID", ee.EmailID); var id = cmd.ExecuteNonQuery(); ee = null; } }
public void UpdateEmailadresse(ref Emailadresse ee) { string insertStringParam = @"UPDATE Emailadresse SET Email = @Email WHERE EmailID = @EmailID"; using (SqlCommand cmd = new SqlCommand(insertStringParam, openConnection)) { cmd.Parameters.AddWithValue("@Email", ee.Email); cmd.ExecuteNonQuery(); } }
public void DeleteEmailDB(ref Emailadresse e) // Sletter en eksisterende Email { string deleteString = @"DELETE FROM Emailadresse WHERE (EmailID = @EmailID)"; using (SqlCommand cmd = new SqlCommand(deleteString, openConnection)) { cmd.Parameters.AddWithValue("@EmailID", e.Email); var id = (long)cmd.ExecuteNonQuery(); e = null; } }
public void AddEmailDB(ref Emailadresse e) // Tilføjer en e-mail adresse { string insertStringParam = @"INSERT INTO [Emailadresse] (Email, Person) OUTPUT INSERTED.EmailID VALUES (@Email, @Person)"; using (SqlCommand cmd = new SqlCommand(insertStringParam, openConnection)) { cmd.Parameters.AddWithValue("@Email", e.Email); cmd.Parameters.AddWithValue("@Person", e.Person); e.EmailID = (long)cmd.ExecuteScalar(); } }
public void UpdateEmailDB(ref Emailadresse e) // Opdaterer en eksisterende Email { string updateStringParam = @"UPDATE Emailadresse SET Email=@Email, Person=@Person WHERE EmailID=@EmailID"; using (SqlCommand cmd = new SqlCommand(updateStringParam, openConnection)) { // Get your parameters ready cmd.Parameters.AddWithValue("@Email", e.Email); cmd.Parameters.AddWithValue("@Person", e.Person); cmd.Parameters.AddWithValue("@EmailID", e.EmailID); var id = (long)cmd.ExecuteNonQuery(); } }
public void GetEmailadresseByID(ref Emailadresse ee) { string sqlcmd = @"SELECT [Emailadresse] FROM EmailID WHERE ([EmailID] = @EmailID)"; using (var cmd = new SqlCommand(sqlcmd, openConnection)) { cmd.Parameters.AddWithValue("@EmailID", ee.EmailID); SqlDataReader rdr = null; rdr = cmd.ExecuteReader(); if (rdr.Read()) { ee.EmailID = (long)rdr["EmailID"]; } } }
public List <Emailadresse> GetEmail() // Printer en liste af alle de eksisterende Emailadresser { string sqlcmd = @"SELECT * FROM Emailadresse"; using (var cmd = new SqlCommand(sqlcmd, openConnection)) { SqlDataReader rdr = null; rdr = cmd.ExecuteReader(); List <Emailadresse> emaillist = new List <Emailadresse>(); Emailadresse e = null; while (rdr.Read()) { e = new Emailadresse(); e.EmailID = (long)rdr["EmailID"]; e.Person = (long)rdr["Person"]; e.Email = (string)rdr["Email"]; emaillist.Add(e); } return(emaillist); } }