Example #1
0
        private void btnInvoerTramNr_Click(object sender, EventArgs e)
        {
            Tram   inrijdtram   = cbTram.SelectedItem as Tram;
            Spoor  inrijdspoor  = cbSpoor.SelectedItem as Spoor;
            Sector inrijdsector = cbSector.SelectedItem as Sector;


            if (inrijdsector != null && inrijdspoor != null && inrijdtram != null)
            {
                if (sectorRepo.CheckTram(inrijdtram) == false)
                {
                    sectorRepo.TramInrijden(inrijdtram, inrijdspoor, inrijdsector);
                    UpdateForm();
                    Simulatie();
                }
                else
                {
                    MessageBox.Show("deze tram moet eerst uitgereden worden");
                }
            }
            else
            {
                MessageBox.Show("Vul alle gegevens in");
            }
        }
Example #2
0
        private Sector CreateSectorFromReader(SqlDataReader reader)
        {
            Spoor s = spoorrepo.GetSpoor(Convert.ToInt16(reader["spoorid"]));

            try
            {
                Tram t = tramrepo.GetTram(Convert.ToInt16(reader["tramid"]));

                return(new Sector(Convert.ToInt32(reader["id"]),
                                  t,
                                  s,
                                  Convert.ToBoolean(reader["blokkade"]),
                                  Convert.ToBoolean(reader["beschikbaarheid"]),
                                  Convert.ToInt16(reader["rownumber"])
                                  ));
            }
            catch
            {
                return(new Sector(Convert.ToInt32(reader["id"]),
                                  s,
                                  Convert.ToBoolean(reader["blokkade"]),
                                  Convert.ToBoolean(reader["beschikbaarheid"]),
                                  Convert.ToInt16(reader["rownumber"])
                                  ));
            }
        }
Example #3
0
 public Sector(int id, Spoor spoor, bool blokkade, bool beschikbaar, int rownumber)
 {
     this.rowNumber   = rownumber;
     this.id          = id;
     this.spoor       = spoor;
     this.Blokkade    = blokkade;
     this.Beschikbaar = beschikbaar;
 }
Example #4
0
        public void TramInrijden(Tram tram, Spoor spoor, Sector sector)
        {
            using (SqlConnection connection = Database.Connection)
            {
                string query = "UPDATE sector SET spoorid= @spoorid,tramid =@tramid  WHERE id = @sectorid";

                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("sectorid", sector.id);
                    command.Parameters.AddWithValue("spoorid", spoor.id);
                    command.Parameters.AddWithValue("tramid", tram.id);


                    Convert.ToInt32(command.ExecuteNonQuery());
                }
            }
        }
Example #5
0
        public bool UpdateSpoor(Spoor spoor, int status)
        {
            using (SqlConnection connection = Database.Connection)
            {
                string query = "UPDATE spoor SET bezetting= @status  WHERE id= @id";
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("id", spoor.id);
                    command.Parameters.AddWithValue("status", status);


                    if (Convert.ToInt32(command.ExecuteNonQuery()) > 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
        public Spoor GetSpoor(int id)
        {
            Spoor ReturnSpoor = new Spoor();

            using (SqlConnection connection = Database.Connection)
            {
                string query = "Select * FROM spoor Where id = @id";
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("id", id);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ReturnSpoor = (CreateSpoorFromReader(reader));
                        }
                    }
                }
            }
            return(ReturnSpoor);
        }
Example #7
0
        public List <Tram> GetTramsInSector(Spoor Spoor)
        {
            List <Tram> result = new List <Tram>();

            using (SqlConnection connection = Database.Connection)
            {
                string query = "  select * from tram where id in (select tramid from sector where spoorid =@spoor)";
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("Spoor", Spoor.id);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            result.Add(CreateTramFromReader(reader));
                        }
                    }
                }
            }
            return(result);
        }
Example #8
0
        public List <Sector> ZoekVrijSector(Spoor spoor)
        {
            List <Sector> returnSectoren = new List <Sector>();

            using (SqlConnection connection = Database.Connection)
            {
                string query = "Select * FROM sector Where spoorid = @spoorid and tramid is null and beschikbaarheid =0 and blokkade =0";
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("spoorid", spoor.id);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            returnSectoren.Add(CreateSectorFromReader(reader));
                        }
                    }
                }
            }
            return(returnSectoren);
        }
Example #9
0
 public bool UpdateSpoor(Spoor spoor, int status)
 {
     return(context.UpdateSpoor(spoor, status));
 }
Example #10
0
 public List <Tram> GetTramsInSector(Spoor spoor)
 {
     return(tramContext.GetTramsInSector(spoor));
 }