def get_client_id(self): sql = "SELECT id_klienta FROM klienci WHERE email = '" + str( self.mail.get()) + "'" query = SelectQuery() self.connection = ConnectToSQLdb(query) client_id = self.connection.execute_query(self.connection.get_cursor(), sql) self.close_all() return client_id[0][0]
def check_client(self): sql = "SELECT * FROM klienci WHERE email = '" + str( self.mail.get()) + "'" query = SelectQuery() self.connection = ConnectToSQLdb(query) client = self.connection.execute_query(self.connection.get_cursor(), sql) self.close_all() if len(client) < 1: return True else: return False
def example_cars(self): sql = 'SELECT marka, model, rok_produkcji, cena_wypozyczenia FROM Samochody WHERE zarezerwowany = 0 LIMIT 2' query_type = SelectQuery() connection = ConnectToSQLdb(query_type) cars = connection.execute_query(connection.get_cursor(), sql) result = '' for car in cars: it = Iterator(car) it.set_first() while it.is_done(): result += str(it.get_current_item()) + '\n' it.next() result += '\n\n' result_label = Label(self.window, text=result) result_label.place(x=730, y=150)
def check_reservation(self): email = str(self.mail.get()) car_id = self.get_car_id() sql = "SELECT rezerwacje.id_rezerwacji, klienci.email, samochody.id_samochodu FROM samochody INNER JOIN " \ "(klienci INNER JOIN rezerwacje on klienci.id_klienta = rezerwacje.id_klienta) on " \ "samochody.id_samochodu = rezerwacje.id_samochodu where klienci.email = '" + email + \ "' and samochody.id_samochodu = '" + car_id + "'" query_type = SelectQuery() self.connection = ConnectToSQLdb(query_type) table_of_result = self.connection.execute_query(self.connection.get_cursor(), sql) self.close_all() if len(table_of_result) > 0: self.res_id = table_of_result[0][0] return True else: return False
def calculate_cost(self): sql = "select rezerwacje.start_rezerwacji, samochody.cena_wypozyczenia FROM rezerwacje INNER JOIN " \ "samochody ON rezerwacje.id_samochodu = samochody.id_samochodu WHERE rezerwacje.id_rezerwacji = '" + \ str(self.res_id) + "'" query_type = SelectQuery() self.connection = ConnectToSQLdb(query_type) table_of_result = self.connection.execute_query(self.connection.get_cursor(), sql) self.close_all() day_cost = table_of_result[0][1] (rok, mies, day) = str(table_of_result[0][0]).split('-') (a_rok, a_mies, a_day) = str(date.today()).split('-') diff = abs(date(int(a_rok), int(a_mies), int(a_day)) - date(int(rok), int(mies), int(day))).days if diff == 0: return day_cost else: return int(day_cost) * int(diff)
def add_values_to_combobox(self): sql = 'SELECT id_samochodu, marka, model, rok_produkcji, cena_wypozyczenia FROM Samochody WHERE zarezerwowany = 0' tmp_table = [] query_type = SelectQuery() self.connection = ConnectToSQLdb(query_type) table_of_result = self.connection.execute_query( self.connection.get_cursor(), sql) self.close_all() for res in table_of_result: tmp = '' it = Iterator(res) it.set_first() while it.is_done(): tmp += str(it.get_current_item()) + ' ' it.next() tmp_table.append(tmp) return tmp_table
def add_values_to_combobox(self): sql = "SELECT samochody.id_samochodu, samochody.marka, samochody.model from rezerwacje INNER JOIN samochody " \ "on rezerwacje.id_samochodu = samochody.id_samochodu WHERE samochody.zarezerwowany = '1' " \ "and rezerwacje.koniec_rezerwacji IS NULL" tmp_table = [] query_type = SelectQuery() self.connection = ConnectToSQLdb(query_type) table_of_result = self.connection.execute_query(self.connection.get_cursor(), sql) self.close_all() for res in table_of_result: tmp = '' it = Iterator(res) it.set_first() while it.is_done(): tmp += str(it.get_current_item()) + ' ' it.next() tmp_table.append(tmp) print(tmp_table) return tmp_table
def create_list_of_car(self): sql = 'SELECT id_samochodu, marka, model, rok_produkcji FROM Samochody WHERE zarezerwowany = 1' query_type = SelectQuery() connection = ConnectToSQLdb(query_type) self.list_of_car = connection.execute_query(connection.get_cursor(), sql)