static void Read(List <modelokaler> modelokalers) { Console.WriteLine("angiv id for den onskede lokale(int):"); String input = Console.ReadLine(); int i = Convert.ToInt32(input); modelokaler reading = modelokalers.Where(g => g.Id == i).First(); Console.WriteLine("id:" + reading.Id + " navn:" + reading.Navn + " lokation:" + reading.Lokation + " plads antal:" + reading.Pladsantal); }
static void Delete(List <modelokaler> modelokalers, Connect con) { Console.WriteLine("angiv id for den der skal slettes(int):"); String input = Console.ReadLine(); int i = Convert.ToInt32(input); modelokaler reading = modelokalers.Where(g => g.Id == i).First(); Console.WriteLine("id:" + reading.Id + " navn:" + reading.Navn + " lokation:" + reading.Lokation + " plads antal:" + reading.Pladsantal); Console.WriteLine("sikker y/n"); if (Console.ReadLine() == "y") { con.DeleteServer(i); } }
static void Update(List <modelokaler> modelokalers, Connect con) { Console.WriteLine("angiv id for den onskede lokale(int):"); String input = Console.ReadLine(); int i = Convert.ToInt32(input); modelokaler reading = modelokalers.Where(g => g.Id == i).First(); Console.WriteLine("id:" + reading.Id + " navn:" + reading.Navn + " lokation:" + reading.Lokation + " plads antal:" + reading.Pladsantal); Console.WriteLine("Indtast nyt navn(string):"); String n = Console.ReadLine(); Console.WriteLine("Indtast nyt lokation(string):"); String l = Console.ReadLine(); Console.WriteLine("Indtast nye antal pladser(int):"); String p = Console.ReadLine(); con.UpdateServer(new modelokaler(i, n, l, Convert.ToInt32(p))); }
string connetionString = "Data Source = ERA; Initial Catalog = meeting; Integrated Security = True"; //lokal database. public bool AddToServer(modelokaler modelokaler) { SqlConnection cnn; cnn = new SqlConnection(connetionString); try { string query = "INSERT INTO modelokale (id, navn, lokation, pladsantal) values(" + modelokaler.Id + ", " + "'" + modelokaler.Navn + "'" + ", " + "'" + modelokaler.Lokation + "'" + ", " + modelokaler.Pladsantal + ")"; cnn.Open(); using (cnn) { SqlCommand command = new SqlCommand(query, cnn); command.ExecuteNonQuery(); } cnn.Close(); Console.WriteLine("done"); } catch (Exception ex) { Console.WriteLine("Can not open connection ! -add " + ex); } return(true); }
public bool UpdateServer(modelokaler modelokaler) { SqlConnection cnn; cnn = new SqlConnection(connetionString); try { string query = "update modelokale set navn = '" + modelokaler.Navn + "'" + ", lokation = " + "'" + modelokaler.Lokation + "'" + ", Pladsantal = " + modelokaler.Pladsantal + "where id = " + modelokaler.Id; cnn.Open(); using (cnn) { SqlCommand command = new SqlCommand(query, cnn); command.ExecuteNonQuery(); } cnn.Close(); Console.WriteLine("done"); } catch (Exception ex) { Console.WriteLine("Can not open connection ! -add " + ex); } return(true); }