Ejemplo n.º 1
0
        void addNewItem_Click(object sender, EventArgs e)
        {
            switch (flag)
            {
            case "Buses":
                dgvBusStation.EndEdit();
                Buses         bus = (Buses)binSourceBusStation.Current;
                BusRepository rep = new BusRepository();
                rep.Create(bus);

                Seats           seat;
                SeatsRepository seatrep = new SeatsRepository();
                for (int i = 0; i < bus.CountSeats; i++)
                {
                    seat            = new Seats();
                    seat.BusId      = bus.BusId;
                    seat.NumberSeat = i + 1;
                    seatrep.Create(seat);
                }

                break;

            default:
                dgvBusStation.EndEdit();
                T t = (T)binSourceBusStation.Current;
                repository.Create(t);
                break;
            }
        }
Ejemplo n.º 2
0
        private void EditBus()
        {
            listSeats.Clear();
            Buses                  bus           = binSourceBusStation.Current as Buses;
            BusRepository          busrep        = new BusRepository();
            List <TempFlightId>    listFlightId2 = new List <TempFlightId>();
            List <TempSeatId>      listSeatId    = new List <TempSeatId>();
            List <BusinessTickets> busTicketsB   = DeleteTicketsFlightsSeats(bus, ref listbusFlights, ref listSeats);

            busrep.Delete(bus);

            Buses newbus = new Buses();

            newbus.BusName     = bus.BusName;
            newbus.CountSeats  = bus.CountSeats;
            newbus.Information = bus.Information;
            busrep.Create(newbus);

            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;
                    busFlight.CityIdEnd     = 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 == bus.BusId ? newbus.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();
                    listFlightId2.Add(ekz);
                }
            }


            SeatsRepository seatrep = new SeatsRepository();
            TempSeatId      ekzseat;

            for (int i = 0; i < newbus.CountSeats; i++)
            {
                Seats seat = new Seats();
                ekzseat         = new TempSeatId();
                seat.BusId      = newbus.BusId;
                seat.NumberSeat = i + 1;
                seatrep.Create(seat);

                SeatsRepository newSeat = new SeatsRepository();
                ekzseat.oldId = i < listSeats.Count ? listSeats[i].SeatId : 0;
                ekzseat.newId = newSeat.GetAll().Select(p => p.SeatId).Last();
                listSeatId.Add(ekzseat);
            }

            if (busTicketsB.Count > 0)
            {
                BusinessTickets           bustick;
                BusinessTicketsRepository bustickrep = new BusinessTicketsRepository();
                for (int i = 0; i < busTicketsB.Count; i++)
                {
                    bustick = new BusinessTickets();
                    for (int j = 0; j < listFlightId2.Count; j++)
                    {
                        if (busTicketsB[i].FlightId == listFlightId2[j].oldId)
                        {
                            bustick.FlightId = listFlightId2[j].newId;
                            break;
                        }
                    }
                    for (int k = 0; k < listSeatId.Count; k++)
                    {
                        if (busTicketsB[i].SeatId == listSeatId[k].oldId)
                        {
                            bustick.SeatId = listSeatId[k].newId;
                            break;
                        }
                    }
                    bustick.ReleaseDate = busTicketsB[i].ReleaseDate;
                    bustick.DiscountId  = busTicketsB[i].DiscountId;
                    bustick.Sold        = busTicketsB[i].Sold;
                    bustick.Reserve     = busTicketsB[i].Reserve;
                    bustick.Canceled    = busTicketsB[i].Canceled;

                    bustickrep.Create(bustick);
                }
            }

            MessageBox.Show("Bus Edit");
        }