数据库系统原理 课程设计:示例程序

简介: 数据库系统原理 课程设计:示例程序
import tkinter
from tkinter import *
from tkinter import ttk
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
import time
#导入ADO接口模块
from tkinter import messagebox
from tkinter.messagebox import *
import pymssql
import win32com.client
#连接服务器和数据库
cn=win32com.client.Dispatch('ADODB.Connection')
cnstr='Provider=SQLOLEDB.1;Integrated Security=SSPI;Data Source=(local)'
cn.Open(cnstr,'uu10','123456')
#打开数据库
cn.Execute("USE XSCJ")
#创建表
#cn.Execute("CREATE TABLE student( cno varchar(50), cname varchar(50),password varchar(50),english int, math int, python int,java int)")
#cn.Execute("CREATE TABLE teacher( name varchar(50),password varchar(50))")
#建立记录集合
rs=win32com.client.Dispatch('ADODB.RecordSet')
server = '127.0.0.1:1433'
user ='uu10'
userpassword ='123456'
database = 'XSCJ'
conn = pymssql.connect(server,user,userpassword,database)
cursor = conn.cursor()
try:
    cursor.execute("CREATE TABLE student( cno varchar(50), cname varchar(50),password varchar(50),english int, math int, python int,java int)")
    cursor.execute("CREATE TABLE teacher( name varchar(50),password varchar(50))")
except pymssql.OperationalError: 
    pass
#else:
#    cursor.execute("CREATE TABLE student( cno varchar(50), cname varchar(50),password varchar(50),english int, math int, python int,java int)")
#    cursor.execute("CREATE TABLE teacher( name varchar(50),password varchar(50))")
def Main():
    rt = Tk()
    rt.title('学生成绩管理系统')
    rt.geometry('605x328+800+200')
    rt.iconbitmap('77.ico')
    bg = PhotoImage(file='背景.gif')
    lab1 = Label(image=bg)
    lab1.place(x=0, y=0)
    Label(text='账户',font=("宋体",'12')).place(x=120, y=90)
    Label(text='密码',font=("宋体",'12')).place(x=120, y=130)
    e1=Entry(width=30)
    e1.focus()
    e1.place(x=190, y=90)
    e2=Entry(show='*', width=30)
    e2.place(x=190, y=130)
    # 获取当前时间
    def getTime():
        timeStr = time.strftime('%Y-%m-%d %H:%M')
        Rtime.configure(text=timeStr)
        #rt.after(1000, getTime)# 每隔1s调用函数 getTime 自身获取时间
    # 时间显示
    Rtime = tkinter.Label(rt, text='', bg='white')
    Rtime.place(x=220, y=40)
    getTime()
    def XSDL():
        s1=e1.get()
        s2=e2.get()
        cursor.execute("SELECT * FROM student WHERE CNO='%s' AND PASSWORD = '%s' " % (s1, s2))
        T=cursor.fetchone()
        if T is None:
            messagebox.showerror('登录失败', '账户或密码错误!')
        else:
            messagebox.showinfo("成功", "登录成功" )
            rt.destroy()
            rt1 = Tk()
            rt1.title('学生登录')
            rt1.geometry('605x328+800+200')
            rt1.iconbitmap('77.ico')
            def qx():
                rt1.destroy()
                Main()
            def CXCJ():
                rt2 = Tk()
                rt2.title('学生登录')
                rt2.geometry('800x400+800+200')
                rt2.iconbitmap('77.ico')
                columns = ("学号", "姓名", "英语", "数学", "python", "java")
                tree = ttk.Treeview(rt2,height=15, show="headings", columns=columns)  # 隐藏首列
                tree.column("学号", width=100)  # 表示列,不显示
                tree.column("姓名", width=100)
                tree.column("英语", width=100)
                tree.column("数学", width=100)
                tree.column("python", width=100)
                tree.column("java", width=100)
                tree.place(x=100, y=10)
                tree.heading("学号", text='学号', anchor=CENTER)
                tree.heading("姓名", text='姓名', anchor=CENTER)
                tree.heading("英语", text='英语', anchor=CENTER)
                tree.heading("数学", text='数学', anchor=CENTER)
                tree.heading("python", text='python', anchor=CENTER)
                tree.heading("java", text='java', anchor=CENTER)
                def qx2():
                    rt2.destroy()
                Button(rt2,command=qx2, text="取消", width=10).place(x=500, y=350)
                cursor.execute("select CNO,CNAME,ENGLISH,MATH,PYTHON,java from student  where cno='%s'"% s1)
                T = cursor.fetchall()
                for row in T:
                    tree.insert("", 0, values=(row[0], row[1], row[2], row[3], row[4], row[5]))
            def XGMM():
                Label(text='学号').place(x=100, y=70)
                Label(text='旧密码:').place(x=100, y=95)
                Label(text='新密码:').place(x=100, y=120)
                e3 = Entry(width=30)
                e3.place(x=200, y=70)
                e4 = Entry(show='*', width=30)
                e4.place(x=200, y=95)
                e5 = Entry(show='*', width=30)
                e5.place(x=200, y=120)
                def qr():
                    s3 = e3.get()
                    s4 = e4.get()
                    s5 = e5.get()
                    cursor.execute("SELECT * FROM student WHERE CNO='%s' AND PASSWORD = '%s' " % (s3, s4))
                    T = cursor.fetchone()
                    if T is None:
                        messagebox.showerror('修改失败', '账户或密码错误!')
                    else:
                        rs.LockType = 4
                        cursor.execute("UPDATE  STUDENT SET PASSWORD='%s' WHERE CNO= '%s' " % (s5, s3))
                        try:
                            conn.commit()
                        except pymssql.OperationalError:
                            pass
                        messagebox.showinfo("成功", '密码修改成功!!!')
                Button(command=qr, text="确认", width=10).place(x=140, y=150)
#                Button(command=quit, text="退出", width=10).place(x=240, y=150)
                Button(command=qx, text="回到首页", width=10).place(x=340, y=150)
            Button(command=XGMM, text="修改密码", width=10).place(x=140, y=150)
            Button(command=CXCJ, text="查询成绩", width=10).place(x=240, y=150)
            Button(command=qx, text="回到首页", width=10).place(x=340, y=150)
    def JSDL():
        s1=e1.get()
        s2=e2.get()
        cursor.execute("SELECT * FROM teacher WHERE name='%s' AND PASSWORD = '%s' " % (s1, s2))
        T=cursor.fetchone()
        if T is None:
            messagebox.showerror('登录失败', '账户或密码错误!')
        else:
            messagebox.showinfo("成功", "登录成功" )
            rt.destroy()
            rt1 = Tk()
            rt1.title('学生成绩管理')
            rt1.geometry('920x600+600+100')
            rt1.iconbitmap('77.ico')
            Label(text='学生成绩管理',font=20,fg='red').place(x=350, y=10)
            Label(text='学号:',font=10).place(x=10, y=50)
            Label(text='姓名:',font=10).place(x=310, y=50)
            Label(text='英语:',font=10).place(x=610, y=50)
            Label(text='数学:',font=10).place(x=10, y=100)
            Label(text='python:',font=10).place(x=310, y=100)
            Label(text='java:',font=10).place(x=610, y=100)
            e3 = Entry(width=30)
            e3.focus()
            e3.place(x=90, y=50)
            e4 = Entry(width=30)
            e4.place(x=390, y=50)
            e5 = Entry(width=30)
            e5.place(x=690, y=50)
            e6 = Entry(width=30)
            e6.place(x=90, y=100)
            e7 = Entry(width=30)
            e7.place(x=390, y=100)
            e8 = Entry(width=30)
            e8.place(x=690, y=100)
            def qx():
                rt1.destroy()
                Main()
            # 显示所有项目
            def get():
                #清空表格
                def delButton(tree):
                    x = tree.get_children()
                    for item in x:
                        tree.delete(item)
                delButton(tree)
                cursor.execute("select CNO,CNAME,ENGLISH,MATH,PYTHON,java from student order by cno desc")
                T = cursor.fetchall()
                for row in T:
                    tree.insert("", 0, values=(row[0],row[1], row[2],row[3], row[4],row[5]))
            #添加学生信息
            def add():
                s3 = e3.get()
                s4 = e4.get()
                s5 = e5.get()
                s6 = e6.get()
                s7 = e7.get()
                s8 = e8.get()
                if len(e3.get()) == 0 or len(e4.get()) == 0:
                    messagebox.showerror("添加失败", "学号,姓名不能为空!")
                else:
                    cursor.execute("SELECT * FROM student WHERE CNO='%s' " % (s3))
                    T = cursor.fetchone()
                    if T is None:
                        rs.LockType = 4
                        cursor.execute("INSERT INTO STUDENT(CNO,CNAME,ENGLISH,MATH,PYTHON,java) VALUES('%s','%s','%s','%s','%s','%s')" %(s3, s4, s5, s6, s7, s8))
                        try:
                            conn.commit()
                        except pymssql.OperationalError:
                            pass
                        messagebox.showinfo("提示", "添加成功!")
                        tree.insert("", 0, values=(s3, s4, s5, s6, s7, s8))
                        get()
                    else:
                        messagebox.showerror('添加失败', '该学生已存在!')
            # 删除学生成绩
            def delete():
                message['text'] = ''
                try:
                    tree.item(tree.selection())['values'][0]
                except IndexError as e:
                    message['text'] = '请选择操作项目'
                    return
                message['text'] = ''
                cno = tree.item(tree.selection())['values'][0]
                rs.LockType = 4
                cursor.execute("delete from student where cno=%s",(cno))
                try:
                    conn.commit()
                except pymssql.OperationalError:
                    pass
                #showinfo(message="删除成功")
                message['text'] = '{}号删除成功'.format(cno)
                get()
            # 修改学生成绩
            def edit():
                message['text'] = ''
                try:
                    tree.item(tree.selection())['values'][0]
                except IndexError as e:
                    message['text'] = '请选择操作项目'
                    return
                old_cno = tree.item(tree.selection())['values'][0]
                old_name = tree.item(tree.selection())['values'][1]
                old_english = tree.item(tree.selection())['values'][2]
                old_math = tree.item(tree.selection())['values'][3]
                old_python = tree.item(tree.selection())['values'][4]
                old_java = tree.item(tree.selection())['values'][5]
                #顶级窗口
                edit_win = Toplevel()
                edit_win.title('修改学生信息')
                screenwidth = edit_win.winfo_screenwidth()
                screenheight = edit_win.winfo_screenheight()
                width = 300
                high = 350
                edit_win.geometry('%dx%d+%d+%d' % (width, high, (screenwidth - width) / 2, (screenheight - high) / 2))
                # 原来的项目
                Label(edit_win, text='学号').grid(row=0, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_cno), state='readonly').grid(
                    row=0, column=2)
                #Label(edit_win, text='新的学号').grid(row=1, column=1)
                #new_cno = Entry(edit_win, textvariable=StringVar(edit_win, value=old_cno))
                #new_cno.grid(row=1, column=2)                
                Label(edit_win, text='原来姓名').grid(row=2, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_name), state='readonly').grid(
                    row=2, column=2)
                Label(edit_win, text='新的姓名').grid(row=3, column=1)
                new_name = Entry(edit_win, textvariable=StringVar(edit_win, value=old_name))
                new_name.grid(row=3, column=2)
                Label(edit_win, text='原来英语成绩').grid(row=4, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_english), state='readonly').grid(
                    row=4, column=2)
                Label(edit_win, text='新的英语成绩').grid(row=5, column=1)
                new_english = Entry(edit_win, textvariable=StringVar(edit_win, value=old_english))
                new_english.grid(row=5, column=2)
                Label(edit_win, text='原来数学成绩').grid(row=6, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_math), state='readonly').grid(
                    row=6, column=2)
                Label(edit_win, text='新的数学成绩').grid(row=7, column=1)
                new_math = Entry(edit_win, textvariable=StringVar(edit_win, value=old_math))
                new_math.grid(row=7, column=2)
                Label(edit_win, text='原来python成绩').grid(row=8, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_python), state='readonly').grid(
                    row=8, column=2)
                Label(edit_win, text='新的python成绩').grid(row=9, column=1)
                new_python = Entry(edit_win, textvariable=StringVar(edit_win, value=old_python))
                new_python.grid(row=9, column=2)
                Label(edit_win, text='原来java成绩').grid(row=10, column=1)
                Entry(edit_win, textvariable=StringVar(edit_win, value=old_java), state='readonly').grid(
                    row=10, column=2)
                Label(edit_win, text='新的java成绩').grid(row=11, column=1)
                new_java = Entry(edit_win, textvariable=StringVar(edit_win, value=old_java))
                new_java.grid(row=11, column=2)
                # 数据修改处理
                def edit_record():
                    #s2 = new_cno.get()
                    s3 = new_name.get()
                    s4 = new_english.get()
                    s5 = new_math.get()
                    s6 = new_python.get()
                    s7 = new_java.get()
                    rs.LockType = 4
                    cursor.execute("update student set cname=%s,english=%s,math=%s,python=%s,java=%s where cno=%s ",(s3,s4,s5,s6,s7,old_cno))
                    try:
                        conn.commit()
                    except pymssql.OperationalError:
                        pass
                    edit_win.destroy()
                    message['text'] = "{}更新成功".format(old_cno)
                    get()
                Button(edit_win, text='更新',
                       command=edit_record).grid(row=12, column=2, sticky=W + E)
                edit_win.mainloop()###
            #查询学生成绩
            def select():
                top = Toplevel()
                top.title('查询学生信息')
                screenwidth = top.winfo_screenwidth()
                screenheight = top.winfo_screenheight()
                width = 800
                high = 600
                top.geometry('%dx%d+%d+%d' % (width, high, (screenwidth - width) / 2, (screenheight - high) / 2))
                Label(top,text='请输入学号').place(x=100, y=10)
                l1 = Entry(top,width=30)
                l1.place(x=200, y=10)
                Label(top,text='请输入姓名').place(x=100, y=50)
                l2 = Entry(top,width=30)
                l2.place(x=200, y=50)
                columns = ("学号", "姓名", "英语", "数学", "python", "java")
                tree = ttk.Treeview(top,height=15, show="headings", columns=columns)  # 隐藏首列
                tree.column("学号", width=100)  # 表示列,不显示
                tree.column("姓名", width=100)
                tree.column("英语", width=100)
                tree.column("数学", width=100)
                tree.column("python", width=100)
                tree.column("java", width=100)
                tree.place(x=100, y=100)
                tree.heading("学号", text='学号', anchor=CENTER)
                tree.heading("姓名", text='姓名', anchor=CENTER)
                tree.heading("英语", text='英语', anchor=CENTER)
                tree.heading("数学", text='数学', anchor=CENTER)
                tree.heading("python", text='python', anchor=CENTER)
                tree.heading("java", text='java', anchor=CENTER)
                def qx2():
                    top.destroy()
                def qk():
                    # 清空表格
                    def delButton(tree):
                        x = tree.get_children()
                        for item in x:
                            tree.delete(item)
                    delButton(tree)
                    l1.delete(0, 'end')
                    l2.delete(0, 'end')
                def qr():
                    # 清空表格
                    def delButton(tree):
                        x = tree.get_children()
                        for item in x:
                            tree.delete(item)
                    delButton(tree)
                    t1=l1.get()
                    t2=l2.get()
                    cursor.execute("select CNO,CNAME,ENGLISH,MATH,PYTHON,java from student  where cno='%s'" % t1)
                    T = cursor.fetchall()
                    for row in T:
                        tree.insert("", 0, values=(row[0], row[1], row[2], row[3], row[4], row[5]))
                    cursor.execute("select CNO,CNAME,ENGLISH,MATH,PYTHON,java from student  where cname='%s'" % t2)
                    T = cursor.fetchall()
                    for row in T:
                        tree.insert("", 0, values=(row[0], row[1], row[2], row[3], row[4], row[5]))
                Button(top,command=qr, text="查询", width=10).place(x=200, y=450)
                Button(top,command=qk, text="清空", width=10).place(x=350, y=450)
                Button(top,command=qx2, text="取消", width=10).place(x=500, y=450)
            #清空按钮
            def qk():
                e3.delete(0,'end')
                e4.delete(0, 'end')
                e5.delete(0, 'end')
                e6.delete(0, 'end')
                e7.delete(0, 'end')
                e8.delete(0, 'end')
            #统计模块
            def tj():
                def xs():
                    if cursor.execute("select max(english) , min(english), round(avg(english),1),COUNT (case when english between 0 and 59 then 1 end),COUNT (case when english between 60 and 69 then 1 end),COUNT (case when english between 70 and 79 then 1 end),COUNT (case when english between 80 and 89 then 1 end),COUNT (case when english between 90 and 100 then 1 end),count(*) from student")!=0:
                        S1 = cursor.fetchall()
                        S1 = ("英语",) + S1[0]
                        tree.insert("", 0, values=S1)
                        cursor.execute(
                            "select max(math), min(math), round(avg(math),1),COUNT (case when math between 0 and 59 then 1 end),COUNT (case when math between 60 and 69 then 1 end),COUNT (case when math between 70 and 79 then 1 end),COUNT (case when math between 80 and 89 then 1 end),COUNT (case when math between 90 and 100 then 1 end), count(*) from student")
                        S2 = cursor.fetchall()
                        S2 = ("数学",) + S2[0]
                        tree.insert("", 1, values=S2)
                        cursor.execute(
                            "select max(python) , min(python), round(avg(python),1),COUNT (case when python between 0 and 59 then 1 end),COUNT (case when python between 60 and 69 then 1 end),COUNT (case when python between 70 and 79 then 1 end),COUNT (case when python between 80 and 89 then 1 end),COUNT (case when python between 90 and 100 then 1 end),count(*) from student")
                        S3 = cursor.fetchall()
                        S3 = ("Python",) + S3[0]
                        tree.insert("", 0, values=S3)
                        cursor.execute(
                            "select max(java), min(java), round(avg(java),1),COUNT (case when java between 0 and 59 then 1 end),COUNT (case when java between 60 and 69 then 1 end),COUNT (case when java between 70 and 79 then 1 end),COUNT (case when java between 80 and 89 then 1 end),COUNT (case when java between 90 and 100 then 1 end), count(*) from student")
                        S4 = cursor.fetchall()
                        S4 = ("java",) + S4[0]
                        tree.insert("", 1, values=S4)
                    else:
                        showerror("统计失败", "没有学生数据无法进行统计")
                def chart():
                    """"统计数据的柱状图"""
                    # 柱状图
                    # 使图形中的中文正常编码显示
                    mpl.rcParams["font.sans-serif"] = ["SimHei"]
                    # 每个柱子下标的索引
                    cursor.execute("select * from student")
                    stu_tuple = cursor.fetchall()
                    x = np.arange(len(stu_tuple))
                    y = [x[5] for x in stu_tuple]
                    y1 = [x[6] for x in stu_tuple]
                    y2= [x[3] for x in stu_tuple]
                    y3 = [x[4] for x in stu_tuple]
                    # 柱子的宽度
                    bar_width = 0.2
                    tick_label = [x[2] for x in stu_tuple]
                    # 绘制柱状图并设置其各项属性
                    plt.bar(x, y, bar_width, align="center", color="c", label="Python", alpha=0.5)
                    plt.bar(x + bar_width, y1, bar_width, color="b", align="center", label="java", alpha=0.5)
                    plt.bar(x + 2*bar_width, y2, bar_width, color="r", align="center", label="英语", alpha=0.5)
                    plt.bar(x + 3*bar_width, y3, bar_width, color="orange", align="center", label="数学", alpha=0.5)
                    plt.tight_layout(pad=0.4, w_pad=10.0, h_pad=3.0)
                    plt.title("学生成绩统计表")
                    plt.xlabel("姓名")
                    plt.ylabel("成绩")
                    plt.xticks(x + bar_width / 2, tick_label)
                    plt.xticks(rotation=-90)
                    plt.yticks(np.arange(0, 101, 20))
                    # 添加图例
                    plt.legend(loc="upper left")
                    plt.show()
                """创建显示统计的窗口"""
                top = Toplevel()
                top.title('统计学生信息')
                screenwidth = top.winfo_screenwidth()
                screenheight = top.winfo_screenheight()
                width = 700
                high = 500
                top.geometry('%dx%d+%d+%d' % (width, high, (screenwidth - width) / 2, (screenheight - high) / 2))
                # 创建显示数据的表格
                tree = ttk.Treeview(top, show='headings', column=('object', 'max', 'min', 'average', 'fail',
                                                                            'pass', 'middle', 'good', 'super', 'count'))
                tree.column('object', width=50, anchor="center")
                tree.column('max', width=50, anchor="center")
                tree.column('min', width=50, anchor="center")
                tree.column('average', width=50, anchor="center")
                tree.column('fail', width=50, anchor="center")
                tree.column('pass', width=50, anchor="center")
                tree.column('middle', width=50, anchor="center")
                tree.column('good', width=50, anchor="center")
                tree.column('super', width=50, anchor="center")
                tree.column('count', width=50, anchor="center")
                tree.heading('object', text='课程')
                tree.heading('max', text='最高分')
                tree.heading('min', text='最低分')
                tree.heading('average', text='平均分')
                tree.heading('fail', text='不及格')
                tree.heading('pass', text='及格')
                tree.heading('middle', text='中')
                tree.heading('good', text='良')
                tree.heading('super', text='优')
                tree.heading('count', text='总人数')
                Button(top,command=chart, text="柱形图", width=15).place(x=300, y=400)
                tree.place(relx=0.02, rely=0.3, relwidth=0.96)
                xs()
            Button(command=get, text="显示所有信息", width=15).place(x=750, y=200)
            Button(command=add, text="添加学生信息", width=15).place(x=750, y=250)
            Button(command=delete, text="删除学生信息", width=15).place(x=750, y=300)
            Button(command=edit, text="修改学生信息", width=15).place(x=750, y=350)
            Button(command=select, text="查询学生信息", width=15).place(x=750, y=400)
            Button(command=tj, text="统计学生信息", width=15).place(x=750, y=450)
            Button(command=qx, text="回到首页", width=15).place(x=350, y=550)
#            Button(command=quit, text="退出", width=15).place(x=500, y=550)
            Button(command=qk, text="清空文本框", width=15).place(x=650, y=550)
            message = Label(text='', fg='red')
            message.place(x=100, y=550)
            columns= ("学号", "姓名", "英语", "数学", "python", "java")
            tree = ttk.Treeview( height=15, show="headings",columns=columns)  # 隐藏首列
            tree.column("学号", width=100)  # 表示列,不显示
            tree.column("姓名", width=100)
            tree.column("英语", width=100)
            tree.column("数学", width=100)
            tree.column("python", width=100)
            tree.column("java", width=100)
            tree.place(x=100, y=200)
            tree.heading("学号", text='学号', anchor=CENTER)
            tree.heading("姓名", text='姓名', anchor=CENTER)
            tree.heading("英语", text='英语', anchor=CENTER)
            tree.heading("数学", text='数学', anchor=CENTER)
            tree.heading("python", text='python', anchor=CENTER)
            tree.heading("java", text='java', anchor=CENTER)
            #点击列标签排序
            def treeview_sort_column(tv, col, reverse):  # Treeview、列名、排列方式
                l = [(tv.set(k, col), k) for k in tv.get_children('')]
                l.sort(reverse=reverse)  # 排序方式
                for index, (val, k) in enumerate(l):  # 根据排序后索引移动
                    tv.move(k, '', index)
                tv.heading(col, command=lambda: treeview_sort_column(tv, col, not reverse))  # 重写标题,使之成为再点倒序的标题
            for col in columns:
                tree.heading(col, text=col, command=lambda _col=col: treeview_sort_column(tree, _col, False))
            rt1.mainloop()
    #注册模块
    def zhuce():
        rt.destroy()
        rt3 = Tk()
        rt3.title('注册用户')
        rt3.geometry('600x323+800+200')
        rt3.iconbitmap('77.ico')
        bg2 = PhotoImage(file='学生背景.gif')
        lab2 = Label(image=bg2)
        lab2.place(x=-2, y=0)
        def qx():
            rt3.destroy()
            Main()
        def jszc():
            rt3.destroy()
            rt2 = Tk()
            rt2.title('教师注册')
            rt2.geometry('600x323+800+200')
            rt2.iconbitmap('77.ico')
            Label(text='请输入姓名:').place(x=100, y=70)
            Label(text='请输入密码:').place(x=100, y=95)
            e3 = Entry(width=30)
            e3.place(x=200, y=70)
            e4 = Entry(show='*', width=30)
            e4.place(x=200, y=95)
            def zc1():
                s1 = e3.get()
                s2 = e4.get()
                if len(e3.get()) == 0 and len(e4.get()) == 0:
                    messagebox.showerror("添加失败", "姓名和密码不能为空!")
                else:
                    cursor.execute("SELECT * FROM teacher WHERE name='%s' " % (s1))
                    T = cursor.fetchone()
                    if T is None:
                        rs.LockType = 4
                        cursor.execute(
                            "INSERT INTO teacher(NAME,PASSWORD) VALUES('%s','%s')" % (s1, s2))
                        try:
                            conn.commit()
                        except pymssql.OperationalError:
                            pass
                        messagebox.showinfo("提示", "添加成功!")
                    else:
                        messagebox.showerror('添加失败', '该教师已存在!')
            def zc2():
                rt2.destroy()
                Main()
            Bt1 = Button(command=zc1, text="确定", width=10)
            Bt1.place(x=200, y=120)
            Bt2 = Button(command=zc2, text="取消", width=10)
            Bt2.place(x=300, y=120)
            rt2.mainloop()
        def xszc():
            rt3.destroy()
            rt2 = Tk()
            rt2.title('学生注册')
            rt2.geometry('600x323+800+200')
            rt2.iconbitmap('77.ico')
            Label(text='请输入学号:').place(x=100, y=45)
            Label(text='请输入姓名:').place(x=100, y=70)
            Label(text='请输入密码:').place(x=100, y=95)
            e2 = Entry(width=30)
            e2.place(x=200, y=45)
            e3 = Entry(width=30)
            e3.place(x=200, y=70)
            e4 = Entry(show='*', width=30)
            e4.place(x=200, y=95)
            def zc1():
                s0 = e2.get()
                s1 = e3.get()
                s2 = e4.get()
                if len(e2.get()) == 0 and len(e3.get()) == 0 and len(e4.get()) == 0:
                    messagebox.showerror("添加失败", "学号和姓名、密码不能为空!")
                else:
                    cursor.execute("SELECT * FROM student WHERE CNO='%s' " % (s0))
                    T = cursor.fetchone()
                    if T is None:
                        rs.LockType = 4
                        cursor.execute(
                            "INSERT INTO STUDENT(CNO,CNAME,PASSWORD) VALUES('%s','%s','%s')" % (s0, s1, s2))
                        try:
                            conn.commit()
                        except pymssql.OperationalError:
                            pass
                        messagebox.showinfo("提示", "添加成功!")
                    else:
                        messagebox.showerror('添加失败', '该学生已存在!')
            def zc2():
                rt2.destroy()
                Main()
            Bt1=Button(command=zc1, text="确定", width=10)
            Bt1.place(x=200, y=120)
            Bt2 = Button(command=zc2, text="取消", width=10)
            Bt2.place(x=300, y=120)
            rt2.mainloop()
        Bt1 = Button(command=xszc, text="学生注册", width=10,height=3)
        Bt1.place(x=150, y=120)
        Bt2 = Button(command=jszc, text="教师注册", width=10,height=3)
        Bt2.place(x=250, y=120)
        Bt2 = Button(command=qx, text="回到首页", width=10,height=3)
        Bt2.place(x=350, y=120)
        rt3.mainloop()
    Button(command=XSDL, text="学生登录", width=10).place(x=100, y=190)
    Button(command=JSDL, text="教师登录", width=10).place(x=250, y=190)
    Button(command=zhuce, text="用户注册", width=10).place(x=400, y=190)
#    Button(command=quit, text="退出", width=10).place(x=390, y=190)
    rt.mainloop()
Main()


目录
相关文章
|
1月前
|
缓存 算法 关系型数据库
Mysql(3)—数据库相关概念及工作原理
数据库是一个以某种有组织的方式存储的数据集合。它通常包括一个或多个不同的主题领域或用途的数据表。
50 5
Mysql(3)—数据库相关概念及工作原理
|
18天前
|
存储 Java 关系型数据库
在Java开发中,数据库连接是应用与数据交互的关键环节。本文通过案例分析,深入探讨Java连接池的原理与最佳实践
在Java开发中,数据库连接是应用与数据交互的关键环节。本文通过案例分析,深入探讨Java连接池的原理与最佳实践,包括连接创建、分配、复用和释放等操作,并通过电商应用实例展示了如何选择合适的连接池库(如HikariCP)和配置参数,实现高效、稳定的数据库连接管理。
34 2
|
1月前
|
SQL 关系型数据库 数据库
SQL数据库:核心原理与应用实践
随着信息技术的飞速发展,数据库管理系统已成为各类组织和企业中不可或缺的核心组件。在众多数据库管理系统中,SQL(结构化查询语言)数据库以其强大的数据管理能力和灵活性,广泛应用于各类业务场景。本文将深入探讨SQL数据库的基本原理、核心特性以及实际应用。一、SQL数据库概述SQL数据库是一种关系型数据库
56 5
|
1月前
|
SQL 关系型数据库 MySQL
sql注入原理与实战(三)数据库操作
sql注入原理与实战(三)数据库操作
sql注入原理与实战(三)数据库操作
|
25天前
|
NoSQL 前端开发 MongoDB
前端的全栈之路Meteor篇(三):运行在浏览器端的NoSQL数据库副本-MiniMongo介绍及其前后端数据实时同步示例
MiniMongo 是 Meteor 框架中的客户端数据库组件,模拟了 MongoDB 的核心功能,允许前端开发者使用类似 MongoDB 的 API 进行数据操作。通过 Meteor 的数据同步机制,MiniMongo 与服务器端的 MongoDB 实现实时数据同步,确保数据一致性,支持发布/订阅模型和响应式数据源,适用于实时聊天、项目管理和协作工具等应用场景。
|
1月前
|
SQL 存储 Java
sql注入原理与实战(二)数据库原理
sql注入原理与实战(二)数据库原理
|
3月前
|
消息中间件 Kafka 数据库
深入理解Kafka的数据一致性原理及其与传统数据库的对比
【8月更文挑战第24天】在分布式系统中,确保数据一致性至关重要。传统数据库利用ACID原则保障事务完整性;相比之下,Kafka作为高性能消息队列,采用副本机制与日志结构确保数据一致性。通过同步所有副本上的数据、维护消息顺序以及支持生产者的幂等性操作,Kafka在不牺牲性能的前提下实现了高可用性和数据可靠性。这些特性使Kafka成为处理大规模数据流的理想工具。
82 6
|
3月前
|
数据库连接 数据库
实现加载驱动、得到数据库对象、关闭资源的代码复用,将代码提取到相应的工具包里边。优化程序
该博客文章展示了如何通过创建工具类`Connectiontools`实现数据库连接、语句执行以及资源关闭的代码复用,以优化程序并提高数据库操作的效率和安全性。
|
2月前
|
关系型数据库 数据库 网络虚拟化
Docker环境下重启PostgreSQL数据库服务的全面指南与代码示例
由于时间和空间限制,我将在后续的回答中分别涉及到“Python中采用lasso、SCAD、LARS技术分析棒球运动员薪资的案例集锦”以及“Docker环境下重启PostgreSQL数据库服务的全面指南与代码示例”。如果你有任何一个问题的优先顺序或需要立即回答的,请告知。
69 0
|
4月前
|
存储 SQL 关系型数据库
(六)MySQL索引原理篇:深入数据库底层揭开索引机制的神秘面纱!
《索引原理篇》它现在终于来了!但对于索引原理及底层实现,相信大家多多少少都有了解过,毕竟这也是面试过程中出现次数较为频繁的一个技术点。在本文中就来一窥`MySQL`索引底层的神秘面纱!
340 5