forked from hlilyjiaxin/mysql_python_DB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtets.py
More file actions
138 lines (121 loc) · 4.2 KB
/
Copy pathtets.py
File metadata and controls
138 lines (121 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3
# coding=utf-8
import pymysql
import numpy as np
from tkinter import *
#选课
def insert_choose_course(SNO,CNO,GRADE):
db = pymysql.connect('localhost', 'root', 'huangxiao','student',charset='utf8')
cursor = db.cursor()
sql = "insert ignore SC (SNO,CNO,GRADE) values ('%s','%s',%d)" % (SNO,CNO,GRADE)
cursor.execute(sql)
db.commit()
db.close()
#退课
def delete_choose_course(CNO):
db = pymysql.connect('localhost', 'root', 'huangxiao','student',charset='utf8')
cursor = db.cursor()
sql = "delete from SC where CNO = '%s'" % CNO
cursor.execute(sql)
db.commit()
db.close()
#打印学生信息
def display_student(text,LOGN):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "SELECT * FROM S where S.LOGN='%s'"%LOGN
cursor.execute(sql)
col=[]
for i in list(np.array(cursor.description)):
col.append(i[0])
text.insert(END,'%s %4s %4s %4s %4s'%tuple(col[0:5]))
text.insert(END,'\n')
result = cursor.fetchall()
for row in result:
text.insert(END,'%s %4s %4s %4s %4s'%tuple(row[0:5]))
text.insert(END,'\n')
db.close()
#显示可选课程
def display_course(text,SNO):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "select * from C where CNO not in (select C.CNO from S,SC,C where S.SNO=SC.SNO and C.CNO=SC.CNO and S.SNO='%s')"%SNO
cursor.execute(sql)
col=[]
for i in list(np.array(cursor.description)):
col.append(i[0])
text.insert(END,col)
text.insert(END,'\n')
result = cursor.fetchall()
for row in result:
text.insert(END,row)
text.insert(END,'\n')
db.close()
#显示已选课程
def display_choose_course(text,SNO):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "select C.CNO,C.CNAME,C.CREDI,C.CDEPT,C.TNAME from S,SC,C where S.SNO=SC.SNO and C.CNO=SC.CNO and S.SNO='%s'" % SNO
cursor.execute(sql)
col=[]
for i in list(np.array(cursor.description)):
col.append(i[0])
text.insert(END,col)
text.insert(END,'\n')
result = cursor.fetchall()
for row in result:
text.insert(END,row)
text.insert(END,'\n')
db.close()
#显示学生成绩
def display_score(text,SNO):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "select C.CNO,C.CNAME,GRADE from S,SC,C where S.SNO=SC.SNO and C.CNO=SC.CNO and S.SNO='%s'"%SNO
cursor.execute(sql)
col=[]
for i in list(np.array(cursor.description)):
col.append(i[0])
text.insert(END,col)
text.insert(END,'\n')
result = cursor.fetchall()
for row in result:
text.insert(END,row)
text.insert(END,'\n')
db.close()
#老师所上的课程
def find_teacher_course(name):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "SELECT CNAME FROM C where TNAME='%s'" % name
cursor.execute(sql)
result = cursor.fetchall()
db.close()
return result
#查询选了该老师该课的学生
def find_student_score(text,CNAME,TNAME):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student',charset='utf8')
cursor = db.cursor()
sql = "select S.SNO,S.SNAME,SC.GRADE from S,SC,C where S.SNO=SC.SNO and C.CNO=SC.CNO and C.CNAME='%s' and C.TNAME='%s'"%(CNAME,TNAME)
cursor.execute(sql)
col=[]
for i in list(np.array(cursor.description)):
col.append(i[0])
text.insert(END,col)
text.insert(END,'\n')
result = cursor.fetchall()
for row in result:
text.insert(END,row)
text.insert(END,'\n')
db.close()
#老师修改成绩
def change_score(SNO,GRADE,CNAME):
db = pymysql.connect('localhost', 'root', 'huangxiao', 'student', charset='utf8')
cursor = db.cursor()
sql = "select CNO from C where CNAME='%s'" % (CNAME)
cursor.execute(sql)
result = cursor.fetchall()
sql = "replace into SC (SNO,CNO,GRADE) values ('%s','%s',%d)" % (SNO, result[0][0], int(GRADE))
cursor.execute(sql)
db.commit()
db.close()