public void RefreshSeats() { if (binSourceBusStation.Count != 0) { flight = binSourceBusStation.Current as BusinessFlights; if (flight.CityStart != null) { DateTime dt = DateTime.Now.Date; cbSeats.DataSource = null; BusStationEntities conect = new BusStationEntities(); BusRepository busrep = new BusRepository(); BusinessTicketsRepository btr = new BusinessTicketsRepository(); string BussName = flight.Bus; dt = flight.DepartureDate; int Busid = busrep.GetAll().Where(p => p.BusName == BussName).Select(p => p.BusId).First(); var notSeats = conect.Tickets.Where(p => p.Flights.DepartureDate == dt && p.Flights.BusId == Busid).Select(p => p.SeatId).ToList(); int count = 0; cbSeats.ValueMember = "SeatId"; cbSeats.DisplayMember = "NumberSeat"; var tempSeats = Seatsr.GetAll().Where(p => p.BusId == Busid).ToList(); while (count < notSeats.Count) { tempSeats = tempSeats.Where(p => p.SeatId != notSeats[count]).ToList(); count++; } cbSeats.DataSource = tempSeats; } else { MessageBox.Show("Выберите рейс"); } } }
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 void EditDiscount() { DiscountRepository discrep = new DiscountRepository(); Discounts disc = (Discounts)binSourceBusStation.Current; List <BusinessTickets> busTicketsD = DeleteTicketsANDFlights(disc); discrep.Delete(disc); Discounts newdisc = new Discounts(); newdisc.DiscountName = disc.DiscountName; newdisc.Size = disc.Size; newdisc.Information = disc.Information; discrep.Create(newdisc); if (busTicketsD.Count > 0) { BusinessTickets bustick = new BusinessTickets(); BusinessTicketsRepository bustickrep = new BusinessTicketsRepository(); for (int i = 0; i < busTicketsD.Count; i++) { bustick.ReleaseDate = busTicketsD[i].ReleaseDate; bustick.FlightId = busTicketsD[i].FlightId; bustick.SeatId = busTicketsD[i].SeatId; bustick.DiscountId = newdisc.DiscountId; bustick.Sold = busTicketsD[i].Sold; bustick.Reserve = busTicketsD[i].Reserve; bustick.Canceled = busTicketsD[i].Canceled; bustickrep.Create(bustick); } } MessageBox.Show("Discount Edit"); }
private void Show_Tickets_Load(object sender, EventArgs e) { BusinessTicketsRepository btr = new BusinessTicketsRepository(); binSourceBusStation.DataSource = btr.GetAll(); dgvBusStation.DataSource = binSourceBusStation; dgvBusStation.Columns["TicketId"].Visible = false; }
void GetTickets() { BusinessTicketsRepository btr = new BusinessTicketsRepository(); binSourceBusStation.DataSource = btr.GetAll(); dgvBusStation.DataSource = binSourceBusStation; dgvBusStation.Columns["TicketId"].Visible = false; dgvBusStation.Columns["FlightId"].Visible = false; dgvBusStation.Columns["SeatId"].Visible = false; dgvBusStation.Columns["DiscountId"].Visible = false; }
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 bDeleteTicket_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { BusinessTickets tic = binSourceBusStation.Current as BusinessTickets; BusinessTicketsRepository obj = new BusinessTicketsRepository(); obj.Delete(tic); GetTickets(); MessageBox.Show("Ticket Delete"); } }
private void bBuyTicket_Click(object sender, EventArgs e) { BusinessTickets bt = binSourceBusStation.Current as BusinessTickets; if (bt.Reserve == true) { BusinessTicketsRepository btr = new BusinessTicketsRepository(); bt.Sold = true; bt.Reserve = false; btr.Save(bt); MessageBox.Show("Ticket sold"); } }
private void bSave_Click(object sender, EventArgs e) { dgvBusStation.EndEdit(); BusinessFlights bfl = binSourceBusStation.Current as BusinessFlights; List <BusinessTickets> busTickets = DeleteTickets(bfl); BusinessFlightsRepository bfr = new BusinessFlightsRepository(); bfr.Save(bfl); if (busTickets.Count > 0) { BusinessTickets bustick = new BusinessTickets(); BusinessTicketsRepository bustickrep = new BusinessTicketsRepository(); FlightRepository newflight = new FlightRepository(); for (int i = 0; i < busTickets.Count; i++) { bustick.ReleaseDate = busTickets[i].ReleaseDate; bustick.FlightId = bfl.FlightId /*newflight.GetAll().Select(p => p.FlightId).Last()*/; bustick.SeatId = busTickets[i].SeatId; bustick.DiscountId = busTickets[i].DiscountId; bustick.Sold = busTickets[i].Sold; bustick.Reserve = busTickets[i].Reserve; bustick.Canceled = busTickets[i].Canceled; bustickrep.Create(bustick); } } // Если надо будет изменять все записи этого рейса //BusinessFlights bfl2 = bfr.GetAll(); //int countFlights = bfr.GetAll(bfl1.FlightNumber).ToList().Count(); //while (countFlights-- > 0) //{ // bfl2 = bfr.GetAll(bfl1.FlightNumber).First(); // listFlights.Add(bfl2); // bfr.Delete(bfl2); //} //for (int i = 0; i < listFlights.Count; i++) //{ // bfl2 = listFlights[i]; // bfr.Save(GetBusinessFlights(bfl1, bfl2)); //} RefreshBindingSourse(); MessageBox.Show("Flights Edit"); }
private List <BusinessTickets> DeleteTicketsANDFlights(Discounts discounts) { List <BusinessTickets> busTickets = new List <BusinessTickets>(); int DiscountId = discounts.DiscountId; BusinessTickets obj = new BusinessTickets(); BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); int countTick = busTickRep.GetAll(DiscountId).ToList().Count; while (countTick-- > 0) { obj = busTickRep.GetAll(DiscountId).First(); busTickets.Add(obj); busTickRep.Delete(obj); } return(busTickets); }
private List <BusinessTickets> DeleteTickets(BusinessFlights BFlights) { List <BusinessTickets> listbusTickets = new List <BusinessTickets>(); BusinessTickets obj = new BusinessTickets(); BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); int countTick = busTickRep.GetAll(BFlights, 1).ToList().Count; while (countTick-- > 0) { obj = busTickRep.GetAll(BFlights, 1).First(); listbusTickets.Add(obj); busTickRep.Delete(obj); } return(listbusTickets); }
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(); } } }
private void bReserveTicket_Click(object sender, EventArgs e) { if (cbCityStart.Text != "" && cbCityEnd.Text != "" && cbSeats.Text != "") { BusinessTickets bustick = new BusinessTickets(); bustick.ReleaseDate = DateTime.Now.Date; bustick.FlightId = flight.FlightId; bustick.SeatId = Convert.ToInt32(cbSeats.SelectedValue); bustick.DiscountId = Convert.ToInt32(cbDiscount.SelectedValue); bustick.Reserve = true; BusinessTicketsRepository bustickrep = new BusinessTicketsRepository(); bustickrep.Create(bustick); MessageBox.Show("Ticket Reserve"); RefreshSeats(); } else { MessageBox.Show("Fill in all the fields"); } }
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"); }
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"); }
void deleteItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { flagdelete = 0; BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); switch (flag) { case "Discounts": Discounts disc = (Discounts)binSourceBusStation.Current; if (busTickRep.GetAll(disc.DiscountId).ToList().Count > 0) { result = MessageBox.Show("С этим дисконтом уже проданы билеты все таки УДАЛИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { DeleteTicketsANDFlights(disc); flagdelete = 1; MessageBox.Show("Discount Delete"); } } else { DeleteTicketsANDFlights(disc); flagdelete = 1; } break; case "Cities": Cities city = binSourceBusStation.Current as Cities; int countC = busTickRep.GetAll(city).ToList().Count; if (countC > 0) { result = MessageBox.Show("Билеты с такими городами уже проданы все таки УДАЛИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { DeleteTicketsANDFlights(city, ref listbusFlights); MessageBox.Show("Citi Delete"); } } else { DeleteTicketsANDFlights(city, ref listbusFlights); MessageBox.Show("Citi Delete"); } break; case "Buses": Buses bus = binSourceBusStation.Current as Buses; int countB = busTickRep.GetAll(bus).ToList().Count; if (countB > 0) { result = MessageBox.Show("Билеты с такими городами уже проданы все таки УДАЛИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { DeleteTicketsFlightsSeats(bus, ref listbusFlights, ref listSeats); MessageBox.Show("Bus Delete"); } } else { DeleteTicketsFlightsSeats(bus, ref listbusFlights, ref listSeats); MessageBox.Show("Bus Delete"); } break; default: break; } if (flagdelete == 1) { T t = (T)binSourceBusStation.Current; repository.Delete(t); binSourceBusStation.RemoveCurrent(); DBRefresh(); } } }
void saveItem_Click(object sender, EventArgs e) { dgvBusStation.EndEdit(); DialogResult result; BusinessTicketsRepository busTickRep = new BusinessTicketsRepository(); switch (flag) { case "Discounts": Discounts disc = (Discounts)binSourceBusStation.Current; if (busTickRep.GetAll(disc.DiscountId).ToList().Count > 0) { result = MessageBox.Show("С этим дисконтом уже проданы билеты, возможна потеря данных, все таки ИЗМЕНИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { EditDiscount(); } } else { EditDiscount(); } break; case "Cities": Cities city = binSourceBusStation.Current as Cities; if (busTickRep.GetAll(city).ToList().Count > 0) { result = MessageBox.Show("С этим городом уже проданы билеты, возможна потеря данных, все таки ИЗМЕНИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { EditCity(); } } else { EditCity(); } break; case "Buses": Buses bus = binSourceBusStation.Current as Buses; if (busTickRep.GetAll(bus).ToList().Count > 0) { result = MessageBox.Show("С этим автобусом уже проданы билеты, возможна потеря данных, все таки ИЗМЕНИТЬ ЗАПИСЬ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result.ToString() == "Yes") { EditBus(); } } else { EditBus(); } break; default: break; } DBRefresh(); }