public void Update(TramOnderhoud maintenance)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "UPDATE TRAM_ONDERHOUD " +
                              "SET" +
                              " BeschikbaarDatum=@maintainedDate," +
                              " DatumTijdstip=@scheduledDate," +
                              " Medewerker_ID=@medewerkerId," +
                              " Tram_ID=@tramId," +
                              " ONDERHOUDSTYPEID=@priorityId" +
                              " [OnderhoudsBeschrijving]=@beschrijving" +
                              " WHERE TRAM_ONDERHOUD.ID = @id";
            cmd.Parameters.AddWithValue("@id", maintenance.Id);
            if (maintenance.MedewerkerId != null)
            {
                cmd.Parameters.AddWithValue("@medewerkerId", maintenance.MedewerkerId);
            }
            else
            {
                cmd.Parameters.AddWithValue("@medewerkerId", DBNull.Value);
            }
            if (maintenance.TramId != null)
            {
                cmd.Parameters.AddWithValue("@tramId", maintenance.TramId);
            }
            else
            {
                cmd.Parameters.AddWithValue("@tramId", DBNull.Value);
            }
            if (maintenance.DatumTijdstip != null)
            {
                cmd.Parameters.AddWithValue("@scheduledDate", maintenance.DatumTijdstip);
            }
            else
            {
                cmd.Parameters.AddWithValue("@scheduledDate", DBNull.Value);
            }
            if (maintenance.BeschikbaarDatum != null)
            {
                cmd.Parameters.AddWithValue("@maintainedDate", maintenance.BeschikbaarDatum);
            }
            else
            {
                cmd.Parameters.AddWithValue("@maintainedDate", DBNull.Value);
            }
            if (maintenance.OnderhoudsBeschrijving != null)
            {
                cmd.Parameters.AddWithValue("@beschrijving", maintenance.OnderhoudsBeschrijving);
            }
            else
            {
                cmd.Parameters.AddWithValue("@beschrijving", DBNull.Value);
            }
            cmd.Parameters.AddWithValue("@priorityId", maintenance.Onderhoudstypeid);
            DatabaseManager.connector.NonQuery(cmd);
        }
        public void Delete(TramOnderhoud maintenance)
        {
            Maintenances.Remove(maintenance);
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "DELETE FROM TRAM_ONDERHOUD" +
                              " WHERE TRAM_ONDERHOUD.ID = @id";
            cmd.Parameters.AddWithValue("@id", maintenance.Id);
            DatabaseManager.connector.NonQuery(cmd);
            //todo: what if maint doesnt exist?
        }
        public void Create(TramOnderhoud maintenance)
        {
            Maintenances.Add(maintenance);
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "INSERT INTO TRAM_ONDERHOUD (BeschikbaarDatum, DatumTijdstip, Tram_ID, ONDERHOUDSTYPEID, Medewerker_ID, [OnderhoudsBeschrijving])" +
                              " VALUES(@maintainedDate, @scheduledDate, @tramId, @priorityId, @employeeId, @beschrijving)";
            if (maintenance.BeschikbaarDatum != null)
            {
                cmd.Parameters.AddWithValue("@maintainedDate", maintenance.BeschikbaarDatum);
            }
            else
            {
                cmd.Parameters.AddWithValue("@maintainedDate", DBNull.Value);
            }
            if (maintenance.DatumTijdstip != null)
            {
                cmd.Parameters.AddWithValue("@scheduledDate", maintenance.DatumTijdstip);
            }
            else
            {
                cmd.Parameters.AddWithValue("@scheduledDate", DBNull.Value);
            }
            if (maintenance.TramId != null)
            {
                cmd.Parameters.AddWithValue("@tramId", maintenance.TramId);
            }
            else
            {
                cmd.Parameters.AddWithValue("@tramId", DBNull.Value);
            }

            cmd.Parameters.AddWithValue("@priorityId", maintenance.Onderhoudstypeid);

            if (maintenance.MedewerkerId != null)
            {
                cmd.Parameters.AddWithValue("@employeeId", maintenance.MedewerkerId);
            }
            else
            {
                cmd.Parameters.AddWithValue("@employeeId", DBNull.Value);
            }
            if (maintenance.OnderhoudsBeschrijving != null)
            {
                cmd.Parameters.AddWithValue("@beschrijving", maintenance.OnderhoudsBeschrijving);
            }
            else
            {
                cmd.Parameters.AddWithValue("@beschrijving", DBNull.Value);
            }
            DatabaseManager.connector.NonQuery(cmd);
        }
        public List <TramOnderhoud> GetAll()
        {
            Maintenances = new List <TramOnderhoud>();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "Select * " +
                              "FROM TRAM_ONDERHOUD";
            using (DatabaseManager.connector)
            {
                using (DbDataReader reader = DatabaseManager.connector.Query(cmd))
                {
                    while (reader.Read())
                    {
                        TramOnderhoud maintenance = new TramOnderhoud();
                        maintenance.Id = reader.GetDecimal(0);
                        if (!reader.IsDBNull(1))
                        {
                            maintenance.MedewerkerId = reader.GetDecimal(1);
                        }
                        else
                        {
                            maintenance.MedewerkerId = null;
                        }
                        if (!reader.IsDBNull(2))
                        {
                            maintenance.TramId = reader.GetDecimal(2);
                        }
                        else
                        {
                            maintenance.TramId = null;
                        }
                        if (!reader.IsDBNull(3))
                        {
                            maintenance.DatumTijdstip = reader.GetDateTime(3);
                        }
                        else
                        {
                            maintenance.DatumTijdstip = null;
                        }
                        if (!reader.IsDBNull(4))
                        {
                            maintenance.BeschikbaarDatum = reader.GetDateTime(4);
                        }
                        else
                        {
                            maintenance.BeschikbaarDatum = null;
                        }
                        maintenance.Onderhoudstypeid = reader.GetInt32(5);
                        if (!reader.IsDBNull(6))
                        {
                            maintenance.OnderhoudsBeschrijving = reader.GetString(6);
                        }
                        else
                        {
                            maintenance.OnderhoudsBeschrijving = null;
                        }
                        Maintenances.Add(maintenance);
                    }
                }
            }
            return(Maintenances);
        }
 public void Update(TramOnderhoud maintenance)
 {
 }
 public void Create(TramOnderhoud maintenance)
 {
     Maintenances.Add(maintenance);
 }
 public void Delete(TramOnderhoud maintenance)
 {
     Maintenances.Remove(maintenance);
 }