Exemplo n.º 1
0
        private void RefreshcbBuses()
        {
            CitiRepository cityRep = new CitiRepository();

            RefreshBindingSourse();
            dtpDepartureDate.MinDate   = DateTime.Now;
            dtpArrivalDate.MinDate     = DateTime.Now;
            dtpFinalDateFlight.MinDate = DateTime.Now;

            cbCityStart.DisplayMember = "CityName";
            cbCityStart.ValueMember   = "CityId";
            cbCityStart.DataSource    = cityRep.GetAll();

            cbCityEnd.DisplayMember = "CityName";
            cbCityEnd.ValueMember   = "CityId";
            cbCityEnd.DataSource    = cityRep.GetAll();

            BusRepository    busRep    = new BusRepository();
            FlightRepository flightRep = new FlightRepository();
            var busybus   = flightRep.GetAll().Select(p => p.BusId).ToList();
            int count     = 0;
            var tempBuses = busRep.GetAll();

            while (count < busybus.Count)
            {
                tempBuses = tempBuses.Where(p => p.BusId != busybus[count]).ToList();
                count++;
            }
            cbBuses.DisplayMember = "BusName";
            cbBuses.ValueMember   = "BusId";
            cbBuses.DataSource    = tempBuses;
        }
Exemplo n.º 2
0
        private void EditCity()
        {
            listbusFlights.Clear();
            Cities                 city         = binSourceBusStation.Current as Cities;
            CitiRepository         cityrep      = new CitiRepository();
            List <TempFlightId>    listFlightId = new List <TempFlightId>();
            List <BusinessTickets> busTicketsC  = DeleteTicketsANDFlights(city, ref listbusFlights);

            cityrep.Delete(city);

            Cities newcity = new Cities();

            newcity.CityName    = city.CityName;
            newcity.Information = city.Information;
            cityrep.Create(newcity);

            if (listbusFlights.Count > 0)
            {
                BusinessFlights           busFlight;
                BusinessFlightsRepository busFlightrep = new BusinessFlightsRepository();
                TempFlightId ekz;
                for (int i = 0; i < listbusFlights.Count; i++)
                {
                    busFlight = new BusinessFlights();
                    ekz       = new TempFlightId();
                    busFlight.FlightNumber  = listbusFlights[i].FlightNumber;
                    busFlight.CityIdStart   = listbusFlights[i].CityIdStart == city.CityId ? newcity.CityId : listbusFlights[i].CityIdStart;
                    busFlight.CityIdEnd     = listbusFlights[i].CityIdEnd == city.CityId ? newcity.CityId : listbusFlights[i].CityIdEnd;
                    busFlight.DepartureDate = listbusFlights[i].DepartureDate;
                    busFlight.DepartureTime = listbusFlights[i].DepartureTime;
                    busFlight.ArrivalDate   = listbusFlights[i].ArrivalDate;
                    busFlight.ArrivaTime    = listbusFlights[i].ArrivaTime;
                    busFlight.BusId         = listbusFlights[i].BusId;
                    busFlight.Price         = listbusFlights[i].Price;
                    busFlightrep.Create(busFlight);

                    FlightRepository newflight = new FlightRepository();
                    ekz.oldId = listbusFlights[i].FlightId;
                    ekz.newId = newflight.GetAll().Select(p => p.FlightId).Last();
                    listFlightId.Add(ekz);
                }
            }
            if (busTicketsC.Count > 0)
            {
                BusinessTickets           bustick;
                BusinessTicketsRepository bustickrep = new BusinessTicketsRepository();
                for (int i = 0; i < busTicketsC.Count; i++)
                {
                    bustick = new BusinessTickets();
                    for (int j = 0; j < listFlightId.Count; j++)
                    {
                        if (busTicketsC[i].FlightId == listFlightId[j].oldId)
                        {
                            bustick.FlightId = listFlightId[j].newId;
                            break;
                        }
                    }
                    bustick.ReleaseDate = busTicketsC[i].ReleaseDate;
                    bustick.SeatId      = busTicketsC[i].SeatId;
                    bustick.DiscountId  = busTicketsC[i].DiscountId;
                    bustick.Sold        = busTicketsC[i].Sold;
                    bustick.Reserve     = busTicketsC[i].Reserve;
                    bustick.Canceled    = busTicketsC[i].Canceled;

                    bustickrep.Create(bustick);
                }
            }

            MessageBox.Show("City Edit");
        }