Esempio n. 1
0
    def card_data(self, id_: int) -> tuple:
        """
        Информация о зале

        :param id_: номер зала
        :return: tuple(кол-во идущих сеансов, кол-во мест во всем зале, список сеансов)
        """
        sessions = [
            i[0] for i in get_data_base(
                self.path_base_file,
                """SELECT title FROM Sessions s WHERE s.hall_id = ?""", (
                    id_, ))
        ]
        quantity_sessions = len(sessions)
        quantity_places = int(
            get_data_base(
                self.path_base_file,
                """SELECT rows * places_row FROM Halls h WHERE h.id = ?""",
                (id_, ))[0][0])
        static = [
            i[0] for i in get_data_base(
                self.path_base_file,
                """SELECT s.price  FROM Sessions s, Places p  
            WHERE s.hall_id = ? AND p.session_id = s.id;""", (id_, ))
        ]
        static = sum(static if static != [None] else [0])
        return quantity_sessions, quantity_places, sessions, static
Esempio n. 2
0
 def __init__(self,
              hall: WindowHall = None,
              session_id: int = None) -> None:
     self.window = hall.session
     self.hall = hall
     self.session_id = session_id
     super().__init__(self.hall.start, self.hall.user)
     #  Информация о сессии
     self.price = get_data_base(
         self.path_base_file, """SELECT price FROM Sessions WHERE id = ?""",
         (self.session_id, ))[0][0]
     self.title_hall = get_data_base(
         self.path_base_file,
         """SELECT h.title FROM Halls h, Sessions s WHERE h.id = s.hall_id AND s.id = ?""",
         (self.session_id, ))[0][0]
     self.date = get_data_base(
         self.path_base_file, """SELECT date FROM Sessions WHERE id = ?""",
         (self.session_id, ))[0][0]
     #
     d_row, d_places = map(
         int,
         get_data_base(
             self.path_base_file,
             """SELECT rows, places_row FROM Halls WHERE  id = ?""",
             (self.hall.hall_id, ))[0])
     take_place = get_data_base(
         self.path_base_file,
         "SELECT p.row, p.place FROM Places p WHERE p.session_id = ?",
         (self.session_id, ))
     self.placement = WidgetPlacement(take_place, d_row, d_places)
     layout = QGridLayout()
     layout.addWidget(self.placement)
     self.grid_card.addLayout(layout, 0, 0)
     self.label_user.hide()
Esempio n. 3
0
    def card_data(self, id_: int) -> tuple:
        """
        Информация о кинотеатре

        :param id_: номер кинотеатра
        :return: tuple(кол-во залов, кол-во сеансов, кол-во мест)
        """
        quantity_halls = int(
            get_data_base(
                self.path_base_file,
                """SELECT COUNT(*) FROM Halls h WHERE h.cinema_id = ?""",
                (id_, ))[0][0])
        quantity_sessions = int(
            get_data_base(
                self.path_base_file,
                """SELECT COUNT(*) FROM Sessions s, Halls h WHERE h.cinema_id = ? AND s.hall_id = h.id""",
                (id_, ))[0][0])
        quantity_places = sum([
            i[0] for i in get_data_base(
                self.path_base_file,
                """SELECT rows * places_row FROM Halls h WHERE h.cinema_id = ?""",
                (id_, ))
        ])
        static = [
            i[0] for i in get_data_base(
                self.path_base_file,
                """SELECT s.price FROM Halls h, Sessions s, Places p
               WHERE h.cinema_id = ? AND s.hall_id = h.id AND p.session_id = s.id""",
                (id_, ))
        ]
        static = sum(static if static != [None] else [0])
        return quantity_halls, quantity_sessions, quantity_places, static
Esempio n. 4
0
    def reservations(self) -> None:
        """
        Покупка и печать билетов.
        Отмена забронированного места.

        :return: Эта функция ничего не возвращает
        """
        take_place_base = set(
            get_data_base(
                self.path_base_file,
                "SELECT p.row, p.place FROM Places p WHERE p.session_id = ?",
                (self.session_id, )))
        deleted = take_place_base - self.placement.take_place
        added = self.placement.take_place - take_place_base
        with get_base(self.path_base_file, True) as base:
            if deleted:
                for row, place in deleted:
                    base.execute(
                        """DELETE FROM Places WHERE row = ? AND place = ? AND session_id = ?""",
                        (row, place, self.session_id))
            if added:
                for row, place in added:
                    base.execute(
                        """INSERT INTO Places (row, place, session_id) VALUES (?, ?, ?)""",
                        (row, place, self.session_id))
                    th = Thread(target=ticket,
                                args=(row, place, self.title_hall, self.price,
                                      self.date))
                    th.start()
Esempio n. 5
0
    def edit(self, id_: int) -> None:
        """
        Изменение сессии

        :param id_: номер изменяемого объекта
        :return: Эта функция ничего не возвращает
        """
        dialog = FormSession(
            'Изменение сеанса',
            *get_data_base(
                self.path_base_file,
                """SELECT title, date, time, duration FROM Sessions WHERE id = ?""",
                (id_, ))[0])
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                base.execute(
                    """
                UPDATE Sessions SET title = ?, date = ?, time = ?, duration = ?, price = ? WHERE id = ?""",
                    (dialog.title.text(),
                     dialog.date.dateTime().toString('dd.MM.yyyy'),
                     dialog.time.dateTime().toString('HH:mm'),
                     dialog.duration.dateTime().toString('HH:mm'),
                     dialog.price.value(), id_))
            self.update_()
        dialog.deleteLater()
Esempio n. 6
0
    def new_hall(self) -> None:
        """
        Добавление в базу данных нового зала с проверкой на название
        (Не может быть несколько залов с одинаковым названием)

        :return: Эта функция ничего не возвращает
        """
        dialog = FormHall('Добавление зала')
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                count = int(
                    get_data_base(
                        self.path_base_file,
                        """SELECT COUNT(*) FROM Halls WHERE title = ? AND id = ?""",
                        (dialog.title.text(), self.cinema_id))[0][0])
                if count == 0:
                    base.execute(
                        """INSERT INTO Halls (id, title, cinema_id, rows, places_row) 
                                    VALUES ((SELECT id FROM Halls ORDER BY id DESC LIMIT 1) + 1, ?, ?, ?, ?);
                                    """,
                        (dialog.title.text(), self.cinema_id,
                         dialog.rows.value(), dialog.places_row.value()))
                else:
                    error_message = Message(
                        title_window='Ошибка!',
                        text=f'Зал с таким названием уже есть!',
                        informative_text='Введите другое название.')
                    error_message.exec()
                    self.new_hall()
            self.update_()
        dialog.deleteLater()
Esempio n. 7
0
    def new_cinema(self) -> None:
        """
        Добавление в базу данных нового кинотеатра с проверкой на название
        (Не может быть несколько кинотеатров с одинаковым названием)

        :return: Эта функция ничего не возвращает
        """
        dialog = FormCinema('Добавление кинотеатра')
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                count = int(
                    get_data_base(
                        self.path_base_file,
                        """SELECT COUNT(*) FROM Cinemas WHERE title = ?""",
                        (dialog.title.text(), ))[0][0])
                if count == 0:
                    base.execute(
                        """
                    INSERT INTO Cinemas (id, title) VALUES ((SELECT id FROM Cinemas ORDER BY id DESC LIMIT 1) + 1, ?);
                    """, (dialog.title.text(), ))
                else:
                    error_message = Message(
                        title_window='Ошибка!',
                        text=f'Кинотеатр с таким названием уже есть!',
                        informative_text='Введите другое название.')
                    error_message.exec()
                    self.new_cinema()
            self.update_()
        dialog.deleteLater()
Esempio n. 8
0
    def card_data(self, id_: int) -> tuple:
        """
        Информация о сеансе

        :param id_: номер сеанса
        :return: tuple(дата, время, продолжительность, цена)
        """
        date, time, duration, price = get_data_base(
            self.cinema.start.path_base_file,
            """SELECT date, time, duration, price FROM Sessions WHERE id = ?""",
            (id_, ))[0]
        static = [
            i[0] for i in get_data_base(
                self.path_base_file, """SELECT s.price
            FROM Sessions s, Places p 
            WHERE s.id = ? AND p.session_id = s.id""", (id_, ))
        ]
        static = sum(static if static != [None] else [0])
        return date, time, duration, price, static
Esempio n. 9
0
    def new_session(self) -> None:
        """
        Добавление в базу данных нового сеанса с проверкой на валидность времени
        (Сеансы в одном зале не могут идти одновременно)
        В настройках указано время на уборку зала. Это время тоже учитывается.
        По умолчанию 30 минут.

        :return: Эта функция ничего не возвращает
        """
        dialog = FormSession('Добавление сеанса')
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                date_inp = dialog.date.dateTime().toString('dd.MM.yyyy')
                time_inp = dialog.time.dateTime().toString('HH:mm')
                duration_inp = dialog.duration.dateTime().toString('HH:mm')
                #
                inp_start = datetime.datetime(
                    *reversed(list(map(int, date_inp.split('.')))),
                    *list(map(int, time_inp.split(':'))))
                # Время сеанса с учётом уборки в зале
                h, m = map(int, duration_inp.split(':'))
                inp_finish = inp_start + datetime.timedelta(
                    hours=h, minutes=m + time_restart_session)
                #
                list_time = get_data_base(
                    self.path_base_file,
                    f"""SELECT date, time, duration FROM Sessions WHERE hall_id = ?""",
                    (self.hall_id, ))
                for date, time, duration in list_time:
                    h, m = map(int, duration.split(':'))
                    start = datetime.datetime(
                        *reversed(list(map(int, date.split('.')))),
                        *list(map(int, time.split(':'))))
                    finish = start + datetime.timedelta(hours=h, minutes=m)
                    if start <= inp_start <= finish or start <= inp_finish <= finish:
                        error_message = Message(
                            title_window='Ошибка!',
                            text=f'Сеанс пересекается с другим сеансом!')
                        error_message.exec()
                        self.new_session()
                        return
                base.execute(
                    """
                                INSERT INTO Sessions (id, title, hall_id, date, time, duration, price)
                                VALUES ((SELECT id FROM Sessions ORDER BY id DESC LIMIT 1) + 1, ?, ?, ?, ?, ?, ?);
                                """,
                    (dialog.title.text(), self.hall_id, date_inp, time_inp,
                     duration_inp, dialog.price.value()))
            self.update_()
        dialog.deleteLater()
Esempio n. 10
0
 def __init__(self,
              start: WindowStart = None,
              user: str = 'Пользователь') -> None:
     self.window = start.cinemas
     self.cinema = None
     self.card = WidgetCinemasCard
     self.base = Base(start.path_base_file,
                      """SELECT id, title FROM Cinemas""")
     super().__init__(start, user)
     self.title_static = 'Доход по кинотеатрам'
     self.base_static = get_data_base(
         self.path_base_file,
         """SELECT c.title, s.price FROM Cinemas c, Halls h, Sessions s, Places p
            WHERE h.cinema_id = c.id AND s.hall_id = h.id AND p.session_id = s.id"""
     )
Esempio n. 11
0
    def edit(self, id_: int) -> None:
        """
        Изменение кинотеатра

        :param id_: номер изменяемого объекта
        :return: Эта функция ничего не возвращает
        """
        dialog = FormCinema(
            'Изменение кинотеатра',
            get_data_base(self.path_base_file,
                          """SELECT title FROM Cinemas WHERE id = ?""",
                          (id_, ))[0][0])
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                base.execute("""UPDATE Cinemas SET title = ? WHERE id = ?""",
                             (dialog.title.text(), id_))
            self.update_()
        dialog.deleteLater()
Esempio n. 12
0
 def __init__(self,
              cinemas: WindowCinemas = None,
              cinema_id: int = None) -> None:
     self.window = cinemas.cinema
     self.hall = None
     self.cinemas = cinemas
     self.cinema_id = cinema_id
     self.base = Base(
         cinemas.start.path_base_file,
         """SELECT id, title FROM Halls WHERE  cinema_id = ?""",
         (self.cinema_id, ))
     self.card = WidgetCinemaCard
     super().__init__(self.cinemas.start, self.cinemas.user)
     self.title_static = 'Доход по кинотеатру'
     self.base_static = get_data_base(
         self.path_base_file,
         """SELECT h.title, s.price  FROM Halls h, Sessions s, Places p
         WHERE h.cinema_id = ? AND s.hall_id = h.id AND p.session_id = s.id;""",
         (self.cinema_id, ))
Esempio n. 13
0
 def __init__(self,
              cinema: WindowCinema = None,
              hall_id: int = None) -> None:
     self.window = cinema.hall
     self.session = None
     self.cinema = cinema
     self.hall_id = hall_id
     self.base = Base(
         self.cinema.start.path_base_file,
         """SELECT id, title, date, time FROM Sessions WHERE  hall_id = ?""",
         (self.hall_id, ),
         key=lambda x: datetime.datetime(
             *reversed(list(map(int, x[2].split('.')))),
             *list(map(int, x[3].split(':')))))
     self.card = WidgetHallCard
     super().__init__(self.cinema.start, self.cinema.user)
     self.title_static = 'Доход по залу'
     self.base_static = get_data_base(
         self.path_base_file, """SELECT s.title, s.price 
            FROM Sessions s, Places p WHERE s.hall_id = ? AND p.session_id = s.id""",
         (self.hall_id, ))
Esempio n. 14
0
    def edit(self, id_: int) -> None:
        """
        Изменение зала

        :param id_: номер изменяемого объекта
        :return: Эта функция ничего не возвращает
        """
        dialog = FormHall(
            'Изменение зала',
            *get_data_base(
                self.path_base_file,
                """SELECT title, rows, places_row FROM Halls WHERE id = ?""",
                (id_, ))[0])
        if dialog.exec_() == QDialog.Accepted:
            with get_base(self.path_base_file, True) as base:
                base.execute(
                    """UPDATE Halls SET title = ?, rows = ?, places_row = ? WHERE id = ?""",
                    (dialog.title.text(), dialog.rows.value(),
                     dialog.places_row.value(), id_))
            self.update_()
        dialog.deleteLater()