2008-05-29 10:15:21 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: utf-8
|
|
|
|
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import sys
|
|
|
|
from pysqlite2 import dbapi2 as sqlite
|
|
|
|
from PyQt4.QtCore import *
|
|
|
|
from PyQt4.QtGui import *
|
2008-06-04 19:35:09 +02:00
|
|
|
#from PyQt4.QtSql import *
|
2008-05-29 10:15:21 +02:00
|
|
|
from main import *
|
|
|
|
from assignment import *
|
|
|
|
from reading import *
|
|
|
|
from schedule import *
|
|
|
|
from calendar import *
|
2008-06-04 19:35:09 +02:00
|
|
|
from book import *
|
|
|
|
from course import *
|
2008-05-29 10:15:21 +02:00
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initDB():
|
|
|
|
conn = sqlite.connect('egon.db')
|
2008-05-29 10:15:21 +02:00
|
|
|
curs = conn.cursor()
|
|
|
|
return curs, conn
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initNewDB():
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor, conn = initDB()
|
|
|
|
initAssignmentDB(cursor)
|
|
|
|
initReadingDB(cursor)
|
|
|
|
initScheduleDB(cursor)
|
|
|
|
initBookDB(cursor)
|
|
|
|
initCourseDB(cursor)
|
|
|
|
exitDB(conn)
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initAssignmentDB(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE Assignment (
|
|
|
|
aid INTEGER PRIMARY KEY,
|
|
|
|
date TEXT,
|
|
|
|
description TEXT,
|
|
|
|
available BOOLEAN,
|
|
|
|
begun BOOLEAN,
|
|
|
|
finished BOOLEAN,
|
|
|
|
delivered BOOLEAN
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initReadingDB(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE Reading (
|
|
|
|
rid INTEGER PRIMARY KEY,
|
|
|
|
week TEXT,
|
|
|
|
chapter TEXT,
|
|
|
|
pages TEXT
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initScheduleDB(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE Lesson (
|
|
|
|
lid INTEGER PRIMARY KEY,
|
|
|
|
day TEXT,
|
|
|
|
fromtime TEXT,
|
|
|
|
totime TEXT,
|
|
|
|
type TEXT,
|
|
|
|
room TEXT
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initBookDB(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE Book (
|
|
|
|
isbn TEXT PRIMARY KEY,
|
|
|
|
title TEXT,
|
|
|
|
author TEXT,
|
|
|
|
edition INTEGER
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initCourseDB(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE Course (
|
|
|
|
code TEXT PRIMARY KEY,
|
|
|
|
title TEXT,
|
|
|
|
short TEXT
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initAssignmentInCourse(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE assignmentInCourse (
|
|
|
|
assignment INTEGER,
|
|
|
|
course INTEGER
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initReadingInCourse(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE readingInCourse (
|
|
|
|
reading INTEGER,
|
|
|
|
course INTEGER
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initLessonInCourse(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE lessonInCourse (
|
|
|
|
lesson INTEGER,
|
|
|
|
course INTEGER
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def initCourseUsesBook(cursor):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor.execute('''
|
|
|
|
CREATE TABLE courseUsesBook (
|
|
|
|
course INTEGER,
|
|
|
|
book TEXT
|
|
|
|
)
|
|
|
|
''')
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def addNewBook(isbn, title, author, edition, course):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor, conn = initDB()
|
|
|
|
|
|
|
|
bookQuery = '''
|
|
|
|
INSERT INTO Book
|
|
|
|
VALUES (%s, %s, %s, %i)
|
|
|
|
''' % (isbn, title, author, edition)
|
|
|
|
courseUsesBookQuery = '''
|
|
|
|
INSERT INTO courseUsesBook
|
|
|
|
VALUES (%i, %s)
|
|
|
|
''' % (course, isbn)
|
|
|
|
|
|
|
|
cursor.execute(bookQuery)
|
|
|
|
cursor.execute(courseUsesBookQuery)
|
|
|
|
|
|
|
|
exitDB(conn)
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def addNewCourse(code, title, short):
|
2008-05-29 10:15:21 +02:00
|
|
|
cursor, conn = initDB()
|
|
|
|
|
|
|
|
courseQuery = '''
|
|
|
|
INSERT INTO Course
|
|
|
|
VALUES (%s, %s, %s)
|
|
|
|
''' % (code, title, short)
|
|
|
|
|
|
|
|
cursor.execute(courseQuery)
|
|
|
|
|
|
|
|
exitDB(conn)
|
|
|
|
|
2008-06-04 19:35:09 +02:00
|
|
|
def exitDB(conn):
|
2008-05-29 10:15:21 +02:00
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
initNewDB()
|