mirror of
https://github.com/EDeev/school_table.git
synced 2026-06-16 03:21:13 +03:00
v. 2
This commit is contained in:
parent
179f28b6e8
commit
5a896ae00a
3 changed files with 911 additions and 615 deletions
216
main.py
216
main.py
|
|
@ -1,9 +1,10 @@
|
||||||
|
import datetime as dt
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget
|
|
||||||
from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem, QTableWidget
|
|
||||||
from PyQt5 import QtCore, QtWidgets, QtGui, uic
|
from PyQt5 import QtCore, QtWidgets, QtGui, uic
|
||||||
|
from PyQt5.QtWidgets import QApplication, QMessageBox, QMainWindow, QTableWidgetItem
|
||||||
|
from PyQt5.QtWidgets import QWidget, QTableView, QTableWidget, QComboBox
|
||||||
|
|
||||||
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
|
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
|
||||||
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
|
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
|
||||||
|
|
@ -18,59 +19,192 @@ class MyWidget(QMainWindow): # Ui_MainWindow
|
||||||
uic.loadUi('rasp.ui', self) # self.setupUi(self)
|
uic.loadUi('rasp.ui', self) # self.setupUi(self)
|
||||||
self.connection = sqlite3.connect("table.db")
|
self.connection = sqlite3.connect("table.db")
|
||||||
self.cursor = self.connection.cursor()
|
self.cursor = self.connection.cursor()
|
||||||
# По умолчанию будем выводить все данные из таблицы
|
|
||||||
|
# РАСПИСАНИЕ
|
||||||
|
self.add_but.clicked.connect(self.add) # ДОБАВЛЕНИЕ ПРЕДМЕТОВ
|
||||||
|
self.upd_but.clicked.connect(self.upd) # ИЗМЕНЕНИЕ ПРЕДМЕТОВ
|
||||||
|
self.clear_but.clicked.connect(self.clear) # УБИРАНИЕ ПРЕДМЕТОВ
|
||||||
|
self.del_but.clicked.connect(self.delete) # УДАЛЕНИЕ ПРЕДМЕТОВ
|
||||||
|
|
||||||
|
# ДАННЫЕ ТАБЛИЦЫ
|
||||||
self.table()
|
self.table()
|
||||||
|
|
||||||
def table(self):
|
def table(self):
|
||||||
try:
|
try:
|
||||||
# РАСПИСАНИЕ
|
# РАСПИСАНИЕ
|
||||||
print(1)
|
|
||||||
with self.connection:
|
with self.connection:
|
||||||
all_day = self.cursor.execute("SELECT * FROM timetable").fetchall()
|
all_day = self.cursor.execute("SELECT * FROM timetable").fetchall()
|
||||||
# Заполним размеры таблицы
|
|
||||||
tables = [self.Mon_school, self.Tue_school, self.Wed_school,
|
tables = [self.Mon_school, self.Tue_school, self.Wed_school,
|
||||||
self.Thu_school, self.Fri_school, self.Sat_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)))
|
|
||||||
|
|
||||||
"""
|
for day in tables:
|
||||||
# ВСЕ ФИЛЬМЫ
|
weekday, subjects = all_day[tables.index(day)], []
|
||||||
with self.connection:
|
for i in range(10):
|
||||||
res = self.cursor.execute("SELECT * FROM films").fetchall()
|
if i > 1:
|
||||||
# Заполним размеры таблицы
|
if weekday[i]:
|
||||||
self.tableWidget.setColumnCount(5)
|
obj = self.cursor.execute(f"SELECT name FROM "
|
||||||
self.tableWidget.setRowCount(0)
|
f"lessons WHERE `id` = {weekday[i]}").fetchone()[0]
|
||||||
# Заполняем таблицу элементами
|
else:
|
||||||
self.tableWidget.setHorizontalHeaderLabels(["ИД", "Название фильм", "Год выпуска",
|
obj = ""
|
||||||
"Жанр", "Продолжительность"])
|
subjects.append((obj, ))
|
||||||
for i, row in enumerate(res):
|
day.setColumnCount(1)
|
||||||
self.tableWidget.setRowCount(
|
day.setHorizontalHeaderLabels(["Предмет"])
|
||||||
self.tableWidget.rowCount() + 1)
|
day.setRowCount(0)
|
||||||
for j, elem in enumerate(row):
|
|
||||||
if j == 3:
|
for i, row in enumerate(subjects):
|
||||||
for n, name in gnr:
|
day.setRowCount(day.rowCount() + 1)
|
||||||
if n == elem:
|
for j, elem in enumerate(row):
|
||||||
self.tableWidget.setItem(
|
day.setItem(i, j, QTableWidgetItem(str(elem)))
|
||||||
i, j, QTableWidgetItem(str(name)))
|
day.horizontalHeader().setStretchLastSection(True)
|
||||||
break
|
|
||||||
|
# ЗАПОЛНЕНИЕ ВЫПАДАЮЩИХ СПИСКОВ ADD / UPD / DEL
|
||||||
|
try:
|
||||||
|
with self.connection:
|
||||||
|
lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall()
|
||||||
|
lessons = [i[0] for i in lessons]
|
||||||
|
for choose_obj in [self.choose_obj1, self.choose_obj2, self.choose_obj3]:
|
||||||
|
choose_obj.clear()
|
||||||
|
if choose_obj == self.choose_obj1:
|
||||||
|
choose_obj.insertItem(0, "Новый предмет")
|
||||||
|
choose_obj.insertItems(1, lessons)
|
||||||
else:
|
else:
|
||||||
self.tableWidget.setItem(
|
choose_obj.insertItems(0, lessons)
|
||||||
i, j, QTableWidgetItem(str(elem)))
|
except Exception:
|
||||||
"""
|
pass
|
||||||
|
|
||||||
|
# ВСЕ ЗАМЕТКИ
|
||||||
|
with self.connection:
|
||||||
|
note = self.cursor.execute("SELECT `date`, `note` FROM notes").fetchall()
|
||||||
|
maintable = self.maintable
|
||||||
|
maintable.setColumnCount(2)
|
||||||
|
maintable.setRowCount(0)
|
||||||
|
maintable.setHorizontalHeaderLabels(["Дата", "Заметка"])
|
||||||
|
|
||||||
|
for i, row in enumerate(note):
|
||||||
|
maintable.setRowCount(maintable.rowCount() + 1)
|
||||||
|
for j, elem in enumerate(row):
|
||||||
|
maintable.setItem(i, j, QTableWidgetItem(str(elem)))
|
||||||
|
maintable.horizontalHeader().setStretchLastSection(True)
|
||||||
|
|
||||||
|
# ЗАМЕТКИ ПОД РАСПИСАНИЕМ
|
||||||
|
with self.connection:
|
||||||
|
note = self.cursor.execute("SELECT `date`, `note` FROM notes").fetchall()
|
||||||
|
notes = [self.Mon_note, self.Tue_note, self.Wed_note, self.Thu_note, self.Fri_note, self.Sat_note]
|
||||||
|
|
||||||
|
week = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []}
|
||||||
|
for i in note:
|
||||||
|
weekday = dt.datetime.weekday(i[0])
|
||||||
|
if weekday != 6:
|
||||||
|
week[weekday].append(i)
|
||||||
|
|
||||||
|
for write in notes:
|
||||||
|
write.setColumnCount(2)
|
||||||
|
write.setRowCount(0)
|
||||||
|
write.setHorizontalHeaderLabels(["Дата", "Заметка"])
|
||||||
|
|
||||||
|
for i, row in enumerate(week[notes.index(write)]):
|
||||||
|
write.setRowCount(write.rowCount() + 1)
|
||||||
|
for j, elem in enumerate(row):
|
||||||
|
write.setItem(i, j, QTableWidgetItem(str(elem)))
|
||||||
|
write.horizontalHeader().setStretchLastSection(True)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
QMessageBox.about(self, 'Ошибка!', "Таблица данных не найдена!")
|
QMessageBox.about(self, 'Ошибка!', "Таблица данных не найдена!")
|
||||||
|
|
||||||
|
def add(self):
|
||||||
|
day = self.weekday1.currentIndex()
|
||||||
|
obj = self.object1.currentIndex()
|
||||||
|
txt1 = self.add_line.text()
|
||||||
|
txt2 = self.choose_obj1.currentText()
|
||||||
|
if txt1 or txt2 != "Новый предмет":
|
||||||
|
with self.connection:
|
||||||
|
lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall()
|
||||||
|
lessons = [i[0] for i in lessons]
|
||||||
|
if txt1:
|
||||||
|
if txt1 not in lessons:
|
||||||
|
with self.connection:
|
||||||
|
self.cursor.execute(f"INSERT INTO `lessons` (`name`) VALUES(?)", (txt1,))
|
||||||
|
lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall()
|
||||||
|
lessons = [i[0] for i in lessons]
|
||||||
|
with self.connection:
|
||||||
|
index = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (txt1,)).fetchone()[0]
|
||||||
|
else:
|
||||||
|
with self.connection:
|
||||||
|
index = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (txt2,)).fetchone()[0]
|
||||||
|
with self.connection:
|
||||||
|
less = self.cursor.execute("SELECT * FROM `timetable` WHERE `id` = ?", (day + 1,)).fetchone()
|
||||||
|
less = list(less)[2:]
|
||||||
|
if None in less:
|
||||||
|
if obj == 0:
|
||||||
|
k = 0
|
||||||
|
for les in reversed(less):
|
||||||
|
if les is not None:
|
||||||
|
obj = len(less) - k + 1
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
k += 1
|
||||||
|
if k == len(less):
|
||||||
|
obj = 1
|
||||||
|
with self.connection:
|
||||||
|
self.cursor.execute(f"UPDATE `timetable` SET `less_{obj}` = ? WHERE `id` = ?", (index, day + 1))
|
||||||
|
for choose_obj in [self.choose_obj1, self.choose_obj2]:
|
||||||
|
choose_obj.clear()
|
||||||
|
choose_obj.insertItem(0, "Новый предмет")
|
||||||
|
self.add_line.clear()
|
||||||
|
self.table()
|
||||||
|
else:
|
||||||
|
for choose_obj in [self.choose_obj1, self.choose_obj2]:
|
||||||
|
choose_obj.clear()
|
||||||
|
choose_obj.insertItem(0, "Новый предмет")
|
||||||
|
choose_obj.insertItems(1, lessons)
|
||||||
|
QMessageBox.about(self, 'Ошибка!', "В этом дне уже расписание всё занято!")
|
||||||
|
else:
|
||||||
|
QMessageBox.about(self, 'Ошибка!', "Введите предмет, который желаете добавить!")
|
||||||
|
|
||||||
|
def upd(self):
|
||||||
|
obj = self.choose_obj2.currentText()
|
||||||
|
txt = self.upd_line.text()
|
||||||
|
if txt != "":
|
||||||
|
with self.connection:
|
||||||
|
self.cursor.execute(f"UPDATE `lessons` SET `name` = ? WHERE `name` = ?", (txt, obj))
|
||||||
|
self.upd_line.clear()
|
||||||
|
self.table()
|
||||||
|
else:
|
||||||
|
QMessageBox.about(self, 'Ошибка!', "Вы не ввели новое название!")
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
day = self.weekday3.currentIndex()
|
||||||
|
obj = self.object3.currentIndex()
|
||||||
|
|
||||||
|
for wkd in range(1, 7):
|
||||||
|
if day == 0 or day == wkd:
|
||||||
|
for less in range(1, 9):
|
||||||
|
if obj == 0 or obj == less:
|
||||||
|
with self.connection:
|
||||||
|
self.cursor.execute(f"UPDATE `timetable` SET `less_{less}` = ? WHERE `id` = ?", (None, wkd))
|
||||||
|
self.table()
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
index = self.choose_obj3.currentText()
|
||||||
|
with self.connection:
|
||||||
|
ids = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (index, )).fetchone()[0]
|
||||||
|
self.cursor.execute("DELETE FROM `lessons` WHERE `id` = ?", (ids, ))
|
||||||
|
|
||||||
|
for day in range(1, 7):
|
||||||
|
with self.connection:
|
||||||
|
lessons = self.cursor.execute("SELECT * FROM `timetable` WHERE `id` = ?", (day,)).fetchone()
|
||||||
|
lessons = list(lessons)[2:]
|
||||||
|
if ids in lessons:
|
||||||
|
for less in range(1, 9):
|
||||||
|
if ids == lessons[less - 1]:
|
||||||
|
with self.connection:
|
||||||
|
self.cursor.execute(f"UPDATE `timetable` SET `less_{less}` = ? WHERE `id` = ?", (None, day))
|
||||||
|
self.table()
|
||||||
|
|
||||||
|
def notes(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
# При закрытии формы закроем и наше соединение с базой данных
|
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -78,4 +212,4 @@ if __name__ == '__main__':
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
ex = MyWidget()
|
ex = MyWidget()
|
||||||
ex.show()
|
ex.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
|
||||||
BIN
table.db
BIN
table.db
Binary file not shown.
Loading…
Add table
Reference in a new issue