public Klant(DtoKlant DTO) { id = DTO.Id; naam = DTO.Naam; factuurAdres = DTO.FactuurAdres; bezorgAdres = DTO.BezorgAdres; }
public void AddNew(Klant klant) { IDalKlant DAL = DalFactory.CreateKlantDal(); DtoKlant DTO = klant.ToDTO(); DAL.Insert(DTO); }
public DtoKlant GetById(int id) { DtoKlant klant = new DtoKlant(); try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = string.Format("select * from Klant where Id={0}", id); using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DtoKlant newKlant = new DtoKlant { Id = reader.GetInt32(0), Naam = reader.GetString(1), FactuurAdres = reader.SafeGetString(2), BezorgAdres = reader.SafeGetString(3) }; klant = newKlant; } } } } catch (SqlException se) { Console.Write(se.Message); } return(klant); }
public void Update(DtoKlant product) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "UPDATE Klant SET Naam = @naam, FactuurAdres = @facAdd, BezorgAdres = @bezAdd Where Id = @id"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@id", product.Id); command.Parameters.AddWithValue("@naam", product.Naam); command.Parameters.AddWithValue("@facAdd", product.FactuurAdres); command.Parameters.AddWithValue("@bezAdd", product.BezorgAdres); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }
public Klant GetByID(int id) { IDalKlant DAL = DalFactory.CreateKlantDal(); DtoKlant DTO = DAL.GetById(id); Klant klant = new Klant(DTO); return(klant); }
public List <DtoKlant> GetAll() { List <DtoKlant> klanten = new List <DtoKlant>(); try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "select * from Klant"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DtoKlant newKlant = new DtoKlant { Id = reader.GetInt32(0), Naam = reader.GetString(1), FactuurAdres = reader.SafeGetString(2), BezorgAdres = reader.SafeGetString(3) }; klanten.Add(newKlant); } } } } catch (SqlException se) { Console.Write(se.Message); } return(klanten); }
public void Insert(DtoKlant klant) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "insert into Klant ( Naam, FactuurAdres, BezorgAdres) values(@param1,@param2,@param3)"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@param1", klant.Naam); command.Parameters.AddWithValue("@param2", klant.FactuurAdres); command.Parameters.AddWithValue("@param3", klant.BezorgAdres); command.CommandType = CommandType.Text; int rowsAdded = command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }