Пример #1
0
        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");
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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;
        }
Пример #6
0
        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;
        }
Пример #7
0
        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);
        }
Пример #8
0
        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();
                }
            }
        }
Пример #9
0
        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();
                }
            }
        }
Пример #10
0
        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();
        }