private List <BusinessTickets> DeleteTicketsFlightsSeats(Buses bus, ref List <BusinessFlights> busFlights, ref List <Seats> listseats) { List <BusinessTickets> busTickets = new List <BusinessTickets>(); BusinessTickets obj = new BusinessTickets(); BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); BusinessFlights objFlights = new BusinessFlights(); BusinessFlightsRepository busFlightsRep = new BusinessFlightsRepository(); Seats seats = new Seats(); SeatsRepository seatsrep = new SeatsRepository(); int countTick = busTickRep.GetAll(bus).ToList().Count; int countFlight = busFlightsRep.GetAll(bus).ToList().Count; int countSeat = seatsrep.GetAll().Where(p => p.BusId == bus.BusId).Count(); if (countTick > 0) { while (countTick-- > 0) { obj = busTickRep.GetAll(bus).First(); busTickets.Add(obj); busTickRep.Delete(obj); } while (countFlight-- > 0) { objFlights = busFlightsRep.GetAll(bus).First(); busFlights.Add(objFlights); busFlightsRep.Delete(objFlights); } flagdelete = 1; } else { while (countFlight-- > 0) { objFlights = busFlightsRep.GetAll(bus).First(); busFlights.Add(objFlights); busFlightsRep.Delete(objFlights); } flagdelete = 1; } while (countSeat-- > 0) { seats = seatsrep.GetAll().Where(p => p.BusId == bus.BusId).First(); listseats.Add(seats); seatsrep.Delete(seats); } return(busTickets); }
private void MetodClearOldDataBase() // Метод для очистки Базы данных от старых рейсов и проданных билетов { BusinessFlightsRepository bfr = new BusinessFlightsRepository(); BusinessTicketsRepository btr = new BusinessTicketsRepository(); BusinessTickets tic = new BusinessTickets(); BusinessFlights fli = new BusinessFlights(); DateTime NowDate = DateTime.Now.Date; int flag = 0; while (btr.GetAll(NowDate).Count() > 0) { tic = btr.GetAll(NowDate).First(); btr.Delete(tic); flag = 1; } while (bfr.GetAll().Where(p => p.ArrivalDate < NowDate).ToList().Count > 0) { fli = bfr.GetAll().Where(p => p.DepartureDate < NowDate).First(); bfr.Delete(fli); flag = 1; } if (flag == 1) { MessageBox.Show("Old Tickets and Flights Deleted"); } }
private List <BusinessTickets> DeleteTicketsANDFlights(Cities city, ref List <BusinessFlights> busFlights) { List <BusinessTickets> busTickets = new List <BusinessTickets>(); BusinessTickets obj = new BusinessTickets(); BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); BusinessFlights objFlights = new BusinessFlights(); BusinessFlightsRepository busFlightsRep = new BusinessFlightsRepository(); int countTick = busTickRep.GetAll(city).ToList().Count; int countFlight = busFlightsRep.GetAll(city).ToList().Count; if (countTick > 0) { while (countTick-- > 0) { obj = busTickRep.GetAll(city).First(); busTickets.Add(obj); busTickRep.Delete(obj); } while (countFlight-- > 0) { objFlights = busFlightsRep.GetAll(city).First(); busFlights.Add(objFlights); busFlightsRep.Delete(objFlights); } flagdelete = 1; } else { while (countFlight-- > 0) { objFlights = busFlightsRep.GetAll(city).First(); busFlights.Add(objFlights); busFlightsRep.Delete(objFlights); } flagdelete = 1; } return(busTickets); }
private void bDelete_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { BusinessFlights bflights = binSourceBusStation.Current as BusinessFlights; BusinessTicketsRepository btr = new BusinessTicketsRepository(); BusinessTickets tic = new BusinessTickets(); if (btr.GetAll(bflights).Count() > 0) { result = MessageBox.Show("На этот рейс проданы билеты, билеты будут удалены, УДАЛИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { while (btr.GetAll(bflights).Count() > 0) { tic = btr.GetAll(bflights).First(); btr.Delete(tic); } BusinessFlightsRepository bfr = new BusinessFlightsRepository(); bfr.Delete(bflights); MessageBox.Show("Flight Delete"); RefreshBindingSourse(); RefreshcbBuses(); } } else { BusinessFlightsRepository bfr = new BusinessFlightsRepository(); bfr.Delete(bflights); MessageBox.Show("Flight Delete"); RefreshBindingSourse(); RefreshcbBuses(); } } }