def show(self, session_id, controller): self.clear() self.user = controller.user_lbl["text"] hall = sql.query_with_fetchall( "select zal_id from сеанс where seans_id=" + str(session_id) + ";")[0][0] self.num_rows, self.num_places = sql.query_with_fetchall( "select колличество_рядов, колличество_мест_в_ряде from зал where zal_id=" + str(hall) + ";")[0] query = "select ряд, место, num from билет where seans_id=" + str( session_id) + ";" self.ticket_id = dict((sublist[0:2], sublist[2]) for sublist in sql.query_with_fetchall(query)) self.btns = {} for i in range(self.num_rows): for j in range(self.num_places): self.btns[(i + 1, j + 1)] = tk.Button( self, text=str(j + 1), command=lambda row=i + 1, place=j + 1: self.buy( row, place, session_id, self.user)) self.btns[(i + 1, j + 1)].grid(row=i, column=j) self.update_btns(session_id)
def add_session(self, film_cb, date_ent, price_ent, ImaxCheck, ThreeDCheck): film = film_cb.get() if film[0] == '{': film = film[1:] if film[-1] == '}': film = film[:-1] hall = self.hall_lb.get(tk.ANCHOR) date = date_ent.get() imax = ImaxCheck.get() threed = ThreeDCheck.get() price = price_ent.get() film_imax, film_threed = sql.query_with_fetchall( "select imax_flg, 3d_flg from фильм where название='" + film + "';")[0] hall_imax, hall_threed = sql.query_with_fetchall( "select imax_flg, 3d_flg from зал where zal_id=" + str(hall) + ";")[0] success = True if imax == 1 and film_imax == 0: success = False if threed == 1 and film_threed == 0: success = False if imax == 1 and hall_imax == 0: success = False if threed == 1 and hall_threed == 0: success = False if success == False: self.success_lbl["text"] = "Ошибка" return query = "insert into сеанс(название_фильма, zal_id, дата_сеанса, imax_flg, 3d_flg, цена) values ('"\ + film + "', " + str(hall) + ", '" + date + "', " + str(imax) + ", " + str(threed) \ + ", " + str(price) + ");" print(query) session_id = sql.insert(query) query = "select колличество_рядов, колличество_мест_в_ряде from зал where zal_id=" + str( hall) + ";" print(query) num_rows, num_places = sql.query_with_fetchall(query)[0] for row in range(1, num_rows + 1): for place in range(1, num_places + 1): ticket_id = sql.insert( "insert into билет(seans_id, ряд, место, цена) values (" + str(session_id) + ", " + str(row) + ", " + str(place) + ", " + str(price) + ");") if success == True: self.success_lbl["text"] = "Успех!"
def select_theater(self, evt): self.hall_lb.delete(0, tk.END) theater = self.theater_lb.get(tk.ANCHOR)[0] query = "select * from зал where название_кинотеатра = '" + theater + "';" halls = sql.query_with_fetchall(query) for row in halls: self.hall_lb.insert(tk.END, row[0])
def update_btns(self, session_id): query = "select ряд, место, логин_пользователя from билет where seans_id=" + str( session_id) + ";" self.btns_flg = dict((sublist[0:2], sublist[2]) for sublist in sql.query_with_fetchall(query)) for i in range(self.num_rows): for j in range(self.num_places): bg = "green" if self.btns_flg[(i + 1, j + 1)] != None: bg = "red" self.btns[(i + 1, j + 1)]["bg"] = bg
def show_sessions(self): self.session_lb.delete(0, tk.END) query = "select * from сеанс where название_фильма='" + self.title_inf[ 'text'] + "';" sessions = sql.query_with_fetchall(query) for row in sessions: self.session_lb.insert(tk.END, row) self.session_lb.grid(row=8, column=1, sticky="nsew") self.buy_btn.grid(row=9, column=1, sticky="nw")
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.columnconfigure(0, minsize=150) self.columnconfigure(1, minsize=400) self.columnconfigure(2, minsize=100) self.rowconfigure([0, 1, 2, 3], minsize=30) self.rowconfigure(4, minsize=210) films = sql.query_with_fetchall("select * from фильм;") for i in range(len(films)): films[i] = films[i][0] film_lbl = tk.Label(self, text="Фильм: ") film_lbl.grid(row=0, column=0, sticky="e") film_cb = ttk.Combobox(self, values=films) film_cb.grid(row=0, column=1, sticky="we") persons = sql.query_with_fetchall("select * from кинодиетели;") person_lbl = tk.Label(self, text="Человек: ") person_lbl.grid(row=1, column=0, sticky="e") person_lb = tk.Listbox(self, height=10) person_lb.grid(row=1, column=1, sticky="we") for row in persons: person_lb.insert(tk.END, row) credits_lbl = tk.Label(self, text="Деятельность: ") credits_lbl.grid(row=2, column=0, sticky="e") credits_ent = tk.Entry(self) credits_ent.grid(row=2, column=1, sticky="we") info_lbl = tk.Label(self, text="Доп. информация: ") info_lbl.grid(row=3, column=0, sticky="e") info_ent = tk.Entry(self) info_ent.grid(row=3, column=1, sticky="we") add_btn = tk.Button( self, text="Добавить", command=lambda: self.add_credits(film_cb, person_lb, credits_ent)) add_btn.grid(row=4, column=1, sticky="nw", pady=15)
def goto_film(self, controller): title = self.results_lb.get(tk.ANCHOR)[0] query = "select * from фильм inner join режисер_фильма on фильм.название=режисер_фильма.название_фильма where название = '" + title + "';" row = sql.query_with_fetchall(query)[0] date = row[1] country = row[2] length = row[3] genre = row[4] director_id = row[9] director_in_film = sql.query_with_fetchall( "select kinodeyatel_id from режисер_фильма where kinodeyatel_id = " + str(director_id) + ";") director = sql.query_with_fetchall( "select ФИО from кинодиетели where kinodeyatel_id = " + str(director_in_film[0][0]) + ";")[0][0] #print(director_name) controller.frames[FilmInfo].update_info(title, genre, date, length, country, director) controller.show_frame(FilmInfo)
def show_results(self, title_ent, genre_cb, year_ent, country_cb, controller): self.results_lb.delete(0, tk.END) title = title_ent.get() genre = genre_cb.get() year = year_ent.get() country = country_cb.get() query = "select название, дата_выпуска from фильм where " and_flag = False if title != "": query = query + "название = '" + title + "'" and_flag = True if genre != "": if and_flag: query += " and " query = query + "жанр = '" + genre + "'" and_flag = True if year != "": if and_flag: query += " and " query = query + "year(дата_выпуска) = '" + year + "'" and_flag = True if country != "": if and_flag: query += " and " query = query + "страна = '" + country + "'" query = query + ";" rows = sql.query_with_fetchall(query) for row in rows: self.results_lb.insert(tk.END, row) self.results_lb.grid(row=5, column=1, sticky="nswe") self.goto_btn.grid(row=6, column=1, sticky="nw", pady=10) self.goto_btn['command'] = lambda: self.goto_film(controller)
def load_users(self): self.users = dict(sql.query_with_fetchall("SELECT логин, пароль FROM пользователь"))
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.columnconfigure(0, minsize=150) self.columnconfigure(1, minsize=400) self.columnconfigure(2, minsize=100) self.rowconfigure([0, 1, 2, 3, 4, 5, 6, 7], minsize=30) self.rowconfigure(8, minsize=170) films = sql.query_with_fetchall("select название from фильм") film_lbl = tk.Label(self, text="Фильм: ") film_lbl.grid(row=0, column=0, sticky="e") film_cb = ttk.Combobox(self, values=films) film_cb.grid(row=0, column=1, sticky="we") theaters = sql.query_with_fetchall("select * from кинотеатр") theater_lbl = tk.Label(self, text="Кинотеатр: ") theater_lbl.grid(row=1, column=0, sticky="e") self.theater_lb = tk.Listbox(self, height=5) for row in theaters: self.theater_lb.insert(tk.END, row) self.theater_lb.grid(row=1, column=1, sticky="we") self.theater_lb.bind("<<ListboxSelect>>", self.select_theater) hall_lbl = tk.Label(self, text="Зал: ") hall_lbl.grid(row=2, column=0, sticky="e") self.hall_lb = tk.Listbox(self, height=5) self.hall_lb.grid(row=2, column=1, sticky="we") date_lbl = tk.Label(self, text="Дата: ") date_lbl.grid(row=3, column=0, sticky="e") date_ent = tk.Entry(self) date_ent.grid(row=3, column=1, sticky="we") price_lbl = tk.Label(self, text="Цена: ") price_lbl.grid(row=4, column=0, sticky="e") price_ent = tk.Entry(self) price_ent.grid(row=4, column=1, sticky="we") imax_lbl = tk.Label(self, text="IMAX: ") imax_lbl.grid(row=5, column=0, sticky="e") ImaxCheck = tk.IntVar() imax_cbtn = tk.Checkbutton(self, variable=ImaxCheck, onvalue=1, offvalue=0) imax_cbtn.grid(row=5, column=1, sticky="w") threed_lbl = tk.Label(self, text="3D: ") threed_lbl.grid(row=6, column=0, sticky="e") ThreeDCheck = tk.IntVar() threed_cbtn = tk.Checkbutton(self, variable=ThreeDCheck, onvalue=1, offvalue=0) threed_cbtn.grid(row=6, column=1, sticky="w") add_btn = tk.Button( self, text="Добавить", command=lambda: self.add_session(film_cb, date_ent, price_ent, ImaxCheck, ThreeDCheck)) add_btn.grid(row=7, column=1, sticky="w") self.success_lbl = tk.Label(self, text="") self.success_lbl.grid(row=8, column=1, sticky="nw", pady=15)