commit 179f28b6e8c965a2b19950576631e6f2f445fb39 Author: Egor Deev <67710823+IGlek@users.noreply.github.com> Date: Sat Nov 27 06:34:09 2021 +0700 v. 1 diff --git a/main.py b/main.py new file mode 100644 index 0000000..5828935 --- /dev/null +++ b/main.py @@ -0,0 +1,81 @@ +import sqlite3 +import sys + +from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget +from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem, QTableWidget +from PyQt5 import QtCore, QtWidgets, QtGui, uic + +if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'): + QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) + +if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'): + QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) + + +class MyWidget(QMainWindow): # Ui_MainWindow + def __init__(self): + super().__init__() + uic.loadUi('rasp.ui', self) # self.setupUi(self) + self.connection = sqlite3.connect("table.db") + self.cursor = self.connection.cursor() + # По умолчанию будем выводить все данные из таблицы + self.table() + + def table(self): + try: + # РАСПИСАНИЕ + print(1) + with self.connection: + all_day = self.cursor.execute("SELECT * FROM timetable").fetchall() + # Заполним размеры таблицы + tables = [self.Mon_school, self.Tue_school, self.Wed_school, + self.Thu_school, self.Fri_school, self.Sat_school] + print(2) + for day in tables: + day = day.QTableWidget.QTableView + day.setSpan(8, 1) + print(3) + # Заполняем таблицу элементами + i, row = enumerate(all_day[tables.index(day)]) + print(i, row) + for j, elem in enumerate(row): + self.tableWidget_2.setItem( + i, j, QTableWidgetItem(str(elem))) + + """ + # ВСЕ ФИЛЬМЫ + with self.connection: + res = self.cursor.execute("SELECT * FROM films").fetchall() + # Заполним размеры таблицы + self.tableWidget.setColumnCount(5) + self.tableWidget.setRowCount(0) + # Заполняем таблицу элементами + self.tableWidget.setHorizontalHeaderLabels(["ИД", "Название фильм", "Год выпуска", + "Жанр", "Продолжительность"]) + for i, row in enumerate(res): + self.tableWidget.setRowCount( + self.tableWidget.rowCount() + 1) + for j, elem in enumerate(row): + if j == 3: + for n, name in gnr: + if n == elem: + self.tableWidget.setItem( + i, j, QTableWidgetItem(str(name))) + break + else: + self.tableWidget.setItem( + i, j, QTableWidgetItem(str(elem))) + """ + except Exception: + QMessageBox.about(self, 'Ошибка!', "Таблица данных не найдена!") + + def closeEvent(self, event): + # При закрытии формы закроем и наше соединение с базой данных + self.connection.close() + + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = MyWidget() + ex.show() + sys.exit(app.exec_()) \ No newline at end of file diff --git a/rasp.ui b/rasp.ui new file mode 100644 index 0000000..1145929 --- /dev/null +++ b/rasp.ui @@ -0,0 +1,1164 @@ + + + MainWindow + + + + 0 + 0 + 1042 + 754 + + + + MainWindow + + + + + + + + + + 0 + + + + Расписание + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Понедельник + + + + + + + + + + + 16777215 + 80 + + + + + 0 + 0 + + + + + + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Вторник + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Среда + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + + + + 10 + 75 + true + + + + Добавить предмет + + + Qt::AlignCenter + + + + + + + 0 + 30 + + + + + 9 + + + QLayout::SetFixedSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 30 + + + + + Пн + + + + + Вт + + + + + Ср + + + + + Чт + + + + + Пт + + + + + Сб + + + + + Вс + + + + + + + + + 0 + 30 + + + + + След. + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + -1 + 50 + false + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Добавить + + + + + combo1 + add_line + add_but + + + + + + + 10 + 75 + true + + + + Изменть предмет + + + Qt::AlignCenter + + + + + + + 0 + 30 + + + + + 9 + + + QLayout::SetFixedSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 30 + + + + + Пн + + + + + Вт + + + + + Ср + + + + + Чт + + + + + Пт + + + + + Сб + + + + + Вс + + + + + + + + + 0 + 30 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + -1 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Обновить + + + + + + + + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Четверг + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Пятница + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Суббота + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + + + + 10 + 75 + true + + + + Удалить предмет + + + Qt::AlignCenter + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + + + + 0 + 30 + + + + + Везде + + + + + Пн + + + + + Вт + + + + + Ср + + + + + Чт + + + + + Пт + + + + + Сб + + + + + Вс + + + + + + + + + 0 + 30 + + + + + Любой + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + -1 + 50 + false + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Удалить + + + + + + + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Обнуление + + + + + + + + Del_Space + Add_Upd + Saturday + Friday + Thursday + Wednesday + Tuesday + Monday + + + + Заметки + + + + + + + + 10 + 430 + 681 + 251 + + + + + 10 + + + + 2 + + + + Сделать + + + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Выполнено + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + 240 + 10 + 411 + 51 + + + + + + + + + + Добавить + + + + + + + + 230 + 10 + 411 + 111 + + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Добавить + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + + + + Редактрировать + + + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Обновить + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + 10 + 130 + 211 + 51 + + + + + + + 240 + 10 + 411 + 171 + + + + + + + + + + + + 710 + 430 + 261 + 251 + + + + + 10 + 75 + true + + + + Просмотр заметки + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + 10 + 20 + 241 + 221 + + + + + + 10 + 10 + 221 + 31 + + + + + За всё время + + + + + За месяц + + + + + За неделю + + + + + На опред. дату + + + + + На опред. время + + + + + + + 10 + 170 + 221 + 41 + + + + + -1 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + + + Показать + + + + + + + + 10 + 10 + 961 + 401 + + + + + + + + + + + + + + &Sig in + + + + + &Sign in + + + + + + diff --git a/sql.py b/sql.py new file mode 100644 index 0000000..1a35f0e --- /dev/null +++ b/sql.py @@ -0,0 +1,111 @@ +import sqlite3 + + +class SQLighter: + def __init__(self, database): + """Подключаемся к БД и сохраняем курсор соединения""" + self.connection = sqlite3.connect(database) + self.cursor = self.connection.cursor() + + # КОМАНДЫ ДЛЯ УРОКОВ + def group_exists(self, id_group): + """Проверяем, есть ли уже группа в базе""" + with self.connection: + result = self.cursor.execute('SELECT * FROM `group` WHERE `id_group` = ?', (id_group,)).fetchall() + return bool(len(result)) + + def add_group(self, domain, id_group, name, last_post, type): + """Добавляем новую группу в таблицу""" + with self.connection: + return self.cursor.execute("INSERT INTO `group` (`domain`, `id_group`, `name`, `last_post`, `type`) " + "VALUES(?,?,?,?,?)", (domain, id_group, name, last_post, type)) + + def update_last_post(self, domain, last_post): + """Обновляем статус группы""" + with self.connection: + return self.cursor.execute("UPDATE `group` SET `last_post` = ? WHERE `domain` = ?", (last_post, domain)) + + def id_group_lst(self): + """Список всех айди групп""" + with self.connection: + dt = self.cursor.execute(f'SELECT id_group FROM `group`').fetchall() + return [i[0] for i in dt] + + def get_last_post(self, idg): + """Получение последнего поста""" + with self.connection: + return self.cursor.execute("SELECT last_post FROM `group` WHERE `id` = ?", (idg,)).fetchone() + + def domain_by_id(self, idg): + """Получение домена по айди""" + with self.connection: + return self.cursor.execute("SELECT domain FROM `group` WHERE `id` = ?", (idg,)).fetchone() + + def get_group_id(self, id_group): + """Получение айди группы в базе данных""" + with self.connection: + return self.cursor.execute("SELECT id FROM `group` WHERE `id_group` = ?", (id_group,)).fetchone()[0] + + # СВЯЗКА ПОЛЬЗОВАТЕЛЯ + def user_exists(self, id_user): + """Проверяем, есть ли уже пользователь в базе""" + with self.connection: + result = self.cursor.execute('SELECT * FROM `user` WHERE `id_user` = ?', (id_user,)).fetchall() + return bool(len(result)) + + def add_user(self, id_user): + """Добавляем нового пользователя""" + with self.connection: + return self.cursor.execute(f"INSERT INTO `user` (`id_user`, `groups`) VALUES(?,?)", (id_user, "")) + + def add_group_user(self, num, id_user, group): + """Обновляем группы пользователя""" + with self.connection: + if num: + groups = str(self.cursor.execute("SELECT groups FROM `user` WHERE `id_user` = ?", + (id_user,)).fetchone()[0]) + str(group) + " " + return self.cursor.execute(f"UPDATE `user` SET `groups` = ? WHERE `id_user` = ?", (groups, id_user)) + else: + lst = self.cursor.execute("SELECT groups FROM `user` WHERE `id_user` = ?", (id_user,)).fetchone() + groups = [i for i in lst[0].split()] + del groups[groups.index(str(group))] + groups = " ".join(groups) + " " + return self.cursor.execute(f"UPDATE `user` SET `groups` = ? WHERE `id_user` = ?", (groups, id_user)) + + def get_user_groups(self, id_user): + """Получаем все группы пользователя""" + with self.connection: + lst = self.cursor.execute("SELECT groups FROM `user` WHERE `id_user` = ?", (id_user,)).fetchone() + return [int(i) for i in lst[0].split()] + + def id_user_lst(self): + """Список айди""" + with self.connection: + dt = self.cursor.execute(f'SELECT id_user, groups FROM `user` WHERE `status` = 1').fetchall() + return [list(i) for i in dt] + + def upd_user_status(self, id_user): + """Обновление статуса подписки""" + with self.connection: + st = self.cursor.execute("SELECT status FROM `user` WHERE `id_user` = ?", (id_user,)).fetchone()[0] + if st: + self.cursor.execute("UPDATE `user` SET `status` = ? WHERE `id_user` = ?", (0, id_user)) + return 0 + else: + self.cursor.execute("UPDATE `user` SET `status` = ? WHERE `id_user` = ?", (1, id_user)) + return 1 + + def get_groups_user(self, id_user): + """Получение полных данных на все группы на которые подписан пользователь""" + with self.connection: + lst = self.cursor.execute("SELECT groups FROM `user` WHERE `id_user` = ?", (id_user,)).fetchone() + lst = [int(i) for i in lst[0].split()] + data = [] + for i in lst: + grp = self.cursor.execute('SELECT * FROM `group` WHERE `id` = ?', (i,)).fetchone() + data.append(list(grp)) + return data + + def close(self): + """Закрываем соединение с БД""" + self.connection.close() diff --git a/table.db b/table.db new file mode 100644 index 0000000..dd0332a Binary files /dev/null and b/table.db differ