예제 #1
0
 def fillForm(self):
     conn = db.getConnection()
     cursor = conn.cursor()
     cursor.execute(
         'SELECT name, hours, code, description, subject_type, withTest FROM subjects WHERE id = ?',
         [self.id])
     result = cursor.fetchone()
     conn.close()
     self.parent.lineEditName.setText(str(result[0]))
     self.parent.lineEditHours.setText(str(result[1]))
     self.parent.lineEditCode.setText(str(result[2]))
     self.parent.lineEditDescription.setText(str(result[3]))
     if result[5]:
         self.parent.radioWithTest.setChecked(True)
     else:
         self.parent.radioWithoutTest.setChecked(True)
     if result[4] == 'A':
         self.parent.radioA.setChecked(True)
     elif result[4] == 'B':
         self.parent.radioB.setChecked(True)
     else:
         self.parent.radioC.setChecked(True)
예제 #2
0
 def fillForm(self):
     conn = db.getConnection()
     cursor = conn.cursor()
     cursor.execute(
         'SELECT name, hours, code, description, divisible, type FROM subjects WHERE id = ?',
         [self.id])
     result = cursor.fetchone()
     conn.close()
     self.parent.lineEditName.setText(str(result[0]))
     self.parent.lineEditHours.setText(str(result[1]))
     self.parent.lineEditCode.setText(str(result[2]))
     self.parent.lineEditDescription.setText(str(result[3]))
     if result[4]:
         self.parent.radioYes.setChecked(True)
     else:
         self.parent.radioNo.setChecked(True)
     if result[5] == 'lec':
         self.parent.radioLec.setChecked(True)
     elif result[5] == 'lab':
         self.parent.radioLab.setChecked(True)
     else:
         self.parent.radioAny.setChecked(True)
예제 #3
0
 def new(self):
     ioHandler.removeTables()
     Database.setup()
     self.tabListener(0)
예제 #4
0
 def setupSubjects(self):
     # Setup subjects tree view
     self.tree = tree = self.parent.treeSubjects
     self.model = model = QtGui.QStandardItemModel()
     model.setHorizontalHeaderLabels(
         ['ID', 'Available', 'Subject Code', 'Subject Name'])
     tree.setModel(model)
     tree.setColumnHidden(0, True)
     tree.setColumnHidden(5, True)
     # Populate tree with values
     conn = db.getConnection()
     cursor = conn.cursor()
     # Get subjects for listing
     cursor.execute('SELECT id, name, code FROM subjects')
     subjects = cursor.fetchall()
     # Subjects that the current section have
     currentSubjects = []
     # Subjects that are shared to the current section
     # [(sharing_id, subject_id, sections [str of list - load using json.loads])]
     sharedSubjects = []
     if self.id:
         cursor.execute('SELECT subjects FROM sections WHERE id = ?',
                        [self.id])
         # Convert result into list of int
         currentSubjects = list(
             map(lambda id: int(id), json.loads(cursor.fetchall()[0][0])))
         # Get active sharing by subject
         for id in currentSubjects:
             cursor.execute(
                 'SELECT id, subjectId, sections FROM sharings WHERE subjectId = ? AND final = 1',
                 [id])
             sharedSubjects.append(cursor.fetchone())
         sharedSubjects = [sharing for sharing in sharedSubjects if sharing]
         # Get section names
         # {id: name}
         sectionNames = []
         cursor.execute('SELECT id, name FROM sections WHERE active = 1')
         sectionNames = dict(cursor.fetchall())
     conn.close()
     for subject in subjects:
         subjectId = QtGui.QStandardItem(str(subject[0]))
         subjectId.setEditable(False)
         availability = QtGui.QStandardItem()
         availability.setCheckable(True)
         availability.setEditable(False)
         availability.setCheckState(2 if subject[0] in
                                    currentSubjects else 0)
         shared = QtGui.QStandardItem('')
         shared.setCheckable(True)
         shared.setEditable(False)
         shareId = QtGui.QStandardItem()
         shareId.setEditable(False)
         for sharing in sharedSubjects:
             if sharing[1] != subject[0]:
                 continue
             sectionList = list(
                 map(lambda id: int(id), json.loads(sharing[2])))
             if self.id not in sectionList:
                 continue
             sectionList.remove(self.id)
             sectionList = ', '.join(
                 list(map(lambda id: sectionNames[id], sectionList)))
             shared.setText(sectionList)
             shared.setCheckState(2)
             shareId.setText(str(sharing[0]))
         code = QtGui.QStandardItem(subject[2])
         code.setEditable(False)
         name = QtGui.QStandardItem(subject[1])
         name.setEditable(False)
         model.appendRow([subjectId, availability, code, name])
     model.itemChanged.connect(lambda item: self.toggleSharing(item))
예제 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
from PyQt5 import QtWidgets  #Thư viện GUI PyQt5
from components import Database as db  #import components xử lý data
from containers import Main

# Entry point for application
if __name__ == '__main__':
    if not db.checkSetup():
        db.setup(
        )  #Nếu trạng thái chương trình chưa được khởi động thì bắt đầu các hàm khởi tạo ban đầu
    app = QtWidgets.QApplication(sys.argv)
    parent = QtWidgets.QMainWindow()
    Main.MainWindow(parent)
    parent.show()
    sys.exit(app.exec_())
예제 #6
0
 def __init__(self):
     self.conn = db.getConnection()
     self.cursor = self.conn.cursor()
예제 #7
0
from PyQt5 import QtWidgets
from components import Database as db
from containers import Main
import sys

# Entry point for application
if __name__ == '__main__':
    if not db.checkSetup():
        db.setup()
    app = QtWidgets.QApplication(sys.argv)
    parent = QtWidgets.QMainWindow()
    Main.MainWindow(parent)
    parent.show()
    sys.exit(app.exec_())
예제 #8
0
def removeTables():
    conn = db.getConnection()
    cursor = conn.cursor()
    tables = list(cursor.execute("SELECT name FROM sqlite_master WHERE type IS 'table'"))
    cursor.executescript(';'.join(['DROP TABLE IF EXISTS {}'.format(table[0]) for table in tables]))
    conn.close()