├── README.md ├── favicon.ico ├── welcome.gif ├── school_logo.ico ├── usrs_info.pickle ├── check.py ├── salary.py ├── main.py └── example.py /README.md: -------------------------------------------------------------------------------- 1 | # staff_salary_management 2 | 数据库课程设计(python+mysql) 3 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/160820120/staff_salary_management/HEAD/favicon.ico -------------------------------------------------------------------------------- /welcome.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/160820120/staff_salary_management/HEAD/welcome.gif -------------------------------------------------------------------------------- /school_logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/160820120/staff_salary_management/HEAD/school_logo.ico -------------------------------------------------------------------------------- /usrs_info.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/160820120/staff_salary_management/HEAD/usrs_info.pickle -------------------------------------------------------------------------------- /check.py: -------------------------------------------------------------------------------- 1 | 2 | import time 3 | import datetime 4 | 5 | import tkinter as tk 6 | from tkinter import ttk 7 | from tkinter import messagebox # import this to fix messagebox error 8 | from tkinter import * 9 | import pymysql 10 | import pickle 11 | 12 | import xlsxwriter 13 | import matplotlib.pyplot as plt 14 | from matplotlib.pylab import mpl 15 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk 16 | from matplotlib.figure import Figure 17 | import main 18 | 19 | #签到情况查询、 20 | class check(tk.Frame): 21 | def __init__(self, parent, root): 22 | super().__init__(parent) 23 | labeltxt = tk.Label(self, 24 | text = "签到情况查询", 25 | font = ("楷体",40), 26 | ) 27 | labeltxt.pack() 28 | labeltxt.place(x = 200,y = 10) 29 | 30 | labelt1 = tk.Label(self, 31 | text = "请输入所要查询的人员:", 32 | font = ("楷体",20) 33 | ) 34 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 35 | labelt1.place(x = 100,y = 100) 36 | 37 | f = Figure(figsize=(5, 3.7), dpi=100) 38 | f_plot = f.add_subplot(111) 39 | canvas = FigureCanvasTkAgg(f, self) 40 | canvas.get_tk_widget().place(x=450, y=220) 41 | 42 | 43 | var1 = StringVar() 44 | var1.set(main.id1) 45 | e1 = Entry(self,textvariable = var1,) 46 | e1.pack() 47 | e1.place(x = 170,y = 140) 48 | 49 | 50 | def clock_display(): 51 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 52 | cursor = db.cursor() 53 | sql = "select * from history where history.id=%s" % (e1.get()) 54 | try: 55 | cursor.execute(sql) 56 | db.commit() 57 | except Exception as e: 58 | print('error:' + str(e)) 59 | db.rollback() 60 | cursor.close() 61 | db.close() 62 | 63 | # 数据处理 64 | result = cursor.fetchone() 65 | name = result[1] 66 | clock_record = result[-1] 67 | clock_list = clock_record.split(";") 68 | y = clock_list[:-1] 69 | print(type(y)) 70 | lenth = len(clock_list) 71 | print(lenth) 72 | x = range(1, lenth) 73 | a, b, c, d = 0, 0, 0, 0 74 | for i in y: 75 | if i == "未迟到 未早退": 76 | a += 1 77 | elif i == "未迟到 早退": 78 | b += 1 79 | elif i == "迟到 未早退": 80 | c += 1 81 | elif i == "迟到 早退": 82 | d += 1 83 | x1 = ["未迟到 未早退", "未迟到 早退", "迟到 未早退", "迟到 早退"] 84 | y1 = [a, b, c, d] 85 | f_plot.clear() 86 | f_plot.bar(x1, y1) 87 | f_plot.set_title(name + "本月的考勤情况") 88 | f_plot.set_xlabel("考勤情况") 89 | f_plot.set_ylabel("天数") 90 | canvas.draw() 91 | print("ok") 92 | 93 | b1 = tk.Button(self, text="查询", width=8, font=("楷体", 20), command=clock_display) 94 | b1.pack(padx=2, pady=20) 95 | b1.place(x=500, y=110) 96 | 97 | 98 | labelt2 = tk.Label(self, 99 | text = "查询结果:", 100 | font = ("楷体",20), 101 | fg = "red" 102 | ) 103 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 104 | labelt2.place(x = 10,y = 200) 105 | 106 | scrolly = Scrollbar(self) 107 | scrolly.pack(side=RIGHT, fill=Y) 108 | 109 | 110 | l=tk.Listbox(self,width = 70,height = 17,exportselection = False,yscrollcommand=scrolly.set) 111 | l.pack() 112 | l.place(x=10,y = 260) -------------------------------------------------------------------------------- /salary.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import ttk 3 | from tkinter import messagebox 4 | from tkinter import * 5 | import pymysql 6 | import xlsxwriter 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | from matplotlib.pylab import mpl 10 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 11 | from matplotlib.figure import Figure 12 | from matplotlib.ticker import MultipleLocator, FuncFormatter 13 | 14 | 15 | mpl.rcParams['font.sans-serif'] = ['SimHei'] # 中文显示 16 | mpl.rcParams['axes.unicode_minus'] = False # 负号显示 17 | 18 | 19 | #工资查询 20 | class salary(tk.Frame): 21 | # Label设计 22 | def __init__(self, parent, root): 23 | super().__init__(parent) 24 | labeltxt = tk.Label(self,text = "工资查询",font = ("楷体",40),) 25 | labeltxt.pack() 26 | labeltxt.place(x = 200,y = 10) 27 | 28 | labelt1 = tk.Label(self,text = "请输入所要查询的工号:",font = ("楷体",20)) 29 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 30 | labelt1.place(x = 100,y = 100) 31 | 32 | f = Figure(figsize=(5, 3.7), dpi=100) 33 | f_plot = f.add_subplot(111) 34 | canvas = FigureCanvasTkAgg(f, self) 35 | canvas.get_tk_widget().place(x=450, y=220) 36 | 37 | var1 = StringVar() 38 | e1 = Entry(self,textvariable = var1,) 39 | e1.pack() 40 | e1.place(x = 170,y = 140) 41 | 42 | def show1(): 43 | basedata = { 44 | 'host': '103.248.223.58', 45 | 'port': 3306, 46 | 'user': 'root', 47 | 'passwd': 'h1613401', 48 | 'db': 'test', 49 | 'charset': 'utf8' 50 | } 51 | 52 | # 打开数据库连接 53 | conn = pymysql.connect(**basedata) 54 | 55 | try: 56 | # 获取一个光标 57 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 58 | cursor = conn.cursor() # 返回字典数据类型 59 | # 定义将要执行的sql语句 60 | # sql = 'select name,sex from member where id=%s;'%e1.get() 61 | if (e1.get() == ""): 62 | l.insert(END, "输入为空,请正确输入!") 63 | 64 | 65 | sql = 'select * from salary where id=%s;' % e1.get() 66 | 67 | # 拼接并执行sql语句 68 | cursor.execute(sql) 69 | if (cursor.execute(sql)== 0): 70 | l.insert(END, "查询失败,请重新输入!") 71 | else: 72 | # 取到查询结果 73 | ret1 = cursor.fetchone() # 取一条 74 | # ret1 = cursor.fetchall() 75 | ret2 = cursor.description # 获取表字段名 76 | 77 | cursor.close() 78 | conn.close() 79 | print(len(ret1)) 80 | # print(e1.get()) 81 | l.insert(END, "查询成功") 82 | l.insert(END, ret1) 83 | 84 | f_plot.clear() 85 | headings = [item[0] for item in ret2] 86 | # print(headings) 87 | labels = headings[4:8] 88 | fracs = ret1[4:8] 89 | explode = [0, 0.1, 0, 0] # 0.1 凸出这部分, 90 | f_plot.pie(x=fracs, labels=labels, explode=explode, autopct='%3.1f %%', 91 | shadow=True, labeldistance=1.1, startangle=90, pctdistance=0.6 92 | ) 93 | f_plot.set_title(ret1[1]+'月薪组成一览图', fontsize='14') 94 | canvas.draw() 95 | 96 | # 显示表头 97 | tree.heading("ID", text=headings[0]) 98 | tree.heading("Name", text=headings[1]) 99 | tree.heading("base", text=headings[4]) 100 | tree.heading("assess", text=headings[5]) 101 | tree.heading("check", text=headings[6]) 102 | tree.heading("insurance", text=headings[7]) 103 | tree.heading("total", text=headings[8]) 104 | tree.insert("", 0, values=(ret1[0], ret1[1], ret1[4], ret1[5], ret1[6], ret1[7], ret1[8])) 105 | tree.pack() 106 | 107 | 108 | except: 109 | print("查询失败") 110 | # 发生错误时回滚 111 | conn.rollback() 112 | 113 | def download(): 114 | # basedata = {'host': '103.248.223.58', 'port': 3306, 'user': 'root', 'passwd': '123', 'db': 'test', 115 | # 'charset': 'utf8'} 116 | basedata = { 117 | 'host': '103.248.223.58', 118 | 'port': 3306, 119 | 'user': 'root', 120 | 'passwd': 'h1613401', 121 | 'db': 'test', 122 | 'charset': 'utf8' 123 | } 124 | 125 | # 打开数据库连接 126 | conn = pymysql.connect(**basedata) 127 | 128 | try: 129 | # 获取一个光标 130 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 131 | cursor = conn.cursor() # 返回字典数据类型 132 | if (e1.get() == ""): 133 | l.insert(END, "输入为空,请正确输入!") 134 | # 定义将要执行的sql语句 135 | # sql = 'select name,sex from member where id=%s;'%e1.get() 136 | sql = 'select * from salary where id=%s;' % e1.get() 137 | # 拼接并执行sql语句 138 | cursor.execute(sql) 139 | 140 | if (cursor.execute(sql)== 0): 141 | l.insert(END, "查询失败,请重新输入!") 142 | else: 143 | 144 | # 取到查询结果 145 | ret1 = cursor.fetchone() # 取一条 146 | # ret1 = cursor.fetchall() 147 | 148 | cursor.close() 149 | conn.close() 150 | 151 | print("已下载") 152 | l.insert(END, "已下载") 153 | 154 | # 新建一个excel文件,起名为expense01.xlsx 155 | workbook = xlsxwriter.Workbook(ret1[1]+"当月薪水情况.xlsx") 156 | # 添加一个Sheet页,不添写名字,默认为Sheet1 157 | worksheet = workbook.add_worksheet() 158 | 159 | # 准备数据 160 | headings = ["ID", "Name", "base", "assess", "check", "insurance", "total"] 161 | data = [[ret1[0],ret1[1],ret1[4],ret1[5], ret1[6],ret1[7], ret1[8]]] 162 | # print(data) 163 | 164 | head_style = workbook.add_format({"bold": True, "bg_color": "yellow", "align": "center", "font": 13}) 165 | # 写数据 166 | worksheet.write_row("A1", headings, head_style) 167 | for i in range(0, len(data)): 168 | worksheet.write_row("A2", data[i]) 169 | 170 | # 添加柱状图 171 | chart1 = workbook.add_chart({"type": "column"}) 172 | chart1.add_series({ 173 | "name": "", 174 | "categories": "=Sheet1!$C$1:$G$1", 175 | "values": "=Sheet1!$C$2:$F$2" 176 | }) 177 | 178 | # 添加柱状图标题 179 | chart1.set_title({"name": "每月薪水柱状图"}) 180 | # Y轴名称 181 | chart1.set_y_axis({"name": "金额/元"}) 182 | # X轴名称 183 | chart1.set_x_axis({"name": "薪水组成"}) 184 | # 图表样式 185 | chart1.set_style(11) 186 | 187 | # 添加饼图 188 | chart2 = workbook.add_chart({"type": "pie"}) 189 | chart2.add_series({ 190 | "name": "饼形图", 191 | "categories": "=Sheet1!$C$1:$G$1", 192 | "values": "=Sheet1!$C$2:$F$2", 193 | 194 | # 定义各饼块的颜色 195 | "points": [ 196 | {"fill": {"color": "red"}}, 197 | {"fill": {"color": "blue"}}, 198 | {"fill": {"color": "yellow"}}, 199 | {"fill": {"color": "green"}}, 200 | # {"fill": {"color": "orange"}}, 201 | # {"fill": {"color": "purple"}} 202 | ], 203 | 'data_labels': {'value': True} 204 | }) 205 | chart2.set_title({"name": "每月薪水组成"}) 206 | chart2.set_style(3) 207 | 208 | # 插入图表 209 | worksheet.insert_chart("B7", chart1) 210 | worksheet.insert_chart("J2", chart2) 211 | 212 | # 关闭EXCEL文件 213 | workbook.close() 214 | 215 | except: 216 | print("下载失败") 217 | # 发生错误时回滚 218 | conn.rollback() 219 | 220 | 221 | def history(): 222 | basedata = { 223 | 'host': '103.248.223.58', 224 | 'port': 3306, 225 | 'user': 'root', 226 | 'passwd': 'h1613401', 227 | 'db': 'test', 228 | 'charset': 'utf8' 229 | } 230 | 231 | # 打开数据库连接 232 | conn = pymysql.connect(**basedata) 233 | 234 | try: 235 | # 获取一个光标 236 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 237 | cursor = conn.cursor() # 返回字典数据类型 238 | # 定义将要执行的sql语句 239 | # sql = 'select name,sex from member where id=%s;'%e1.get() 240 | if (e1.get() == ""): 241 | l.insert(END, "输入为空,请正确输入!") 242 | 243 | sql = 'select * from history where id=%s;' % e1.get() 244 | # 拼接并执行sql语句 245 | cursor.execute(sql) 246 | if (cursor.execute(sql)== 0): 247 | l.insert(END, "查询失败,请重新输入!") 248 | else: 249 | # 取到查询结果 250 | ret3 = cursor.fetchone() # 取一条 251 | # ret1 = cursor.fetchall() 252 | ret4 = cursor.description # 获取表字段名 253 | 254 | cursor.close() 255 | conn.close() 256 | 257 | print("已查询") 258 | l.insert(END, "已查询") 259 | 260 | l.insert(END, ret3) 261 | 262 | # 新建一个excel文件 263 | workbook = xlsxwriter.Workbook(ret3[1]+"每月薪水情况.xlsx") 264 | # 添加一个Sheet页,不添写名字,默认为Sheet1 265 | worksheet = workbook.add_worksheet() 266 | 267 | # 准备数据 268 | headings = [item[0] for item in ret4] 269 | data = [[ret3[0],ret3[1],ret3[2],ret3[3],ret3[4],ret3[5], ret3[6],ret3[7], ret3[8],ret3[9], ret3[10],ret3[11], ret3[12]]] 270 | 271 | print(headings) 272 | print(data) 273 | head_style = workbook.add_format({"bold": True, "bg_color": "yellow", "align": "center", "font": 13}) 274 | # 写数据 275 | worksheet.write_row("A1", headings, head_style) 276 | for i in range(0, len(data)): 277 | worksheet.write_row("A2", data[i]) 278 | 279 | # 添加柱状图 280 | chart1 = workbook.add_chart({"type": "column"}) 281 | chart1.add_series({ 282 | "name": "", 283 | "categories": "=Sheet1!$C$1:$N$1", 284 | "values": "=Sheet1!$C$2:$N$2" 285 | }) 286 | 287 | # 添加柱状图标题 288 | chart1.set_title({"name": "各月薪水柱状图"}) 289 | # Y轴名称 290 | chart1.set_y_axis({"name": "金额/元"}) 291 | # X轴名称 292 | chart1.set_x_axis({"name": "薪水组成"}) 293 | # 图表样式 294 | chart1.set_style(11) 295 | 296 | # 添加柱状图 297 | chart2 = workbook.add_chart({"type": "line"}) 298 | chart2.add_series({ 299 | "name": "", 300 | "categories": "=Sheet1!$C$1:$N$1", 301 | "values": "=Sheet1!$C$2:$N$2", 302 | 'line': {'color': 'red'} 303 | }) 304 | 305 | # 添加柱状图标题 306 | chart2.set_title({"name": "各月薪水折线图"}) 307 | # Y轴名称 308 | chart2.set_y_axis({"name": "金额/元"}) 309 | # X轴名称 310 | chart2.set_x_axis({"name": "薪水组成"}) 311 | # 图表样式 312 | chart2.set_style(11) 313 | 314 | # 插入图表 315 | worksheet.insert_chart("B7", chart1) 316 | worksheet.insert_chart("J2", chart2) 317 | 318 | # 关闭EXCEL文件 319 | workbook.close() 320 | 321 | f_plot.clear() 322 | # x = list(map(int, headings[2:])) 323 | x = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12)# 关于数据的部分可以提取出 324 | y = ret3[2:14] 325 | # print(x,y) 326 | f_plot.plot(x, y,color="red", linewidth=1.5) 327 | 328 | 329 | f_plot.set_title(ret3[1]+'各月薪水一览图', fontsize='14') 330 | f_plot.grid(True, linestyle='-.') 331 | f_plot.set_xlabel('月份/月', color='black') 332 | f_plot.set_ylabel('每月薪水/元', color='black') 333 | f_plot.axis([1,12,0,10000]) 334 | xminorLocator = MultipleLocator(1) 335 | f_plot.xaxis.set_minor_locator(xminorLocator) 336 | canvas.draw() 337 | 338 | except: 339 | print("下载失败") 340 | # 发生错误时回滚 341 | conn.rollback() 342 | 343 | def clear(): 344 | l.delete(0,END) 345 | x = tree.get_children() 346 | for item in x: 347 | tree.delete(item) 348 | 349 | #label设计 350 | b1=tk.Button(self,text='查询',width = 8,height = 2,activeforeground = "red",command=show1) 351 | b1.pack(padx = 5, pady = 10) 352 | b1.place(x=350,y=140) 353 | 354 | b2=tk.Button(self,text='下载',width = 8,height = 2,activeforeground = "red",command=download) 355 | b2.pack(padx = 5, pady = 20) 356 | b2.place(x=450,y=140) 357 | 358 | b3=tk.Button(self,text='查看历史',width = 8,height = 2,activeforeground = "red",command=history) 359 | b3.pack(padx = 5, pady = 20) 360 | b3.place(x=550,y=140) 361 | 362 | b3=tk.Button(self,text='清除',width = 6,height = 1,activeforeground = "red",command=clear) 363 | b3.pack(padx = 5, pady = 20) 364 | b3.place(x=380,y=220) 365 | 366 | labelt2 = tk.Label(self,text = "查询工资的记录:",font = ("楷体",15),fg = "red") 367 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 368 | labelt2.place(x = 10,y = 220) 369 | 370 | scrolly = Scrollbar(self) 371 | scrolly.pack(side=RIGHT, fill=Y) 372 | 373 | l=tk.Listbox(self,width = 70,height = 5,exportselection = False,yscrollcommand=scrolly.set) 374 | scrollbar1 = Scrollbar(self) 375 | scrollbar1.pack(side=RIGHT, fill=Y) 376 | l.pack() 377 | l.place(x=10,y = 250) 378 | 379 | labelt3 = tk.Label(self,text = "查询结果展示:",font = ("楷体",15),fg = "red") 380 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 381 | labelt3.place(x = 10,y = 350) 382 | 383 | l1=tk.Listbox(self,width = 50,height = 10,exportselection = False,yscrollcommand=scrolly.set) 384 | l1.pack() 385 | l1.place(x=10,y = 380) 386 | 387 | tree = ttk.Treeview(l1, height=18, show="headings", columns=("ID","Name","base","assess", "check","insurance","total")) 388 | tree.column("ID", width=60) # 表示列,不显示 389 | tree.column("Name", width=60) 390 | tree.column("base", width=60) 391 | tree.column("assess", width=60) 392 | tree.column("check", width=60) 393 | tree.column("insurance", width=60) 394 | tree.column("total", width=60) 395 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | import time 5 | import datetime 6 | 7 | import tkinter as tk 8 | from tkinter import ttk 9 | from tkinter import messagebox # import this to fix messagebox error 10 | from tkinter import * 11 | import pymysql 12 | import pickle 13 | 14 | import xlsxwriter 15 | import matplotlib.pyplot as plt 16 | from matplotlib.pylab import mpl 17 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk 18 | from matplotlib.figure import Figure 19 | import salary as sal 20 | import check as che 21 | 22 | id1=0 23 | 24 | mpl.rcParams['font.sans-serif'] = ['SimHei'] # 中文显示 25 | mpl.rcParams['axes.unicode_minus'] = False # 负号显示 26 | # print(StartPage0.var_usr_name.get()) 27 | #登陆后界面 28 | class Application(tk.Tk): 29 | 30 | def __init__(self): 31 | super().__init__() #super() 函数是用于调用父类(超类)的一个方法。 32 | 33 | self.wm_title("人才管理系统") 34 | self.geometry("930x600") 35 | self.resizable(width = 0,height = False) 36 | 37 | print(id1) 38 | 39 | container = tk.Frame(self) 40 | container.pack(side="top", fill="both", expand = True) #fill 填充整个分配给它的空间 41 | container.grid_rowconfigure(0, weight=1)#grid 网格 42 | container.grid_columnconfigure(0, weight=1) 43 | 44 | # 创建一个菜单项,类似于导航栏 45 | menubar=Menu(self) 46 | # 创建菜单项 47 | # menubar.add_cascade(label="登录",command=lambda: self.show_frame(StartPage)) 48 | menubar.add_cascade(label="考勤",command=lambda: self.show_frame(PageNine)) 49 | menubar.add_cascade(label="用户信息添加",command=lambda: self.show_frame(PageTwo)) 50 | # menubar.add_cascade(label="个人信息查询",command=lambda: self.show_frame(PageThree)) 51 | menubar.add_cascade(label="部门人员查询",command=lambda: self.show_frame(PageFore)) 52 | # menubar.add_cascade(label="专业配置",command=lambda: self.show_frame(PageFive)) 53 | menubar.add_cascade(label="工资查询",command=lambda: self.show_frame(sal.salary)) 54 | menubar.add_cascade(label="签到情况查询",command=lambda: self.show_frame(che.check)) 55 | menubar.add_cascade(label="人员调动", command=lambda: self.show_frame(PageEight)) 56 | self['menu']=menubar 57 | 58 | self.frames = {} 59 | 60 | for F in (PageNine,PageTwo,PageFore,sal.salary,che.check,PageEight): 61 | frame = F(container, self) 62 | self.frames[F] = frame 63 | frame.grid(row=0, column=0, sticky="nsew") # 四个页面的位置都是 grid(row=0, column=0), 位置重叠,只有最上面的可见!! 64 | 65 | 66 | self.show_frame(PageNine) 67 | 68 | 69 | def show_frame(self, cont): 70 | frame = self.frames[cont] 71 | frame.tkraise() # 切换,提升当前 tk.Frame z轴顺序 72 | 73 | #欢迎页 74 | class StartPage0(object): 75 | idd=10 76 | def __init__(self): 77 | # super().__init__() # super() 函数是用于调用父类(超类)的一个方法。 78 | 79 | window = tk.Tk() 80 | window.iconbitmap("./school_logo.ico") 81 | window.title('Employee-managerment') 82 | window.geometry('450x300') 83 | 84 | # welcome image 85 | canvas = tk.Canvas(window, height=200, width=500) # 画布 86 | image_file = tk.PhotoImage(file='welcome.gif') # 加载图片文件 87 | image = canvas.create_image(0, 0, anchor='nw', image=image_file) # 将图片置于画布上 88 | canvas.pack(side='top') # 放置画布(为上端) 89 | 90 | # user information 91 | tk.Label(window, text='User name: ').place(x=50, y=150) 92 | tk.Label(window, text='Password: ').place(x=50, y=190) 93 | 94 | var_usr_name = tk.StringVar() # 定义变量 95 | var_usr_name.set('') 96 | entry_usr_name = tk.Entry(window, textvariable=var_usr_name) 97 | entry_usr_name.place(x=160, y=150) 98 | var_usr_pwd = tk.StringVar() 99 | entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*') 100 | entry_usr_pwd.place(x=160, y=190) 101 | 102 | 103 | 104 | def enter_mainwindows(): 105 | # 实例化Application 106 | # self.idd 107 | app = Application() 108 | app.iconbitmap("./school_logo.ico") 109 | # 主循环: 110 | app.mainloop() 111 | 112 | def usr_sign_up(): 113 | 114 | def sign_to(): 115 | np = new_pwd.get() 116 | npf = new_pwd_confirm.get() 117 | nn = new_name.get() 118 | with open('usrs_info.pickle', 'rb') as usr_file: 119 | exist_usr_info = pickle.load(usr_file) 120 | if np != npf: 121 | tk.messagebox.showerror('Error', 'Password and confirm password must be the same!') 122 | elif nn in exist_usr_info: 123 | tk.messagebox.showerror('Error', 'The user has already signed up!') 124 | else: 125 | exist_usr_info[nn] = np 126 | with open('usrs_info.pickle', 'wb') as usr_file: 127 | pickle.dump(exist_usr_info, usr_file) 128 | tk.messagebox.showinfo('Welcome', 'You have successfully signed up!') 129 | window_sign_up.destroy() 130 | 131 | window_sign_up = tk.Toplevel(window) # 在主体窗口的window上创建一个Sign up window窗口。 132 | window_sign_up.geometry('350x200') 133 | window_sign_up.iconbitmap(".//school_logo.ico") 134 | window_sign_up.title('Sign up window') 135 | 136 | new_name = tk.StringVar() 137 | new_name.set('') 138 | tk.Label(window_sign_up, text='User name: ').place(x=10, y=10) 139 | entry_new_name = tk.Entry(window_sign_up, textvariable=new_name) 140 | entry_new_name.place(x=150, y=10) 141 | 142 | new_pwd = tk.StringVar() 143 | tk.Label(window_sign_up, text='Password: ').place(x=10, y=50) 144 | entry_usr_pwd = tk.Entry(window_sign_up, textvariable=new_pwd, show='*') 145 | entry_usr_pwd.place(x=150, y=50) 146 | 147 | new_pwd_confirm = tk.StringVar() 148 | tk.Label(window_sign_up, text='Confirm password: ').place(x=10, y=90) 149 | entry_usr_pwd_confirm = tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*') 150 | entry_usr_pwd_confirm.place(x=150, y=90) 151 | 152 | btn_comfirm_sign_up = tk.Button(window_sign_up, text='Sign up', command=sign_to) 153 | btn_comfirm_sign_up.place(x=150, y=130) 154 | 155 | def usr_login(): 156 | usr_name = var_usr_name.get() 157 | global id1 158 | id1 = usr_name 159 | usr_pwd = var_usr_pwd.get() 160 | 161 | ##这里设置异常捕获,当我们第一次访问用户信息文件时是不存在的,所以这里设置异常捕获。 162 | ##中间的两行就是我们的匹配,即程序将输入的信息和文件中的信息匹配。 163 | try: 164 | with open('usrs_info.pickle', 'rb') as usr_file: 165 | usrs_info = pickle.load(usr_file) 166 | except FileNotFoundError: 167 | ##这里就是我们在没有读取到`usr_file`的时候,程序会创建一个`usr_file`这个文件,并将管理员 168 | ##的用户和密码写入,即用户名为`admin`密码为`admin`。 169 | with open('usrs_info.pickle', 'wb') as usr_file: 170 | usrs_info = {'admin': 'admin'} 171 | pickle.dump(usrs_info, usr_file) 172 | 173 | if usr_name in usrs_info: 174 | if usr_pwd == usrs_info[usr_name]: 175 | # a=tk.messagebox.showinfo(title='Welcome', message='Welcome to Employee-managerment ' + usr_name) 176 | 177 | print(datetime.datetime.now()) 178 | 179 | time.sleep(1) 180 | 181 | 182 | # a.destroy() 183 | window.destroy() 184 | enter_mainwindows() 185 | else: 186 | tk.messagebox.showerror(message='Error, your password is wrong, try again.') 187 | else: 188 | is_sign_up = tk.messagebox.askyesno('Welcome', 189 | 'You have not signed up yet. Sign up today?') 190 | if is_sign_up: 191 | usr_sign_up() 192 | 193 | # login and sign up button 194 | btn_login = tk.Button(window, text='Login', command=usr_login) 195 | btn_login.place(x=170, y=230) 196 | btn_sign_up = tk.Button(window, text='Sign up', command=usr_sign_up) 197 | btn_sign_up.place(x=270, y=230) 198 | 199 | 200 | 201 | window.mainloop() 202 | 203 | #登录界面、 204 | class StartPage(tk.Frame): 205 | def __init__(self, parent, root): 206 | super().__init__(parent) 207 | 208 | 209 | 210 | labeltxt = tk.Label(self, 211 | text = "用户登录", 212 | font = ("楷体",40), 213 | ) 214 | labeltxt.pack() 215 | labeltxt.place(x = 240,y = 50) 216 | 217 | labelt1 = tk.Label(self, 218 | text = "账户:", 219 | font = ("楷体",25) 220 | ) 221 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 222 | labelt1.place(x = 210,y = 200) 223 | 224 | var1 = StringVar() 225 | e1 = Entry(self, 226 | textvariable = var1, 227 | ) 228 | e1.pack() 229 | e1.place(x = 300,y = 215) 230 | 231 | # 登录密码 232 | labelt2 = tk.Label(self, 233 | text = "密码:", 234 | font = ("楷体",25) 235 | ) 236 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 237 | labelt2.place(x = 210,y = 320) 238 | 239 | var2 = StringVar() 240 | e2 = Entry(self, 241 | textvariable = var2, 242 | show = "*" 243 | ) 244 | e2.pack() 245 | e2.place(x = 300,y = 335) 246 | 247 | # 按钮设计 248 | btnkaishi = tk.Button(self, 249 | text="直接登录", 250 | width = 20, 251 | height = 4, 252 | activeforeground = "red", 253 | # command=lambda: 254 | 255 | ) 256 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 257 | btnkaishi.place(x = 50,y = 470) 258 | 259 | btnkaishi = tk.Button(self, 260 | text="立即注册", 261 | width = 20, 262 | height = 4, 263 | activeforeground = "red", 264 | command=lambda: root.show_frame(PageOne) 265 | ) 266 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 267 | btnkaishi.place(x = 500,y = 470) 268 | 269 | #注册账号信息、 270 | class PageOne(tk.Frame): 271 | 272 | 273 | 274 | # root = tk.Tk() 275 | # root.iconbitmap(".//school_logo.ico") 276 | # root.title('Employee-managerment') 277 | # root.geometry('450x300') 278 | # view = PageOne(root) 279 | # view.pack(side="top", fill="both", expand=True) 280 | # root.mainloop() 281 | 282 | def __init__(self, *args, **kwargs): 283 | 284 | tk.Frame.__init__(self, *args, **kwargs) 285 | 286 | 287 | b = tk.Button(self, text="Open new window", command=self.new_window1) 288 | b.pack(side="bottom") 289 | 290 | # welcome image 291 | canvas = tk.Canvas(self, height=200, width=500) # 画布 292 | image_file = tk.PhotoImage(file='welcome.gif') # 加载图片文件 293 | image = canvas.create_image(0, 0, anchor='nw', image=image_file) # 将图片置于画布上 294 | canvas.pack(side='top') # 放置画布(为上端) 295 | 296 | # user information 297 | tk.Label(self, text='User name: ').place(x=50, y=150) 298 | tk.Label(self, text='Password: ').place(x=50, y=190) 299 | 300 | var_usr_name = tk.StringVar() # 定义变量 301 | var_usr_name.set('example@python.com') 302 | entry_usr_name = tk.Entry(self, textvariable=var_usr_name) 303 | entry_usr_name.place(x=160, y=150) 304 | var_usr_pwd = tk.StringVar() 305 | entry_usr_pwd = tk.Entry(self, textvariable=var_usr_pwd, show='*') 306 | entry_usr_pwd.place(x=160, y=190) 307 | 308 | def enter_mainwindows(): 309 | # 实例化Application 310 | app = Application() 311 | app.iconbitmap(".//school_logo.ico") 312 | # 主循环: 313 | app.mainloop() 314 | def usr_login(): 315 | usr_name = var_usr_name.get() 316 | usr_pwd = var_usr_pwd.get() 317 | 318 | ##这里设置异常捕获,当我们第一次访问用户信息文件时是不存在的,所以这里设置异常捕获。 319 | ##中间的两行就是我们的匹配,即程序将输入的信息和文件中的信息匹配。 320 | try: 321 | with open('usrs_info.pickle', 'rb') as usr_file: 322 | usrs_info = pickle.load(usr_file) 323 | except FileNotFoundError: 324 | ##这里就是我们在没有读取到`usr_file`的时候,程序会创建一个`usr_file`这个文件,并将管理员 325 | ##的用户和密码写入,即用户名为`admin`密码为`admin`。 326 | with open('usrs_info.pickle', 'wb') as usr_file: 327 | usrs_info = {'admin': 'admin'} 328 | pickle.dump(usrs_info, usr_file) 329 | 330 | if usr_name in usrs_info: 331 | if usr_pwd == usrs_info[usr_name]: 332 | tk.messagebox.showinfo(title='Welcome', message='How are you? ' + usr_name) 333 | root.destroy() 334 | enter_mainwindows() 335 | else: 336 | tk.messagebox.showerror(message='Error, your password is wrong, try again.') 337 | else: 338 | is_sign_up = tk.messagebox.askyesno('Welcome', 339 | 'You have not signed up yet. Sign up today?') 340 | if is_sign_up: 341 | self.new_window1() 342 | 343 | 344 | # login and sign up button 345 | btn_login = tk.Button(self, text='Login', command=usr_login) 346 | btn_login.place(x=170, y=230) 347 | btn_sign_up = tk.Button(self, text='Sign up', command=self.new_window1) 348 | btn_sign_up.place(x=270, y=230) 349 | 350 | def new_window1(self): 351 | 352 | window = tk.Toplevel(self) 353 | window.title("人才管理系统") 354 | window.geometry("700x600") 355 | label = tk.Label(window, text=id) 356 | label.pack(side="top", fill="both", padx=10, pady=10) 357 | 358 | labeltxt = tk.Label(window, 359 | text="账号注册", 360 | font=("楷体", 40), 361 | ) 362 | labeltxt.pack() 363 | labeltxt.place(x=240, y=50) 364 | 365 | # 登录账号 366 | labelt1 = tk.Label(window, 367 | text="账户:", 368 | font=("楷体", 25) 369 | ) 370 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 371 | labelt1.place(x=200, y=140) 372 | 373 | var1 = StringVar() 374 | e1 = Entry(window, 375 | textvariable=var1, 376 | ) 377 | e1.pack() 378 | e1.place(x=305, y=150) 379 | 380 | # 登录密码 381 | labelt2 = tk.Label(window, 382 | text="密码:", 383 | font=("楷体", 25) 384 | ) 385 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 386 | labelt2.place(x=200, y=240) 387 | 388 | var2 = StringVar() 389 | e2 = Entry(window, 390 | textvariable=var2, 391 | show="*" 392 | ) 393 | e2.pack() 394 | e2.place(x=305, y=250) 395 | 396 | # 确认密码 397 | labelt3 = tk.Label(window, 398 | text="确认密码:", 399 | font=("楷体", 25) 400 | ) 401 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 402 | labelt3.place(x=150, y=350) 403 | 404 | var3 = StringVar() 405 | e3 = Entry(window, 406 | textvariable=var3, 407 | show="*" 408 | ) 409 | e3.pack() 410 | e3.place(x=305, y=365) 411 | 412 | labelp = tk.Label(window, 413 | text=" ", 414 | font=("楷体", 20) 415 | ) 416 | labelp.pack(padx=5, pady=10, side=tk.LEFT) 417 | labelp.place(x=200, y=400) 418 | 419 | def show1(): 420 | basedata = { 421 | 'host': '103.248.223.58', 422 | 'port': 3306, 423 | 'user': 'root', 424 | 'passwd': '123', 425 | 'db': 'test', 426 | 'charset': 'utf8' 427 | } 428 | # 打开数据库连接 429 | conn = pymysql.connect(**basedata) 430 | 431 | try: 432 | User = str(e1.get()) 433 | Passwd = str(e2.get()) 434 | 435 | # 使用 cursor() 方法创建一个游标对象 cursor 436 | cursor = conn.cursor() 437 | print() 438 | 439 | sql = "INSERT INTO test1(id,name ) \ 440 | VALUES ('%s', '%s' )" % \ 441 | (User, Passwd) 442 | 443 | cursor.execute(sql) 444 | 445 | # commit 修改 446 | conn.commit() 447 | 448 | # 关闭游标 449 | cursor.close() 450 | 451 | # 关闭链接 452 | conn.close() 453 | print("添加成功") 454 | 455 | labelp.configure(text="注册成功") 456 | 457 | except: 458 | print("添加记录失败") 459 | labelp.configure(text="注册失败") 460 | # 发生错误时回滚 461 | conn.rollback() 462 | 463 | # 按钮设计 464 | btnkaishi = tk.Button(window, 465 | text="立即注册", 466 | width=20, 467 | height=4, 468 | activeforeground="red", 469 | command=show1 470 | ) 471 | btnkaishi.pack(padx=5, pady=10, side=tk.LEFT) 472 | btnkaishi.place(x=50, y=470) 473 | 474 | btnkaishi = tk.Button(window, 475 | text="返回登录", 476 | width=20, 477 | height=4, 478 | activeforeground="red", 479 | command=lambda: window.show_frame(StartPage) 480 | ) 481 | btnkaishi.pack(padx=5, pady=10, side=tk.LEFT) 482 | btnkaishi.place(x=500, y=470) 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | # window = tk.Toplevel() 491 | # label = tk.Label(window, text=id) 492 | # label.pack(side="top", fill="both", padx=10, pady=10) 493 | 494 | # 用户信息添加页面 495 | class PageTwo(tk.Frame): 496 | def __init__(self, parent, root): 497 | super().__init__(parent) 498 | 499 | labeltxt = tk.Label(self, 500 | text = "用户信息添加", 501 | font = ("楷体",40), 502 | ) 503 | labeltxt.pack() 504 | labeltxt.place(x = 230,y = 10) 505 | 506 | 507 | # 姓名 508 | labelt1 = tk.Label(self, 509 | text = "姓名:", 510 | font = ("楷体",17) 511 | ) 512 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 513 | labelt1.place(x = 100,y = 70) 514 | 515 | var1 = StringVar() 516 | e1 = Entry(self, 517 | textvariable = var1, 518 | ) 519 | e1.pack() 520 | e1.place(x = 170,y = 80) 521 | 522 | # 年龄 523 | labelt2 = tk.Label(self, 524 | text = "ID:", 525 | font = ("楷体",17) 526 | ) 527 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 528 | labelt2.place(x = 350,y = 70) 529 | var2 = StringVar() 530 | var2.set(id1) 531 | e2 = Entry(self, 532 | textvariable = var2,state=DISABLED 533 | ) 534 | e2.pack() 535 | e2.place(x = 420,y = 80) 536 | 537 | # 性别 538 | labelt3 = tk.Label(self, 539 | text = "性别:", 540 | font = ("楷体",17) 541 | ) 542 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 543 | labelt3.place(x = 100,y = 150) 544 | var3 = StringVar() 545 | e3 = Entry(self, 546 | textvariable = var3, 547 | ) 548 | e3.pack() 549 | e3.place(x = 170,y = 160) 550 | 551 | # 生日 552 | labelt4 = tk.Label(self, 553 | text = "生日:", 554 | font = ("楷体",17) 555 | ) 556 | labelt4.pack(padx=5, pady=10, side=tk.LEFT) 557 | labelt4.place(x = 350,y = 150) 558 | var4 = StringVar() 559 | e4 = Entry(self, 560 | textvariable = var4, 561 | ) 562 | e4.pack() 563 | e4.place(x = 420,y = 160) 564 | 565 | # 学历 566 | labelt5 = tk.Label(self, 567 | text = "等级:", 568 | font = ("楷体",17) 569 | ) 570 | labelt5.pack(padx=5, pady=10, side=tk.LEFT) 571 | labelt5.place(x = 100,y = 230) 572 | var5 = StringVar() 573 | e5 = Entry(self, 574 | textvariable = var5, 575 | ) 576 | e5.pack() 577 | e5.place(x = 170,y = 240) 578 | 579 | # 专业 580 | labelt6 = tk.Label(self, 581 | text = "专业:", 582 | font = ("楷体",17) 583 | ) 584 | labelt6.pack(padx=5, pady=10, side=tk.LEFT) 585 | labelt6.place(x = 350,y = 230) 586 | var6 = StringVar() 587 | e6 = Entry(self, 588 | textvariable = var6, 589 | ) 590 | e6.pack() 591 | e6.place(x = 420,y = 240) 592 | 593 | # 学校 594 | labelt7 = tk.Label(self, 595 | text = "毕业学校:", 596 | font = ("楷体",17) 597 | ) 598 | labelt7.pack(padx=5, pady=10, side=tk.LEFT) 599 | labelt7.place(x = 50,y = 285) 600 | var7 = StringVar() 601 | e7= Entry(self, 602 | textvariable = var7, 603 | ) 604 | e7.pack() 605 | e7.place(x = 170,y = 295) 606 | 607 | # 手机号码 608 | labelt8 = tk.Label(self, 609 | text = "手机号码:", 610 | font = ("楷体",17) 611 | ) 612 | labelt8.pack(padx=5, pady=10, side=tk.LEFT) 613 | labelt8.place(x =50,y = 335) 614 | var8 = StringVar() 615 | e8= Entry(self, 616 | textvariable = var8, 617 | ) 618 | e8.pack() 619 | e8.place(x = 170,y = 345) 620 | 621 | # # QQ邮箱 622 | # labelt9 = tk.Label(self, 623 | # text = "QQ邮箱:", 624 | # font = ("楷体",17) 625 | # ) 626 | # labelt9.pack(padx=5, pady=10, side=tk.LEFT) 627 | # labelt9.place(x = 50,y = 385) 628 | # var9 = StringVar() 629 | # e9= Entry(self, 630 | # textvariable = var9, 631 | # ) 632 | # e9.pack() 633 | # e9.place(x = 170,y = 395) 634 | 635 | # 工作部门 636 | labelt10 = tk.Label(self, 637 | text = "工作部门:", 638 | font = ("楷体",17) 639 | ) 640 | labelt10.pack(padx=5, pady=10, side=tk.LEFT) 641 | labelt10.place(x = 50,y = 435) 642 | var10 = StringVar() 643 | e10= Entry(self, 644 | textvariable = var10, 645 | ) 646 | e10.pack() 647 | e10.place(x =170,y = 445) 648 | 649 | # 姓名 650 | labelt11 = tk.Label(self, 651 | text="QQ/Wechat:", 652 | font=("楷体", 17) 653 | ) 654 | labelt11.pack(padx=5, pady=10, side=tk.LEFT) 655 | labelt11.place(x=350, y=285) 656 | 657 | var11 = StringVar() 658 | e11 = Entry(self, 659 | textvariable=var11, 660 | ) 661 | e11.pack() 662 | e11.place(x=500, y=285) 663 | 664 | # 年龄 665 | labelt12 = tk.Label(self, 666 | text="入职时间:", 667 | font=("楷体", 17) 668 | ) 669 | labelt12.pack(padx=5, pady=10, side=tk.LEFT) 670 | labelt12.place(x=350, y=335) 671 | var12 = StringVar() 672 | e12 = Entry(self, 673 | textvariable=var12, 674 | ) 675 | e12.pack() 676 | e12.place(x=500, y=335) 677 | 678 | # 性别 679 | labelt13 = tk.Label(self, 680 | text="等级:", 681 | font=("楷体", 17) 682 | ) 683 | labelt13.pack(padx=5, pady=10, side=tk.LEFT) 684 | labelt13.place(x=350, y=385) 685 | var13 = StringVar() 686 | e13 = Entry(self, 687 | textvariable=var13, 688 | ) 689 | e13.pack() 690 | e13.place(x=500, y=395) 691 | 692 | # 生日 693 | labelt14 = tk.Label(self, 694 | text="密码:", 695 | font=("楷体", 17) 696 | ) 697 | labelt14.pack(padx=5, pady=10, side=tk.LEFT) 698 | labelt14.place(x=350, y=435) 699 | var14 = StringVar() 700 | e14 = Entry(self, 701 | textvariable=var14, 702 | 703 | ) 704 | e14.pack() 705 | e14.place(x=500, y=435) 706 | 707 | def show(): 708 | basedata = { 709 | 'host': '103.248.223.58', 710 | 'port': 3306, 711 | 'user': 'root', 712 | 'passwd': 'h1613401', 713 | 'db': 'test', 714 | 'charset': 'utf8' 715 | } 716 | # 打开数据库连接 717 | conn = pymysql.connect(**basedata) 718 | 719 | try: 720 | 721 | Name = str(e1.get()) 722 | Id = str(e2.get()) 723 | Sex = str(e3.get()) 724 | Birthday = str(e4.get()) 725 | Level = str(e5.get()) 726 | Major = str(e6.get()) 727 | Graduate = str(e7.get()) 728 | phone = str(e8.get()) 729 | # #Emile = str(e9.get()) 730 | Department = str(e10.get()) 731 | Mail = str(e11.get()) 732 | Entry_time = str(e12.get()) 733 | # Level = str(e13.get()) 734 | Password = str(e14.get()) 735 | 736 | # 使用 cursor() 方法创建一个游标对象 cursor 737 | cursor = conn.cursor() 738 | print(Id,Name, Sex ,Birthday ,Graduate ,Major,phone,Mail,Department,Level,Password) 739 | 740 | sql = """INSERT INTO member(id,name, sex, birthday ,rank, edu,major,phone_number ,department,entry_time,mail) \ 741 | VALUES ('%s','%s ','%s','%s','%s','%s','%s','%s','%s','%s','%s')""" % \ 742 | (Id, Name, Sex, Birthday, Level, Graduate,Major, phone,Department,Entry_time,Mail) 743 | 744 | # sql = """INSERT INTO member(id,name, sex , birthday ,level , edu ,major,phone_number ,department,password,entry_time,mail) \ 745 | # VALUES ('%s','%s ','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')""" % \ 746 | # (Id, Name, Sex, Birthday, Level, Graduate, Major, phone,Department,Password,Entry_time,wechat) 747 | 748 | cursor.execute(sql) 749 | 750 | # commit 修改 751 | conn.commit() 752 | 753 | # 关闭游标 754 | cursor.close() 755 | 756 | # 关闭链接 757 | conn.close() 758 | tk.messagebox.showinfo('ok', '添加成功') 759 | print("添加成功") 760 | 761 | except: 762 | print("添加记录失败") 763 | tk.messagebox.showerror('error', '添加失败') 764 | # 发生错误时回滚 765 | conn.rollback() 766 | 767 | # 按钮设计 768 | btnkaishi = tk.Button(self, 769 | text="立即添加", 770 | width = 20, 771 | height = 4, 772 | activeforeground = "red", 773 | command = show 774 | ) 775 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 776 | btnkaishi.place(x = 50,y = 470) 777 | 778 | btnkaishi = tk.Button(self, 779 | text="返回查询", 780 | width = 20, 781 | height = 4, 782 | activeforeground = "red", 783 | command=lambda: root.show_frame(PageThree) 784 | ) 785 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 786 | btnkaishi.place(x = 500,y = 470) 787 | 788 | # 个人信息查询 789 | class PageThree(tk.Frame): 790 | def __init__(self, parent, root): 791 | super().__init__(parent) 792 | 793 | 794 | 795 | labeltxt = tk.Label(self, 796 | text = "个人信息", 797 | font = ("楷体",40), 798 | ) 799 | labeltxt.pack() 800 | labeltxt.place(x = 230,y = 10) 801 | # 姓名 802 | labelt1 = tk.Label(self, 803 | text = "姓名:", 804 | font = ("楷体",17) 805 | ) 806 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 807 | labelt1.place(x = 100,y = 70) 808 | var1 = StringVar() 809 | e1 = Entry(self, 810 | textvariable = var1, 811 | ) 812 | e1.pack() 813 | e1.place(x = 170,y = 80) 814 | 815 | # 年龄 816 | labelt2 = tk.Label(self, 817 | text = "年龄:", 818 | font = ("楷体",17) 819 | ) 820 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 821 | labelt2.place(x = 350,y = 70) 822 | var2 = StringVar() 823 | e2 = Entry(self, 824 | textvariable = var2, 825 | ) 826 | e2.pack() 827 | e2.place(x = 420,y = 80) 828 | 829 | # 性别 830 | labelt3 = tk.Label(self, 831 | text = "性别:", 832 | font = ("楷体",17) 833 | ) 834 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 835 | labelt3.place(x = 100,y = 150) 836 | var3 = StringVar() 837 | e3 = Entry(self, 838 | textvariable = var3, 839 | ) 840 | e3.pack() 841 | e3.place(x = 170,y = 160) 842 | 843 | # 生日 844 | labelt4 = tk.Label(self, 845 | text = "生日:", 846 | font = ("楷体",17) 847 | ) 848 | labelt4.pack(padx=5, pady=10, side=tk.LEFT) 849 | labelt4.place(x = 350,y = 150) 850 | var4 = StringVar() 851 | e4 = Entry(self, 852 | textvariable = var4, 853 | ) 854 | e4.pack() 855 | e4.place(x = 420,y = 160) 856 | 857 | # 学历 858 | labelt5 = tk.Label(self, 859 | text = "学历:", 860 | font = ("楷体",17) 861 | ) 862 | labelt5.pack(padx=5, pady=10, side=tk.LEFT) 863 | labelt5.place(x = 100,y = 230) 864 | var5 = StringVar() 865 | e5 = Entry(self, 866 | textvariable = var5, 867 | ) 868 | e5.pack() 869 | e5.place(x = 170,y = 240) 870 | 871 | # 专业 872 | labelt6 = tk.Label(self, 873 | text = "专业:", 874 | font = ("楷体",17) 875 | ) 876 | labelt6.pack(padx=5, pady=10, side=tk.LEFT) 877 | labelt6.place(x = 350,y = 230) 878 | var6 = StringVar() 879 | e6 = Entry(self, 880 | textvariable = var6, 881 | ) 882 | e6.pack() 883 | e6.place(x = 420,y = 240) 884 | 885 | # 固定电话 886 | labelt7 = tk.Label(self, 887 | text = "毕业学校:", 888 | font = ("楷体",17) 889 | ) 890 | labelt7.pack(padx=5, pady=10, side=tk.LEFT) 891 | labelt7.place(x = 180,y = 290) 892 | var7 = StringVar() 893 | e7= Entry(self, 894 | textvariable = var7, 895 | ) 896 | e7.pack() 897 | e7.place(x = 300,y = 300) 898 | 899 | # 手机号码 900 | labelt8 = tk.Label(self, 901 | text = "手机号码:", 902 | font = ("楷体",17) 903 | ) 904 | labelt8.pack(padx=5, pady=10, side=tk.LEFT) 905 | labelt8.place(x = 180,y = 350) 906 | var8 = StringVar() 907 | e8= Entry(self, 908 | textvariable = var8, 909 | ) 910 | e8.pack() 911 | e8.place(x = 300,y = 360) 912 | 913 | # QQ邮箱 914 | labelt9 = tk.Label(self, 915 | text = "QQ邮箱:", 916 | font = ("楷体",17) 917 | ) 918 | labelt9.pack(padx=5, pady=10, side=tk.LEFT) 919 | labelt9.place(x = 180,y = 410) 920 | var9 = StringVar() 921 | e9= Entry(self, 922 | textvariable = var9, 923 | ) 924 | e9.pack() 925 | e9.place(x = 300,y = 420) 926 | 927 | # 按钮设计 928 | btnkaishi = tk.Button(self, 929 | text="立即查询", 930 | width = 20, 931 | height = 4, 932 | activeforeground = "red", 933 | ) 934 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 935 | btnkaishi.place(x = 50,y = 470) 936 | 937 | btnkaishi = tk.Button(self, 938 | text="查询其他", 939 | width = 20, 940 | height = 4, 941 | activeforeground = "red", 942 | ) 943 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 944 | btnkaishi.place(x = 500,y = 470) 945 | 946 | #部门人员查询 947 | class PageFore(tk.Frame): 948 | def __init__(self, parent, root): 949 | super().__init__(parent) 950 | 951 | labeltxt = tk.Label(self, 952 | text = "部门人员查询", 953 | font = ("楷体",40), 954 | ) 955 | labeltxt.pack() 956 | labeltxt.place(x = 180,y = 10) 957 | 958 | labelt1 = tk.Label(self, 959 | text = "请输入所要查询的部门:", 960 | font = ("楷体",20) 961 | ) 962 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 963 | labelt1.place(x = 100,y = 100) 964 | var1 = StringVar() 965 | e1 = Entry(self, 966 | textvariable = var1, 967 | ) 968 | e1.pack() 969 | e1.place(x = 170,y = 140) 970 | 971 | # global Ret,row,vol 972 | 973 | def show1(): 974 | 975 | # basedata = {"103.248.223.58", "root", "h1613401", "test"} 976 | basedata = { 977 | 'host': '103.248.223.58', 978 | 'port': 3306, 979 | 'user': 'root', 980 | 'passwd': 'h1613401', 981 | 'db': 'test', 982 | 'charset': 'utf8' 983 | } 984 | # 打开数据库连接 985 | conn = pymysql.connect(**basedata) 986 | try: 987 | # 获取一个光标 988 | cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 989 | 990 | # 定义将要执行的sql语句 991 | sql = """select id,name,phone_number,mail,major from member where department=%s;"""%(e1.get()) 992 | # 拼接并执行sql语句 993 | cursor.execute(sql) 994 | 995 | # 取到查询结果 996 | ret1 = cursor.fetchall() # 取所有 997 | #ret1 = cursor.fetchone() # 取一条 998 | #ret2 = cursor.fetchmany(3) # 取三条 999 | 1000 | row = cursor.rowcount # 取得记录个数,用于设置表格的行数 1001 | vol = len(ret1[0]) # 取得字段数,用于设置表格的列数 1002 | Ret=ret1 1003 | 1004 | 1005 | cursor.close() 1006 | conn.close() 1007 | 1008 | def get_tree(): 1009 | # # # 删除原节点 1010 | # for _ in map(tree.delete, tree.get_children("")): 1011 | # pass 1012 | # 更新插入新节点 1013 | for i in range(0, row): 1014 | tree.insert("", "end", values=(i + 1, Ret[i]["id"], 1015 | Ret[i]["name"], 1016 | Ret[i]["phone_number"], 1017 | Ret[i]["mail"], 1018 | Ret[i]["major"])) 1019 | # tree.after(500, get_tree) 1020 | 1021 | get_tree() 1022 | 1023 | print(ret1) 1024 | print(e1.get()) 1025 | 1026 | print("查询成功") 1027 | # l.insert(END, ret1) 1028 | 1029 | except: 1030 | print("查询失败") 1031 | 1032 | # 发生错误时回滚 1033 | conn.rollback() 1034 | 1035 | # 表格内容插入 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | labelt2 = tk.Label(self, 1043 | text = "查询部门的结果:", 1044 | font = ("楷体",20), 1045 | fg = "red" 1046 | ) 1047 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1048 | labelt2.place(x = 10,y = 200) 1049 | 1050 | scrolly = Scrollbar(self) #滚动条 1051 | scrolly.pack(side=RIGHT, fill=Y) 1052 | 1053 | l = tk.Listbox(self,width = 10,height = 17,exportselection = False,yscrollcommand=scrolly.set) 1054 | l.pack() 1055 | l.place(x=0,y = 260) 1056 | 1057 | 1058 | tree = ttk.Treeview(l) # 表格 1059 | tree["columns"] = ("num","id","name", "phone_number","mail","major") 1060 | 1061 | # # 定义树形结构与滚动条 1062 | # vbar = ttk.Scrollbar(l, orient=VERTICAL, command=tree.yview) 1063 | # tree.configure(yscrollcommand=vbar.set) 1064 | 1065 | 1066 | tree.column("num", width=100) 1067 | tree.column("id", width=100) 1068 | tree.column("name", width=100) 1069 | tree.column("phone_number", width=100) 1070 | tree.column("mail", width=120) 1071 | tree.column("major", width=100) # 表示列,不显示 1072 | 1073 | tree.heading("num", text="num") 1074 | tree.heading("id", text="id") 1075 | tree.heading("name", text="name") # 显示表头 1076 | tree.heading("phone_number", text="phone_number") 1077 | tree.heading("mail", text="mail") 1078 | tree.heading("major", text="major") # 显示表头 1079 | 1080 | 1081 | b1 = tk.Button(self, text='查询', width=15, height=3, activeforeground="red", command=show1) 1082 | b1.pack(padx=5, pady=10) 1083 | b1.place(x=500, y=110) 1084 | 1085 | tree.pack() 1086 | 1087 | #专业配置 1088 | class PageFive(tk.Frame): 1089 | def __init__(self, parent, root): 1090 | super().__init__(parent) 1091 | labeltxt = tk.Label(self, 1092 | text = "专业配置", 1093 | font = ("楷体",40), 1094 | ) 1095 | labeltxt.pack() 1096 | labeltxt.place(x = 200,y = 10) 1097 | 1098 | labelt1 = tk.Label(self, 1099 | text = "请输入所要查询的专业:", 1100 | font = ("楷体",20) 1101 | ) 1102 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1103 | labelt1.place(x = 100,y = 100) 1104 | var1 = StringVar() 1105 | e1 = Entry(self, 1106 | textvariable = var1, 1107 | ) 1108 | e1.pack() 1109 | e1.place(x = 170,y = 140) 1110 | 1111 | b1=tk.Button(self,text='查询',width = 15,height = 3,activeforeground = "red") 1112 | b1.pack(padx = 5, pady = 10) 1113 | b1.place(x=500,y=110) 1114 | 1115 | labelt2 = tk.Label(self, 1116 | text = "查询专业的结果:", 1117 | font = ("楷体",20), 1118 | fg = "red" 1119 | ) 1120 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1121 | labelt2.place(x = 10,y = 200) 1122 | 1123 | scrolly = Scrollbar(self) 1124 | scrolly.pack(side=RIGHT, fill=Y) 1125 | 1126 | l = tk.Listbox(self, width=70, height=17, exportselection=False, yscrollcommand=scrolly.set) 1127 | l.pack() 1128 | l.place(x=10, y=260) 1129 | 1130 | 1131 | tree = ttk.Treeview(l) # 表格 1132 | tree["columns"] = ("姓名", "年龄", "身高") 1133 | tree.column("姓名", width=100) # 表示列,不显示 1134 | tree.column("年龄", width=100) 1135 | tree.column("身高", width=100) 1136 | tree.heading("姓名", text="姓名-name") # 显示表头 1137 | tree.heading("年龄", text="年龄-age") 1138 | tree.heading("身高", text="身高-tall") 1139 | tree.insert("", 0, text="line1", values=("1", "2", "3")) # 插入数据, 1140 | tree.insert("", 1, text="line1", values=("1", "2", "3")) 1141 | tree.insert("", 2, text="line1", values=("1", "2", "3")) 1142 | tree.insert("", 3, text="line1", values=("1", "2", "3")) 1143 | tree.pack() 1144 | 1145 | # 调动员工信息 1146 | class PageEight(tk.Frame): 1147 | def __init__(self, parent, root): 1148 | super().__init__(parent) 1149 | 1150 | label = tk.Label(self, text="人员调动", font=("楷体", 40), ) 1151 | label.pack() 1152 | label.place(x=200, y=10) 1153 | 1154 | labelt1 = tk.Label(self, 1155 | text="部门调动人员工号:", 1156 | font=("楷体", 20) 1157 | ) 1158 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1159 | labelt1.place(x=100, y=100) 1160 | 1161 | labelt1 = tk.Label(self, 1162 | text="调入部门:", 1163 | font=("楷体", 20) 1164 | ) 1165 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1166 | labelt1.place(x=50, y=200) 1167 | 1168 | labelt2 = tk.Label(self, 1169 | text="调入等级:", 1170 | font=("楷体", 20) 1171 | ) 1172 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1173 | labelt2.place(x=50, y=290) 1174 | 1175 | 1176 | var1 = StringVar() 1177 | var1.set(id1) 1178 | e1 = Entry(self, 1179 | textvariable=var1, 1180 | ) 1181 | e1.pack() 1182 | e1.place(x=370, y=100) 1183 | 1184 | var2 = StringVar() 1185 | e2 = Entry(self, 1186 | textvariable=var2, 1187 | ) 1188 | e2.pack() 1189 | e2.place(x=200, y=210) 1190 | 1191 | var3 = StringVar() 1192 | e3 = Entry(self, 1193 | textvariable=var3, 1194 | ) 1195 | e3.pack() 1196 | e3.place(x=200, y=300) 1197 | 1198 | # 建立对象 1199 | def tran(): 1200 | wangwu = Trans(e1.get()) 1201 | wangwu.department_trans(e1.get(), e2.get()) 1202 | 1203 | def d_trans(): 1204 | wangwu = Trans(e1.get()) 1205 | wangwu.rank_trans(e1.get(), e3.get()) 1206 | 1207 | 1208 | b1=tk.Button(self, text="部门调动", width=8, font=("楷体",20), command=tran) 1209 | b1.pack(padx=2, pady=20) 1210 | b1.place(x=400, y=200) 1211 | 1212 | b1 = tk.Button(self, text="等级调动", width=8, font=("楷体", 20), command=d_trans) 1213 | b1.pack(padx=2, pady=20) 1214 | b1.place(x=400, y=290) 1215 | 1216 | b2=tk.Button(self, text="返回首页", width=8, font=("楷体",20), command=lambda: root.show_frame(PageTwo)) 1217 | b2.pack(padx=5, pady=40) 1218 | b2.place(x=500, y=410) 1219 | 1220 | # 创建部门调动与级别调动类 1221 | class Trans(): 1222 | def __init__(self, id): 1223 | self.id = id 1224 | def department_trans(self, id, cur_department): 1225 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1226 | cursor = db.cursor() 1227 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1228 | sql_0 = "insert into trans set trans_date='%s'"%(now) 1229 | sql_1 = "update trans set id=%s where trans_date='%s'"%(id,now) 1230 | sql_2 = """ update trans, member 1231 | set trans.name=member.name, trans.entry_time=member.entry_time, 1232 | trans.ori_department=member.department, trans.ori_rank=member.rank, 1233 | trans.cur_department=%s, trans.cur_rank=member.rank 1234 | where trans.id=%s and member.id=%s and trans.trans_date='%s' 1235 | """%(cur_department, id, id, now) 1236 | sql_3 = """ update member, clock, salary 1237 | set member.department=%s, clock.department=%s, salary.department=%s 1238 | where member.id=%s and clock.id=%s and salary.id=%s 1239 | """%(cur_department, cur_department, cur_department, id, id, id) 1240 | try: 1241 | cursor.execute(sql_0) 1242 | cursor.execute(sql_1) 1243 | cursor.execute(sql_2) 1244 | cursor.execute(sql_3) 1245 | db.commit() 1246 | tk.messagebox.showinfo(title='ok', message='部门调动完成!') 1247 | print('部门调动完成') 1248 | except Exception as e: 1249 | tk.messagebox.showinfo(title='no', message='error') 1250 | print('error:'+str(e)) 1251 | db.rollback() 1252 | cursor.close() 1253 | db.close() 1254 | def rank_trans(self, id, cur_rank): 1255 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1256 | cursor = db.cursor() 1257 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1258 | sql_4 = "insert into trans set trans_date='%s'"%(now) 1259 | sql_5 = "update trans set id = %s where trans_date='%s'"%(id,now) 1260 | sql_6 = """ update trans, member 1261 | set trans.name = member.name, trans.entry_time = member.entry_time, 1262 | trans.ori_department = member.department, trans.ori_rank = member.rank, 1263 | trans.cur_department = member.department, trans.cur_rank = %s 1264 | where trans.id = %s and member.id = %s and trans.trans_date='%s' 1265 | """%(cur_rank, id, id, now) 1266 | sql_7 = """ update member, clock, salary 1267 | set member.rank = %s, clock.rank = %s, salary.rank = %s 1268 | where member.id = %s and clock.id = %s and salary.id = %s 1269 | """%(cur_rank, cur_rank, cur_rank, id, id, id) 1270 | try: 1271 | cursor.execute(sql_4) 1272 | cursor.execute(sql_5) 1273 | cursor.execute(sql_6) 1274 | cursor.execute(sql_7) 1275 | db.commit() 1276 | tk.messagebox.showinfo(title='ok', message='等级调动完成!') 1277 | print('等级调动完成') 1278 | except Exception as e: 1279 | tk.messagebox.showinfo(title='no', message='error') 1280 | print('error:'+str(e)) 1281 | db.rollback() 1282 | cursor.close() 1283 | db.close() 1284 | 1285 | #考勤信息 1286 | class PageNine(tk.Frame): 1287 | def __init__(self, parent, root): 1288 | super().__init__(parent) 1289 | 1290 | labeltxt = tk.Label(self, 1291 | text="考勤", 1292 | font=("楷体", 40), 1293 | ) 1294 | labeltxt.pack() 1295 | labeltxt.place(x=200, y=10) 1296 | 1297 | labelt1 = tk.Label(self, 1298 | text="考勤id:", 1299 | font=("楷体", 20) 1300 | ) 1301 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1302 | labelt1.place(x=100, y=100) 1303 | 1304 | var1 = StringVar() 1305 | var1.set(id1) 1306 | e1 = Entry(self, 1307 | textvariable=var1,state=DISABLED 1308 | ) 1309 | e1.pack() 1310 | e1.place(x=170, y=140) 1311 | 1312 | # 建立对象 1313 | def qiandao(): 1314 | wangwu = Clock(e1.get()) 1315 | wangwu.clock_in(e1.get()) 1316 | # wangwu.clock_out(e1.get()) 1317 | 1318 | def qiantui(): 1319 | wangwu = Clock(e1.get()) 1320 | # wangwu.clock_in(e1.get()) 1321 | wangwu.clock_out(e1.get()) 1322 | 1323 | b1 = tk.Button(self, text='签到', width=15, height=3, activeforeground="red", command=qiandao) 1324 | b1.pack(padx=5, pady=10) 1325 | b1.place(x=500, y=110) 1326 | 1327 | b2 = tk.Button(self, text='签退', width=15, height=3, activeforeground="red", command=qiantui) 1328 | b2.pack(padx=5, pady=10) 1329 | b2.place(x=500, y=210) 1330 | 1331 | # 创建考勤类 1332 | class Clock(): 1333 | def __init__(self, id): 1334 | self.id = id 1335 | def clock_in(self, id): 1336 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1337 | cursor = db.cursor() 1338 | # 考勤表中clock_in字段清零 1339 | try: 1340 | sql_0 = """ update clock, member 1341 | set clock_in='0000-00-00 00:00:00' 1342 | where clock.id=%s 1343 | """%(id) 1344 | cursor.execute(sql_0) 1345 | db.commit() 1346 | except Exception as e: 1347 | print('error:'+str(e)) 1348 | db.rollback() 1349 | # 签到 1350 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1351 | sql_1 = "update clock set clock_in='%s' where clock.id=%s"%(now, id) 1352 | if now[-8:]<='08:00:00': 1353 | sql_2 = "update history set clock_history=concat(clock_history,'未迟到 ') where history.id=%s"%(id) 1354 | try: 1355 | cursor.execute(sql_1) 1356 | cursor.execute(sql_2) 1357 | db.commit() 1358 | print("签到完成") 1359 | except Exception as e: 1360 | print('error:'+str(e)) 1361 | db.rollback() 1362 | cursor.close() 1363 | db.close() 1364 | else: 1365 | sql_3 = "update history set clock_history=concat(clock_history,'迟到 ') where history.id=%s"%(id) 1366 | try: 1367 | cursor.execute(sql_1) 1368 | cursor.execute(sql_3) 1369 | db.commit() 1370 | print('签到完成,已迟到') 1371 | except Exception as e: 1372 | print('error:'+str(e)) 1373 | db.rollback() 1374 | cursor.close() 1375 | db.close() 1376 | def clock_out(self, id): 1377 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1378 | cursor = db.cursor() 1379 | # 考勤表中clock_out字段清零 1380 | try: 1381 | sql_0 = """ update clock, member 1382 | set clock_out='0000-00-00 00:00:00' 1383 | where clock.id=%s 1384 | """%(id) 1385 | cursor.execute(sql_0) 1386 | db.commit() 1387 | except Exception as e: 1388 | print('error:'+str(e)) 1389 | db.rollback() 1390 | # 签到 1391 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1392 | sql_1 = "update clock set clock_out='%s' where clock.id=%s"%(now, id) 1393 | 1394 | if now[-8:]>='18:00:00': 1395 | # sql_1 = "update history set clock_history = left(clock_history,LENGTH(clock_history) - 1) where history.id=%s"%(id) 1396 | sql_2 = "update history set clock_history=concat(clock_history,'未早退;') where history.id=%s"%(id) 1397 | try: 1398 | cursor.execute(sql_1) 1399 | cursor.execute(sql_2) 1400 | db.commit() 1401 | print("签退完成") 1402 | except Exception as e: 1403 | print('error:'+str(e)) 1404 | db.rollback() 1405 | cursor.close() 1406 | db.close() 1407 | else: 1408 | 1409 | sql_3 = "update history set clock_history=concat(clock_history,'早退;') where history.id=%s"%(id) 1410 | try: 1411 | cursor.execute(sql_1) 1412 | cursor.execute(sql_3) 1413 | db.commit() 1414 | print('签退完成,已早退') 1415 | except Exception as e: 1416 | print('error:'+str(e)) 1417 | db.rollback() 1418 | cursor.close() 1419 | db.close() 1420 | 1421 | if __name__ == '__main__': 1422 | 1423 | 1424 | a=StartPage0() 1425 | 1426 | print(id1) 1427 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | 4 | import time 5 | import datetime 6 | 7 | import tkinter as tk 8 | from tkinter import ttk 9 | from tkinter import messagebox # import this to fix messagebox error 10 | from tkinter import * 11 | import pymysql 12 | import pickle 13 | 14 | import xlsxwriter 15 | import matplotlib.pyplot as plt 16 | from matplotlib.pylab import mpl 17 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk 18 | from matplotlib.figure import Figure 19 | 20 | 21 | mpl.rcParams['font.sans-serif'] = ['SimHei'] # 中文显示 22 | mpl.rcParams['axes.unicode_minus'] = False # 负号显示 23 | 24 | 25 | class Application(tk.Tk): 26 | 27 | def __init__(self): 28 | super().__init__() #super() 函数是用于调用父类(超类)的一个方法。 29 | 30 | self.wm_title("人才管理系统") 31 | self.geometry("930x600") 32 | self.resizable(width = 0,height = False) 33 | 34 | 35 | 36 | container = tk.Frame(self) 37 | container.pack(side="top", fill="both", expand = True) #fill 填充整个分配给它的空间 38 | container.grid_rowconfigure(0, weight=1)#grid 网格 39 | container.grid_columnconfigure(0, weight=1) 40 | 41 | # 创建一个菜单项,类似于导航栏 42 | menubar=Menu(self) 43 | # 创建菜单项 44 | # menubar.add_cascade(label="登录",command=lambda: self.show_frame(StartPage)) 45 | menubar.add_cascade(label="考勤",command=lambda: self.show_frame(PageNine)) 46 | menubar.add_cascade(label="个人信息注册",command=lambda: self.show_frame(PageTwo)) 47 | menubar.add_cascade(label="个人信息查询",command=lambda: self.show_frame(PageThree)) 48 | menubar.add_cascade(label="部门人员查询",command=lambda: self.show_frame(PageFore)) 49 | menubar.add_cascade(label="专业配置",command=lambda: self.show_frame(PageFive)) 50 | menubar.add_cascade(label="工资查询",command=lambda: self.show_frame(PageSix)) 51 | menubar.add_cascade(label="签到情况查询",command=lambda: self.show_frame(PageSeven)) 52 | menubar.add_cascade(label="人员调动", command=lambda: self.show_frame(PageEight)) 53 | self['menu']=menubar 54 | 55 | self.frames = {} 56 | 57 | for F in (PageNine,PageTwo, PageThree,PageFore,PageSix,PageSeven,PageEight,PageFive): 58 | frame = F(container, self) 59 | self.frames[F] = frame 60 | frame.grid(row=0, column=0, sticky="nsew") # 四个页面的位置都是 grid(row=0, column=0), 位置重叠,只有最上面的可见!! 61 | 62 | 63 | self.show_frame(PageThree) 64 | 65 | 66 | def show_frame(self, cont): 67 | frame = self.frames[cont] 68 | frame.tkraise() # 切换,提升当前 tk.Frame z轴顺序 69 | 70 | 71 | 72 | #登录界面、 73 | class StartPage(tk.Frame): 74 | def __init__(self, parent, root): 75 | super().__init__(parent) 76 | 77 | 78 | 79 | labeltxt = tk.Label(self, 80 | text = "用户登录", 81 | font = ("楷体",40), 82 | ) 83 | labeltxt.pack() 84 | labeltxt.place(x = 240,y = 50) 85 | 86 | labelt1 = tk.Label(self, 87 | text = "账户:", 88 | font = ("楷体",25) 89 | ) 90 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 91 | labelt1.place(x = 210,y = 200) 92 | 93 | var1 = StringVar() 94 | e1 = Entry(self, 95 | textvariable = var1, 96 | ) 97 | e1.pack() 98 | e1.place(x = 300,y = 215) 99 | 100 | # 登录密码 101 | labelt2 = tk.Label(self, 102 | text = "密码:", 103 | font = ("楷体",25) 104 | ) 105 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 106 | labelt2.place(x = 210,y = 320) 107 | 108 | var2 = StringVar() 109 | e2 = Entry(self, 110 | textvariable = var2, 111 | show = "*" 112 | ) 113 | e2.pack() 114 | e2.place(x = 300,y = 335) 115 | 116 | # 按钮设计 117 | btnkaishi = tk.Button(self, 118 | text="直接登录", 119 | width = 20, 120 | height = 4, 121 | activeforeground = "red", 122 | # command=lambda: 123 | 124 | ) 125 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 126 | btnkaishi.place(x = 50,y = 470) 127 | 128 | btnkaishi = tk.Button(self, 129 | text="立即注册", 130 | width = 20, 131 | height = 4, 132 | activeforeground = "red", 133 | command=lambda: root.show_frame(PageOne) 134 | ) 135 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 136 | btnkaishi.place(x = 500,y = 470) 137 | 138 | #注册账号信息、 139 | class PageOne(tk.Frame): 140 | 141 | 142 | 143 | # root = tk.Tk() 144 | # root.iconbitmap(".//school_logo.ico") 145 | # root.title('Employee-managerment') 146 | # root.geometry('450x300') 147 | # view = PageOne(root) 148 | # view.pack(side="top", fill="both", expand=True) 149 | # root.mainloop() 150 | 151 | def __init__(self, *args, **kwargs): 152 | 153 | tk.Frame.__init__(self, *args, **kwargs) 154 | 155 | 156 | b = tk.Button(self, text="Open new window", command=self.new_window1) 157 | b.pack(side="bottom") 158 | 159 | # welcome image 160 | canvas = tk.Canvas(self, height=200, width=500) # 画布 161 | image_file = tk.PhotoImage(file='welcome.gif') # 加载图片文件 162 | image = canvas.create_image(0, 0, anchor='nw', image=image_file) # 将图片置于画布上 163 | canvas.pack(side='top') # 放置画布(为上端) 164 | 165 | # user information 166 | tk.Label(self, text='User name: ').place(x=50, y=150) 167 | tk.Label(self, text='Password: ').place(x=50, y=190) 168 | 169 | var_usr_name = tk.StringVar() # 定义变量 170 | var_usr_name.set('example@python.com') 171 | entry_usr_name = tk.Entry(self, textvariable=var_usr_name) 172 | entry_usr_name.place(x=160, y=150) 173 | var_usr_pwd = tk.StringVar() 174 | entry_usr_pwd = tk.Entry(self, textvariable=var_usr_pwd, show='*') 175 | entry_usr_pwd.place(x=160, y=190) 176 | 177 | def enter_mainwindows(): 178 | # 实例化Application 179 | app = Application() 180 | app.iconbitmap(".//school_logo.ico") 181 | # 主循环: 182 | app.mainloop() 183 | def usr_login(): 184 | usr_name = var_usr_name.get() 185 | usr_pwd = var_usr_pwd.get() 186 | 187 | ##这里设置异常捕获,当我们第一次访问用户信息文件时是不存在的,所以这里设置异常捕获。 188 | ##中间的两行就是我们的匹配,即程序将输入的信息和文件中的信息匹配。 189 | try: 190 | with open('usrs_info.pickle', 'rb') as usr_file: 191 | usrs_info = pickle.load(usr_file) 192 | except FileNotFoundError: 193 | ##这里就是我们在没有读取到`usr_file`的时候,程序会创建一个`usr_file`这个文件,并将管理员 194 | ##的用户和密码写入,即用户名为`admin`密码为`admin`。 195 | with open('usrs_info.pickle', 'wb') as usr_file: 196 | usrs_info = {'admin': 'admin'} 197 | pickle.dump(usrs_info, usr_file) 198 | 199 | if usr_name in usrs_info: 200 | if usr_pwd == usrs_info[usr_name]: 201 | tk.messagebox.showinfo(title='Welcome', message='How are you? ' + usr_name) 202 | root.destroy() 203 | enter_mainwindows() 204 | else: 205 | tk.messagebox.showerror(message='Error, your password is wrong, try again.') 206 | else: 207 | is_sign_up = tk.messagebox.askyesno('Welcome', 208 | 'You have not signed up yet. Sign up today?') 209 | if is_sign_up: 210 | self.new_window1() 211 | 212 | 213 | # login and sign up button 214 | btn_login = tk.Button(self, text='Login', command=usr_login) 215 | btn_login.place(x=170, y=230) 216 | btn_sign_up = tk.Button(self, text='Sign up', command=self.new_window1) 217 | btn_sign_up.place(x=270, y=230) 218 | 219 | def new_window1(self): 220 | 221 | window = tk.Toplevel(self) 222 | window.title("人才管理系统") 223 | window.geometry("700x600") 224 | label = tk.Label(window, text=id) 225 | label.pack(side="top", fill="both", padx=10, pady=10) 226 | 227 | labeltxt = tk.Label(window, 228 | text="账号注册", 229 | font=("楷体", 40), 230 | ) 231 | labeltxt.pack() 232 | labeltxt.place(x=240, y=50) 233 | 234 | # 登录账号 235 | labelt1 = tk.Label(window, 236 | text="账户:", 237 | font=("楷体", 25) 238 | ) 239 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 240 | labelt1.place(x=200, y=140) 241 | 242 | var1 = StringVar() 243 | e1 = Entry(window, 244 | textvariable=var1, 245 | ) 246 | e1.pack() 247 | e1.place(x=305, y=150) 248 | 249 | # 登录密码 250 | labelt2 = tk.Label(window, 251 | text="密码:", 252 | font=("楷体", 25) 253 | ) 254 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 255 | labelt2.place(x=200, y=240) 256 | 257 | var2 = StringVar() 258 | e2 = Entry(window, 259 | textvariable=var2, 260 | show="*" 261 | ) 262 | e2.pack() 263 | e2.place(x=305, y=250) 264 | 265 | # 确认密码 266 | labelt3 = tk.Label(window, 267 | text="确认密码:", 268 | font=("楷体", 25) 269 | ) 270 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 271 | labelt3.place(x=150, y=350) 272 | 273 | var3 = StringVar() 274 | e3 = Entry(window, 275 | textvariable=var3, 276 | show="*" 277 | ) 278 | e3.pack() 279 | e3.place(x=305, y=365) 280 | 281 | labelp = tk.Label(window, 282 | text=" ", 283 | font=("楷体", 20) 284 | ) 285 | labelp.pack(padx=5, pady=10, side=tk.LEFT) 286 | labelp.place(x=200, y=400) 287 | 288 | def show1(): 289 | basedata = { 290 | 'host': '103.248.223.58', 291 | 'port': 3306, 292 | 'user': 'root', 293 | 'passwd': '123', 294 | 'db': 'test', 295 | 'charset': 'utf8' 296 | } 297 | # 打开数据库连接 298 | conn = pymysql.connect(**basedata) 299 | 300 | try: 301 | User = str(e1.get()) 302 | Passwd = str(e2.get()) 303 | 304 | # 使用 cursor() 方法创建一个游标对象 cursor 305 | cursor = conn.cursor() 306 | print() 307 | 308 | sql = "INSERT INTO test1(id,name ) \ 309 | VALUES ('%s', '%s' )" % \ 310 | (User, Passwd) 311 | 312 | cursor.execute(sql) 313 | 314 | # commit 修改 315 | conn.commit() 316 | 317 | # 关闭游标 318 | cursor.close() 319 | 320 | # 关闭链接 321 | conn.close() 322 | print("添加成功") 323 | 324 | labelp.configure(text="注册成功") 325 | 326 | except: 327 | print("添加记录失败") 328 | labelp.configure(text="注册失败") 329 | # 发生错误时回滚 330 | conn.rollback() 331 | 332 | # 按钮设计 333 | btnkaishi = tk.Button(window, 334 | text="立即注册", 335 | width=20, 336 | height=4, 337 | activeforeground="red", 338 | command=show1 339 | ) 340 | btnkaishi.pack(padx=5, pady=10, side=tk.LEFT) 341 | btnkaishi.place(x=50, y=470) 342 | 343 | btnkaishi = tk.Button(window, 344 | text="返回登录", 345 | width=20, 346 | height=4, 347 | activeforeground="red", 348 | command=lambda: window.show_frame(StartPage) 349 | ) 350 | btnkaishi.pack(padx=5, pady=10, side=tk.LEFT) 351 | btnkaishi.place(x=500, y=470) 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | # window = tk.Toplevel() 360 | # label = tk.Label(window, text=id) 361 | # label.pack(side="top", fill="both", padx=10, pady=10) 362 | 363 | 364 | # 注册个人信息页面 365 | class PageTwo(tk.Frame): 366 | def __init__(self, parent, root): 367 | super().__init__(parent) 368 | 369 | labeltxt = tk.Label(self, 370 | text = "用户注册", 371 | font = ("楷体",40), 372 | ) 373 | labeltxt.pack() 374 | labeltxt.place(x = 230,y = 10) 375 | 376 | 377 | # 姓名 378 | labelt1 = tk.Label(self, 379 | text = "姓名:", 380 | font = ("楷体",17) 381 | ) 382 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 383 | labelt1.place(x = 100,y = 70) 384 | 385 | var1 = StringVar() 386 | e1 = Entry(self, 387 | textvariable = var1, 388 | ) 389 | e1.pack() 390 | e1.place(x = 170,y = 80) 391 | 392 | # 年龄 393 | labelt2 = tk.Label(self, 394 | text = "ID:", 395 | font = ("楷体",17) 396 | ) 397 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 398 | labelt2.place(x = 350,y = 70) 399 | var2 = StringVar() 400 | e2 = Entry(self, 401 | textvariable = var2, 402 | ) 403 | e2.pack() 404 | e2.place(x = 420,y = 80) 405 | 406 | # 性别 407 | labelt3 = tk.Label(self, 408 | text = "性别:", 409 | font = ("楷体",17) 410 | ) 411 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 412 | labelt3.place(x = 100,y = 150) 413 | var3 = StringVar() 414 | e3 = Entry(self, 415 | textvariable = var3, 416 | ) 417 | e3.pack() 418 | e3.place(x = 170,y = 160) 419 | 420 | # 生日 421 | labelt4 = tk.Label(self, 422 | text = "生日:", 423 | font = ("楷体",17) 424 | ) 425 | labelt4.pack(padx=5, pady=10, side=tk.LEFT) 426 | labelt4.place(x = 350,y = 150) 427 | var4 = StringVar() 428 | e4 = Entry(self, 429 | textvariable = var4, 430 | ) 431 | e4.pack() 432 | e4.place(x = 420,y = 160) 433 | 434 | # 学历 435 | labelt5 = tk.Label(self, 436 | text = "学历:", 437 | font = ("楷体",17) 438 | ) 439 | labelt5.pack(padx=5, pady=10, side=tk.LEFT) 440 | labelt5.place(x = 100,y = 230) 441 | var5 = StringVar() 442 | e5 = Entry(self, 443 | textvariable = var5, 444 | ) 445 | e5.pack() 446 | e5.place(x = 170,y = 240) 447 | 448 | # 专业 449 | labelt6 = tk.Label(self, 450 | text = "专业:", 451 | font = ("楷体",17) 452 | ) 453 | labelt6.pack(padx=5, pady=10, side=tk.LEFT) 454 | labelt6.place(x = 350,y = 230) 455 | var6 = StringVar() 456 | e6 = Entry(self, 457 | textvariable = var6, 458 | ) 459 | e6.pack() 460 | e6.place(x = 420,y = 240) 461 | 462 | # 学校 463 | labelt7 = tk.Label(self, 464 | text = "毕业学校:", 465 | font = ("楷体",17) 466 | ) 467 | labelt7.pack(padx=5, pady=10, side=tk.LEFT) 468 | labelt7.place(x = 50,y = 285) 469 | var7 = StringVar() 470 | e7= Entry(self, 471 | textvariable = var7, 472 | ) 473 | e7.pack() 474 | e7.place(x = 170,y = 295) 475 | 476 | # 手机号码 477 | labelt8 = tk.Label(self, 478 | text = "手机号码:", 479 | font = ("楷体",17) 480 | ) 481 | labelt8.pack(padx=5, pady=10, side=tk.LEFT) 482 | labelt8.place(x =50,y = 335) 483 | var8 = StringVar() 484 | e8= Entry(self, 485 | textvariable = var8, 486 | ) 487 | e8.pack() 488 | e8.place(x = 170,y = 345) 489 | 490 | # # QQ邮箱 491 | # labelt9 = tk.Label(self, 492 | # text = "QQ邮箱:", 493 | # font = ("楷体",17) 494 | # ) 495 | # labelt9.pack(padx=5, pady=10, side=tk.LEFT) 496 | # labelt9.place(x = 50,y = 385) 497 | # var9 = StringVar() 498 | # e9= Entry(self, 499 | # textvariable = var9, 500 | # ) 501 | # e9.pack() 502 | # e9.place(x = 170,y = 395) 503 | 504 | # 工作部门 505 | labelt10 = tk.Label(self, 506 | text = "工作部门:", 507 | font = ("楷体",17) 508 | ) 509 | labelt10.pack(padx=5, pady=10, side=tk.LEFT) 510 | labelt10.place(x = 50,y = 435) 511 | var10 = StringVar() 512 | e10= Entry(self, 513 | textvariable = var10, 514 | ) 515 | e10.pack() 516 | e10.place(x =170,y = 445) 517 | 518 | # 姓名 519 | labelt11 = tk.Label(self, 520 | text="QQ/Wechat:", 521 | font=("楷体", 17) 522 | ) 523 | labelt11.pack(padx=5, pady=10, side=tk.LEFT) 524 | labelt11.place(x=350, y=285) 525 | 526 | var11 = StringVar() 527 | e11 = Entry(self, 528 | textvariable=var11, 529 | ) 530 | e11.pack() 531 | e11.place(x=500, y=285) 532 | 533 | # 年龄 534 | labelt12 = tk.Label(self, 535 | text="入职时间:", 536 | font=("楷体", 17) 537 | ) 538 | labelt12.pack(padx=5, pady=10, side=tk.LEFT) 539 | labelt12.place(x=350, y=335) 540 | var12 = StringVar() 541 | e12 = Entry(self, 542 | textvariable=var12, 543 | ) 544 | e12.pack() 545 | e12.place(x=500, y=335) 546 | 547 | # 性别 548 | labelt13 = tk.Label(self, 549 | text="等级:", 550 | font=("楷体", 17) 551 | ) 552 | labelt13.pack(padx=5, pady=10, side=tk.LEFT) 553 | labelt13.place(x=350, y=385) 554 | var13 = StringVar() 555 | e13 = Entry(self, 556 | textvariable=var13, 557 | ) 558 | e13.pack() 559 | e13.place(x=500, y=395) 560 | 561 | # 生日 562 | labelt14 = tk.Label(self, 563 | text="密码:", 564 | font=("楷体", 17) 565 | ) 566 | labelt14.pack(padx=5, pady=10, side=tk.LEFT) 567 | labelt14.place(x=350, y=435) 568 | var14 = StringVar() 569 | e14 = Entry(self, 570 | textvariable=var14, 571 | 572 | ) 573 | e14.pack() 574 | e14.place(x=500, y=435) 575 | 576 | def show(): 577 | basedata = { 578 | 'host':'103.248.223.58', 579 | 'port':3306, 580 | 'user':'root', 581 | 'passwd':'123', 582 | 'db':'test', 583 | 'charset':'utf8' 584 | } 585 | # 打开数据库连接 586 | conn = pymysql.connect(**basedata) 587 | 588 | try: 589 | 590 | Name = str(e1.get()) 591 | Id = str(e2.get()) 592 | Sex = str(e3.get()) 593 | Birthday = str(e4.get()) 594 | Edb = str(e5.get()) 595 | Major = str(e6.get()) 596 | Graduate = str(e7.get()) 597 | phone = str(e8.get()) 598 | # #Emile = str(e9.get()) 599 | Department = str(e10.get()) 600 | wechat = str(e11.get()) 601 | Entry_time = str(e12.get()) 602 | # Level = str(e13.get()) 603 | Password = str(e14.get()) 604 | 605 | # 使用 cursor() 方法创建一个游标对象 cursor 606 | cursor = conn.cursor() 607 | # print(Id,Name, Sex ,Birthday ,Edb,Graduate ,Major,phone,wechat,Entray_time,Department,Level,Password) 608 | 609 | # sql = "INSERT INTO member(id,name, sex , birthday ,EDB , graduate ,major ,Phone ,QQ/Wechat,entray_time,department,level,password) \ 610 | # VALUES ('%s','%s ','%s','%s','%s' ,'%s','%s' , '%s' ,'%s' ,'%s','%d' , '%s')" % \ 611 | # (Id,Name, Sex ,Birthday ,Edb,Graduate ,Major,phone,wechat,Entray_time,Department,Level,Password) 612 | 613 | sql = "INSERT INTO member(id,name, sex , birthday ,EDB , graduate ,major,Phone ,department,password,entry_time,Wechat) \ 614 | VALUES ('%s','%s ','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % \ 615 | (Id, Name, Sex, Birthday, Edb, Graduate, Major, phone,Department,Password,Entry_time,wechat) 616 | 617 | # 618 | # 619 | # sql = "INSERT INTO member(id,name, sex , birthday ,EDB , graduate ,major,Phone ) \ 620 | # VALUES ('%s','%s ','%s','%s','%s','%s','%s','%s')" % \ 621 | # (Id ,Name, Sex ,Birthday,Edb, Graduate ,Major,phone) 622 | 623 | 624 | cursor.execute(sql) 625 | 626 | 627 | # commit 修改 628 | conn.commit() 629 | 630 | # 关闭游标 631 | cursor.close() 632 | 633 | # 关闭链接 634 | conn.close() 635 | print("添加成功") 636 | 637 | except: 638 | print("添加记录失败") 639 | 640 | # 发生错误时回滚 641 | conn.rollback() 642 | 643 | # 按钮设计 644 | btnkaishi = tk.Button(self, 645 | text="立即注册", 646 | width = 20, 647 | height = 4, 648 | activeforeground = "red", 649 | command = show 650 | ) 651 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 652 | btnkaishi.place(x = 50,y = 470) 653 | 654 | btnkaishi = tk.Button(self, 655 | text="返回查询", 656 | width = 20, 657 | height = 4, 658 | activeforeground = "red", 659 | command=lambda: root.show_frame(PageThree) 660 | ) 661 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 662 | btnkaishi.place(x = 500,y = 470) 663 | 664 | # 个人信息查询 665 | class PageThree(tk.Frame): 666 | def __init__(self, parent, root): 667 | super().__init__(parent) 668 | labeltxt = tk.Label(self, 669 | text = "个人信息", 670 | font = ("楷体",40), 671 | ) 672 | labeltxt.pack() 673 | labeltxt.place(x = 230,y = 10) 674 | # 姓名 675 | labelt1 = tk.Label(self, 676 | text = "姓名:", 677 | font = ("楷体",17) 678 | ) 679 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 680 | labelt1.place(x = 100,y = 70) 681 | var1 = StringVar() 682 | e1 = Entry(self, 683 | textvariable = var1, 684 | ) 685 | e1.pack() 686 | e1.place(x = 170,y = 80) 687 | 688 | # 年龄 689 | labelt2 = tk.Label(self, 690 | text = "年龄:", 691 | font = ("楷体",17) 692 | ) 693 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 694 | labelt2.place(x = 350,y = 70) 695 | var2 = StringVar() 696 | e2 = Entry(self, 697 | textvariable = var2, 698 | ) 699 | e2.pack() 700 | e2.place(x = 420,y = 80) 701 | 702 | # 性别 703 | labelt3 = tk.Label(self, 704 | text = "性别:", 705 | font = ("楷体",17) 706 | ) 707 | labelt3.pack(padx=5, pady=10, side=tk.LEFT) 708 | labelt3.place(x = 100,y = 150) 709 | var3 = StringVar() 710 | e3 = Entry(self, 711 | textvariable = var3, 712 | ) 713 | e3.pack() 714 | e3.place(x = 170,y = 160) 715 | 716 | # 生日 717 | labelt4 = tk.Label(self, 718 | text = "生日:", 719 | font = ("楷体",17) 720 | ) 721 | labelt4.pack(padx=5, pady=10, side=tk.LEFT) 722 | labelt4.place(x = 350,y = 150) 723 | var4 = StringVar() 724 | e4 = Entry(self, 725 | textvariable = var4, 726 | ) 727 | e4.pack() 728 | e4.place(x = 420,y = 160) 729 | 730 | # 学历 731 | labelt5 = tk.Label(self, 732 | text = "学历:", 733 | font = ("楷体",17) 734 | ) 735 | labelt5.pack(padx=5, pady=10, side=tk.LEFT) 736 | labelt5.place(x = 100,y = 230) 737 | var5 = StringVar() 738 | e5 = Entry(self, 739 | textvariable = var5, 740 | ) 741 | e5.pack() 742 | e5.place(x = 170,y = 240) 743 | 744 | # 专业 745 | labelt6 = tk.Label(self, 746 | text = "专业:", 747 | font = ("楷体",17) 748 | ) 749 | labelt6.pack(padx=5, pady=10, side=tk.LEFT) 750 | labelt6.place(x = 350,y = 230) 751 | var6 = StringVar() 752 | e6 = Entry(self, 753 | textvariable = var6, 754 | ) 755 | e6.pack() 756 | e6.place(x = 420,y = 240) 757 | 758 | # 固定电话 759 | labelt7 = tk.Label(self, 760 | text = "毕业学校:", 761 | font = ("楷体",17) 762 | ) 763 | labelt7.pack(padx=5, pady=10, side=tk.LEFT) 764 | labelt7.place(x = 180,y = 290) 765 | var7 = StringVar() 766 | e7= Entry(self, 767 | textvariable = var7, 768 | ) 769 | e7.pack() 770 | e7.place(x = 300,y = 300) 771 | 772 | # 手机号码 773 | labelt8 = tk.Label(self, 774 | text = "手机号码:", 775 | font = ("楷体",17) 776 | ) 777 | labelt8.pack(padx=5, pady=10, side=tk.LEFT) 778 | labelt8.place(x = 180,y = 350) 779 | var8 = StringVar() 780 | e8= Entry(self, 781 | textvariable = var8, 782 | ) 783 | e8.pack() 784 | e8.place(x = 300,y = 360) 785 | 786 | # QQ邮箱 787 | labelt9 = tk.Label(self, 788 | text = "QQ邮箱:", 789 | font = ("楷体",17) 790 | ) 791 | labelt9.pack(padx=5, pady=10, side=tk.LEFT) 792 | labelt9.place(x = 180,y = 410) 793 | var9 = StringVar() 794 | e9= Entry(self, 795 | textvariable = var9, 796 | ) 797 | e9.pack() 798 | e9.place(x = 300,y = 420) 799 | 800 | # 按钮设计 801 | btnkaishi = tk.Button(self, 802 | text="立即查询", 803 | width = 20, 804 | height = 4, 805 | activeforeground = "red", 806 | ) 807 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 808 | btnkaishi.place(x = 50,y = 470) 809 | 810 | btnkaishi = tk.Button(self, 811 | text="查询其他", 812 | width = 20, 813 | height = 4, 814 | activeforeground = "red", 815 | ) 816 | btnkaishi.pack(padx = 5, pady = 10, side = tk.LEFT) 817 | btnkaishi.place(x = 500,y = 470) 818 | 819 | #部门人员查询 820 | class PageFore(tk.Frame): 821 | def __init__(self, parent, root): 822 | super().__init__(parent) 823 | 824 | labeltxt = tk.Label(self, 825 | text = "部门人员查询", 826 | font = ("楷体",40), 827 | ) 828 | labeltxt.pack() 829 | labeltxt.place(x = 180,y = 10) 830 | 831 | labelt1 = tk.Label(self, 832 | text = "请输入所要查询的部门:", 833 | font = ("楷体",20) 834 | ) 835 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 836 | labelt1.place(x = 100,y = 100) 837 | var1 = StringVar() 838 | e1 = Entry(self, 839 | textvariable = var1, 840 | ) 841 | e1.pack() 842 | e1.place(x = 170,y = 140) 843 | 844 | # global Ret,row,vol 845 | 846 | def show1(): 847 | 848 | basedata = {"103.248.223.58", "root", "h1613401", "test"} 849 | # basedata = { 850 | # 'host': 'localhost', 851 | # 'port': 3306, 852 | # 'user': 'root', 853 | # 'passwd': ' ', 854 | # 'db': 'test', 855 | # 'charset': 'utf8' 856 | # } 857 | # 打开数据库连接 858 | conn = pymysql.connect(**basedata) 859 | try: 860 | # 获取一个光标 861 | cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 862 | 863 | # 定义将要执行的sql语句 864 | sql = 'select user,passwd from userr where user=%s;'%e1.get() 865 | # 拼接并执行sql语句 866 | cursor.execute(sql) 867 | 868 | # 取到查询结果 869 | ret1 = cursor.fetchall() # 取所有 870 | #ret1 = cursor.fetchone() # 取一条 871 | #ret2 = cursor.fetchmany(3) # 取三条 872 | 873 | row = cursor.rowcount # 取得记录个数,用于设置表格的行数 874 | vol = len(ret1[0]) # 取得字段数,用于设置表格的列数 875 | Ret=ret1 876 | 877 | 878 | cursor.close() 879 | conn.close() 880 | 881 | def get_tree(): 882 | # # # 删除原节点 883 | # for _ in map(tree.delete, tree.get_children("")): 884 | # pass 885 | # 更新插入新节点 886 | for i in range(0, row): 887 | tree.insert("", "end", values=(i + 1, Ret[i]["user"], 888 | Ret[i]["passwd"])) 889 | # tree.after(500, get_tree) 890 | 891 | get_tree() 892 | 893 | print(ret1) 894 | print(e1.get()) 895 | 896 | print("查询成功") 897 | # l.insert(END, ret1) 898 | 899 | except: 900 | print("查询失败") 901 | 902 | # 发生错误时回滚 903 | conn.rollback() 904 | 905 | # 表格内容插入 906 | 907 | 908 | 909 | 910 | 911 | 912 | labelt2 = tk.Label(self, 913 | text = "查询部门的结果:", 914 | font = ("楷体",20), 915 | fg = "red" 916 | ) 917 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 918 | labelt2.place(x = 10,y = 200) 919 | 920 | scrolly = Scrollbar(self) #滚动条 921 | scrolly.pack(side=RIGHT, fill=Y) 922 | 923 | l=tk.Listbox(self,width = 70,height = 17,exportselection = False,yscrollcommand=scrolly.set) 924 | l.pack() 925 | l.place(x=10,y = 260) 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | tree = ttk.Treeview(l) # 表格 936 | tree["columns"] = ("num","user", "passwd") 937 | 938 | # # 定义树形结构与滚动条 939 | # vbar = ttk.Scrollbar(l, orient=VERTICAL, command=tree.yview) 940 | # tree.configure(yscrollcommand=vbar.set) 941 | 942 | tree.column("num", width=100) 943 | tree.column("user", width=100) # 表示列,不显示 944 | tree.column("passwd", width=100) 945 | # tree.column("身高", width=100) 946 | 947 | tree.heading("num", text="num-id") 948 | tree.heading("user", text="user-name") # 显示表头 949 | tree.heading("passwd", text="passwd-age") 950 | # tree.heading("身高", text="身高-tall") 951 | 952 | # tree.insert("", 0, text="line1", values=("1", "2", "3")) # 插入数据, 953 | # tree.insert("", 1, text="line1", values=("1", "2", "3")) 954 | # tree.insert("", 2, text="line1", values=("1", "2", "3")) 955 | # tree.insert("", 3, text="line1", values=("1", "2", "3")) 956 | 957 | 958 | 959 | # 调用方法获取表格内容插入 960 | # get_tree() 961 | # tree.grid(row=0, column=0, sticky=NSEW) 962 | # vbar.grid(row=0, column=1, sticky=NS) 963 | 964 | 965 | b1 = tk.Button(self, text='查询', width=15, height=3, activeforeground="red", command=show1) 966 | b1.pack(padx=5, pady=10) 967 | b1.place(x=500, y=110) 968 | 969 | tree.pack() 970 | 971 | #专业配置 972 | class PageFive(tk.Frame): 973 | def __init__(self, parent, root): 974 | super().__init__(parent) 975 | labeltxt = tk.Label(self, 976 | text = "专业配置", 977 | font = ("楷体",40), 978 | ) 979 | labeltxt.pack() 980 | labeltxt.place(x = 200,y = 10) 981 | 982 | labelt1 = tk.Label(self, 983 | text = "请输入所要查询的专业:", 984 | font = ("楷体",20) 985 | ) 986 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 987 | labelt1.place(x = 100,y = 100) 988 | var1 = StringVar() 989 | e1 = Entry(self, 990 | textvariable = var1, 991 | ) 992 | e1.pack() 993 | e1.place(x = 170,y = 140) 994 | 995 | b1=tk.Button(self,text='查询',width = 15,height = 3,activeforeground = "red") 996 | b1.pack(padx = 5, pady = 10) 997 | b1.place(x=500,y=110) 998 | 999 | labelt2 = tk.Label(self, 1000 | text = "查询专业的结果:", 1001 | font = ("楷体",20), 1002 | fg = "red" 1003 | ) 1004 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1005 | labelt2.place(x = 10,y = 200) 1006 | 1007 | scrolly = Scrollbar(self) 1008 | scrolly.pack(side=RIGHT, fill=Y) 1009 | 1010 | l = tk.Listbox(self, width=70, height=17, exportselection=False, yscrollcommand=scrolly.set) 1011 | l.pack() 1012 | l.place(x=10, y=260) 1013 | 1014 | 1015 | tree = ttk.Treeview(l) # 表格 1016 | tree["columns"] = ("姓名", "年龄", "身高") 1017 | tree.column("姓名", width=100) # 表示列,不显示 1018 | tree.column("年龄", width=100) 1019 | tree.column("身高", width=100) 1020 | tree.heading("姓名", text="姓名-name") # 显示表头 1021 | tree.heading("年龄", text="年龄-age") 1022 | tree.heading("身高", text="身高-tall") 1023 | tree.insert("", 0, text="line1", values=("1", "2", "3")) # 插入数据, 1024 | tree.insert("", 1, text="line1", values=("1", "2", "3")) 1025 | tree.insert("", 2, text="line1", values=("1", "2", "3")) 1026 | tree.insert("", 3, text="line1", values=("1", "2", "3")) 1027 | tree.pack() 1028 | 1029 | #工资查询 1030 | class PageSix(tk.Frame): 1031 | def __init__(self, parent, root): 1032 | super().__init__(parent) 1033 | labeltxt = tk.Label(self,text = "工资查询",font = ("楷体",40),) 1034 | labeltxt.pack() 1035 | labeltxt.place(x = 200,y = 10) 1036 | 1037 | f = Figure(figsize=(5, 4), dpi=100) 1038 | f_plot = f.add_subplot(111) 1039 | 1040 | canvas = FigureCanvasTkAgg(f, self) 1041 | # canvas.get_tk_widget().pack(anchor = E ,expand=1) 1042 | canvas.get_tk_widget().place(x =0,y =200) 1043 | 1044 | def other_picture_alg(): # 数据相关的算法应该与plot分离开 1045 | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 1046 | y = [3, 6, 9, 12, 15, 18, 15, 12, 15, 18] 1047 | return x, y 1048 | 1049 | def draw_picture(): 1050 | f_plot.clear() 1051 | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # 关于数据的部分可以提取出来 1052 | y = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30] 1053 | print(x) 1054 | f_plot.plot(x, y) 1055 | canvas.draw() 1056 | 1057 | def draw_picture2(): 1058 | f_plot.clear() 1059 | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # 关于数据的部分可以提取出来 1060 | y = [2, 4, 6, 8, 10, 8, 6, 4, 2, 0] 1061 | f_plot.plot(x, y) 1062 | canvas.draw() 1063 | 1064 | def draw_picture3(): 1065 | f_plot.clear() 1066 | x, y = other_picture_alg() # 使用由算法生成的数据,可以避免重复的运算过程 1067 | f_plot.plot(x, y) 1068 | canvas.draw() 1069 | 1070 | Button(self, text='pic', command=draw_picture).place(x =500,y =250) 1071 | Button(self, text='pic2', command=draw_picture2).place(x =500,y =350) 1072 | Button(self, text='pic3', command=draw_picture3).place(x =500,y =450) 1073 | 1074 | 1075 | 1076 | 1077 | labelt1 = tk.Label(self,text = "请输入所要查询的工号:",font = ("楷体",20)) 1078 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1079 | labelt1.place(x = 100,y = 100) 1080 | 1081 | var1 = StringVar() 1082 | e1 = Entry(self,textvariable = var1,) 1083 | e1.pack() 1084 | e1.place(x = 170,y = 140) 1085 | 1086 | def show1(): 1087 | # basedata = {'host': '103.248.223.58', 'port': 3306, 'user': 'root', 'passwd': '123', 'db': 'test', 1088 | # 'charset': 'utf8'} 1089 | basedata = { 1090 | 'host': 'localhost', 1091 | 'port': 3306, 1092 | 'user': 'root', 1093 | 'passwd': '000', 1094 | 'db': 'test', 1095 | 'charset': 'utf8' 1096 | } 1097 | 1098 | # 打开数据库连接 1099 | conn = pymysql.connect(**basedata) 1100 | 1101 | try: 1102 | # 获取一个光标 1103 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 1104 | cursor = conn.cursor() # 返回字典数据类型 1105 | # 定义将要执行的sql语句 1106 | # sql = 'select name,sex from member where id=%s;'%e1.get() 1107 | sql = 'select * from salary where id=%s;' % e1.get() 1108 | # 拼接并执行sql语句 1109 | cursor.execute(sql) 1110 | 1111 | # 取到查询结果 1112 | ret1 = cursor.fetchone() # 取一条 1113 | # ret1 = cursor.fetchall() 1114 | 1115 | cursor.close() 1116 | conn.close() 1117 | 1118 | # print(ret1) 1119 | # print(e1.get()) 1120 | l.insert(END, "查询成功") 1121 | l.insert(END, ret1) 1122 | 1123 | except: 1124 | print("下载失败") 1125 | # 发生错误时回滚 1126 | conn.rollback() 1127 | 1128 | def download(): 1129 | # basedata = {'host': '103.248.223.58', 'port': 3306, 'user': 'root', 'passwd': '123', 'db': 'test', 1130 | # 'charset': 'utf8'} 1131 | basedata = { 1132 | 'host': 'localhost', 1133 | 'port': 3306, 1134 | 'user': 'root', 1135 | 'passwd': '000', 1136 | 'db': 'test', 1137 | 'charset': 'utf8' 1138 | } 1139 | 1140 | # 打开数据库连接 1141 | conn = pymysql.connect(**basedata) 1142 | 1143 | try: 1144 | # 获取一个光标 1145 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 1146 | cursor = conn.cursor() # 返回字典数据类型 1147 | # 定义将要执行的sql语句 1148 | # sql = 'select name,sex from member where id=%s;'%e1.get() 1149 | sql = 'select * from salary where id=%s;' % e1.get() 1150 | # 拼接并执行sql语句 1151 | cursor.execute(sql) 1152 | 1153 | # 取到查询结果 1154 | ret1 = cursor.fetchone() # 取一条 1155 | # ret1 = cursor.fetchall() 1156 | 1157 | cursor.close() 1158 | conn.close() 1159 | 1160 | print("已下载") 1161 | # l.insert(END, "已下载") 1162 | 1163 | # 新建一个excel文件,起名为expense01.xlsx 1164 | workbook = xlsxwriter.Workbook(ret1[1]+"当月薪水情况.xlsx") 1165 | # 添加一个Sheet页,不添写名字,默认为Sheet1 1166 | worksheet = workbook.add_worksheet() 1167 | 1168 | # 准备数据 1169 | headings = ["ID", "Name", "base", "assess", "check", "insurance", "total"] 1170 | data = [[ret1[0],ret1[1],ret1[4],ret1[5], ret1[6],ret1[7], ret1[8]]] 1171 | # print(data) 1172 | 1173 | head_style = workbook.add_format({"bold": True, "bg_color": "yellow", "align": "center", "font": 13}) 1174 | # 写数据 1175 | worksheet.write_row("A1", headings, head_style) 1176 | for i in range(0, len(data)): 1177 | worksheet.write_row("A2", data[i]) 1178 | 1179 | # 添加柱状图 1180 | chart1 = workbook.add_chart({"type": "column"}) 1181 | chart1.add_series({ 1182 | "name": "", 1183 | "categories": "=Sheet1!$C$1:$G$1", 1184 | "values": "=Sheet1!$C$2:$F$2" 1185 | }) 1186 | 1187 | # 添加柱状图标题 1188 | chart1.set_title({"name": "每月薪水柱状图"}) 1189 | # Y轴名称 1190 | chart1.set_y_axis({"name": "金额/元"}) 1191 | # X轴名称 1192 | chart1.set_x_axis({"name": "薪水组成"}) 1193 | # 图表样式 1194 | chart1.set_style(11) 1195 | 1196 | # 添加饼图 1197 | chart2 = workbook.add_chart({"type": "pie"}) 1198 | chart2.add_series({ 1199 | # "name":"饼形图", 1200 | # "categories": "=Sheet1!$A$2:$A$4", 1201 | # "values": "=Sheet1!$B$2:$B$4", 1202 | "name": "饼形图", 1203 | "categories": "=Sheet1!$C$1:$G$1", 1204 | "values": "=Sheet1!$C$2:$F$2", 1205 | 1206 | # 定义各饼块的颜色 1207 | "points": [ 1208 | {"fill": {"color": "red"}}, 1209 | {"fill": {"color": "blue"}}, 1210 | {"fill": {"color": "yellow"}}, 1211 | {"fill": {"color": "green"}}, 1212 | # {"fill": {"color": "orange"}}, 1213 | # {"fill": {"color": "purple"}} 1214 | ], 1215 | 'data_labels': {'value': True} 1216 | }) 1217 | chart2.set_title({"name": "每月薪水组成"}) 1218 | chart2.set_style(3) 1219 | 1220 | # 插入图表 1221 | worksheet.insert_chart("B7", chart1) 1222 | worksheet.insert_chart("J2", chart2) 1223 | 1224 | # 关闭EXCEL文件 1225 | workbook.close() 1226 | 1227 | except: 1228 | print("下载失败") 1229 | # 发生错误时回滚 1230 | conn.rollback() 1231 | 1232 | 1233 | def history(): 1234 | # basedata = {'host': '103.248.223.58', 'port': 3306, 'user': 'root', 'passwd': '123', 'db': 'test', 1235 | # 'charset': 'utf8'} 1236 | basedata = { 1237 | 'host': 'localhost', 1238 | 'port': 3306, 1239 | 'user': 'root', 1240 | 'passwd': '000', 1241 | 'db': 'test', 1242 | 'charset': 'utf8' 1243 | } 1244 | 1245 | # 打开数据库连接 1246 | conn = pymysql.connect(**basedata) 1247 | 1248 | try: 1249 | # 获取一个光标 1250 | # cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 1251 | cursor = conn.cursor() # 返回字典数据类型 1252 | # 定义将要执行的sql语句 1253 | # sql = 'select name,sex from member where id=%s;'%e1.get() 1254 | sql = 'select * from history where id=%s;' % e1.get() 1255 | # 拼接并执行sql语句 1256 | cursor.execute(sql) 1257 | 1258 | # 取到查询结果 1259 | ret1 = cursor.fetchone() # 取一条 1260 | # ret1 = cursor.fetchall() 1261 | ret2 = cursor.description # 获取表字段名 1262 | 1263 | cursor.close() 1264 | conn.close() 1265 | 1266 | print("已查询") 1267 | l.insert(END, "已查询") 1268 | # print(ret2) 1269 | # print("表头:", ",".join([item[0] for item in ret2])) 1270 | # l.insert(END, ",".join([item[0] for item in ret2])) 1271 | l.insert(END, ret1) 1272 | # print("数据:", ",".join([item[0] for item in ret1])) 1273 | 1274 | # 新建一个excel文件,起名为expense01.xlsx 1275 | workbook = xlsxwriter.Workbook(ret1[1]+"每月薪水情况.xlsx") 1276 | # 添加一个Sheet页,不添写名字,默认为Sheet1 1277 | worksheet = workbook.add_worksheet() 1278 | 1279 | # 准备数据 1280 | headings = [item[0] for item in ret2] 1281 | data = [[ret1[0],ret1[1],ret1[2],ret1[3],ret1[4],ret1[5], ret1[6],ret1[7], ret1[8],ret1[9], ret1[10],ret1[11], ret1[12]]] 1282 | 1283 | 1284 | head_style = workbook.add_format({"bold": True, "bg_color": "yellow", "align": "center", "font": 13}) 1285 | # 写数据 1286 | worksheet.write_row("A1", headings, head_style) 1287 | for i in range(0, len(data)): 1288 | worksheet.write_row("A2", data[i]) 1289 | 1290 | # 添加柱状图 1291 | chart1 = workbook.add_chart({"type": "column"}) 1292 | chart1.add_series({ 1293 | "name": "", 1294 | "categories": "=Sheet1!$C$1:$N$1", 1295 | "values": "=Sheet1!$C$2:$N$2" 1296 | }) 1297 | 1298 | # 添加柱状图标题 1299 | chart1.set_title({"name": "各月薪水柱状图"}) 1300 | # Y轴名称 1301 | chart1.set_y_axis({"name": "金额/元"}) 1302 | # X轴名称 1303 | chart1.set_x_axis({"name": "薪水组成"}) 1304 | # 图表样式 1305 | chart1.set_style(11) 1306 | 1307 | # 添加柱状图 1308 | chart2 = workbook.add_chart({"type": "line"}) 1309 | chart2.add_series({ 1310 | "name": "", 1311 | "categories": "=Sheet1!$C$1:$N$1", 1312 | "values": "=Sheet1!$C$2:$N$2", 1313 | 'line': {'color': 'red'} 1314 | }) 1315 | 1316 | # 添加柱状图标题 1317 | chart2.set_title({"name": "各月薪水折线图"}) 1318 | # Y轴名称 1319 | chart2.set_y_axis({"name": "金额/元"}) 1320 | # X轴名称 1321 | chart2.set_x_axis({"name": "薪水组成"}) 1322 | # 图表样式 1323 | chart2.set_style(11) 1324 | 1325 | # 插入图表 1326 | worksheet.insert_chart("B7", chart1) 1327 | worksheet.insert_chart("J2", chart2) 1328 | 1329 | # 关闭EXCEL文件 1330 | workbook.close() 1331 | 1332 | except: 1333 | print("下载失败") 1334 | # 发生错误时回滚 1335 | conn.rollback() 1336 | 1337 | 1338 | #label设计 1339 | b1=tk.Button(self,text='查询',width = 8,height = 2,activeforeground = "red",command=show1) 1340 | b1.pack(padx = 5, pady = 10) 1341 | b1.place(x=350,y=140) 1342 | 1343 | b2=tk.Button(self,text='下载',width = 8,height = 2,activeforeground = "red",command=download) 1344 | b2.pack(padx = 5, pady = 20) 1345 | b2.place(x=450,y=140) 1346 | # 1347 | # b3=tk.Button(self,text='查看历史',width = 8,height = 2,activeforeground = "red",command=history) 1348 | # b3.pack(padx = 5, pady = 20) 1349 | # b3.place(x=550,y=140) 1350 | 1351 | # labelt2 = tk.Label(self,text = "查询工资的结果:",font = ("楷体",20),fg = "red") 1352 | # labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1353 | # labelt2.place(x = 10,y = 200) 1354 | # 1355 | # scrolly = Scrollbar(self) 1356 | # scrolly.pack(side=RIGHT, fill=Y) 1357 | # 1358 | # l=tk.Listbox(self,width = 70,height = 17,exportselection = False,yscrollcommand=scrolly.set) 1359 | # l.pack() 1360 | # l.place(x=10,y = 260) 1361 | 1362 | 1363 | #签到情况查询、 1364 | class PageSeven(tk.Frame): 1365 | def __init__(self, parent, root): 1366 | super().__init__(parent) 1367 | labeltxt = tk.Label(self, 1368 | text = "签到情况查询", 1369 | font = ("楷体",40), 1370 | ) 1371 | labeltxt.pack() 1372 | labeltxt.place(x = 200,y = 10) 1373 | 1374 | labelt1 = tk.Label(self, 1375 | text = "请输入所要查询的人员:", 1376 | font = ("楷体",20) 1377 | ) 1378 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1379 | labelt1.place(x = 100,y = 100) 1380 | var1 = StringVar() 1381 | 1382 | e1 = Entry(self, 1383 | textvariable = var1, 1384 | ) 1385 | e1.pack() 1386 | e1.place(x = 170,y = 140) 1387 | 1388 | 1389 | def clock_display(): 1390 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1391 | cursor = db.cursor() 1392 | sql = "select * from history where history.id=%s" % (e1.get()) 1393 | try: 1394 | cursor.execute(sql) 1395 | db.commit() 1396 | except Exception as e: 1397 | print('error:' + str(e)) 1398 | db.rollback() 1399 | cursor.close() 1400 | db.close() 1401 | # 数据处理 1402 | result = cursor.fetchone() 1403 | name = result[1] 1404 | clock_record = result[-1] 1405 | clock_list = clock_record.split(";") 1406 | y = clock_list[:-1] 1407 | print(type(y)) 1408 | lenth = len(clock_list) 1409 | print(lenth) 1410 | x = range(1, lenth) 1411 | a, b, c, d = 0, 0, 0, 0 1412 | for i in y: 1413 | if i == "未迟到 未早退": 1414 | a += 1 1415 | elif i == "未迟到 早退": 1416 | b += 1 1417 | elif i == "迟到 未早退": 1418 | c += 1 1419 | elif i == "迟到 早退": 1420 | d += 1 1421 | x1 = ["未迟到 未早退", "未迟到 早退", "迟到 未早退", "迟到 早退"] 1422 | y1 = [a, b, c, d] 1423 | 1424 | plt.yticks(range(32)) # 设置y1刻度 1425 | plt.bar(x1, y1, width=0.5) 1426 | plt.title(name + "本月的考勤情况") 1427 | plt.xlabel("考勤情况") 1428 | plt.ylabel("天数") 1429 | plt.show() 1430 | print("ok") 1431 | 1432 | b1 = tk.Button(self, text="查询", width=8, font=("楷体", 20), command=clock_display) 1433 | b1.pack(padx=2, pady=20) 1434 | b1.place(x=500, y=110) 1435 | 1436 | 1437 | labelt2 = tk.Label(self, 1438 | text = "查询结果:", 1439 | font = ("楷体",20), 1440 | fg = "red" 1441 | ) 1442 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1443 | labelt2.place(x = 10,y = 200) 1444 | 1445 | scrolly = Scrollbar(self) 1446 | scrolly.pack(side=RIGHT, fill=Y) 1447 | 1448 | 1449 | l=tk.Listbox(self,width = 70,height = 17,exportselection = False,yscrollcommand=scrolly.set) 1450 | l.pack() 1451 | l.place(x=10,y = 260) 1452 | 1453 | 1454 | # 调动员工信息 1455 | class PageEight(tk.Frame): 1456 | def __init__(self, parent, root): 1457 | super().__init__(parent) 1458 | 1459 | label = tk.Label(self, text="人员调动", font=("楷体", 40), ) 1460 | label.pack() 1461 | label.place(x=200, y=10) 1462 | 1463 | labelt1 = tk.Label(self, 1464 | text="部门调动人员工号:", 1465 | font=("楷体", 20) 1466 | ) 1467 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1468 | labelt1.place(x=100, y=100) 1469 | 1470 | labelt1 = tk.Label(self, 1471 | text="调入部门:", 1472 | font=("楷体", 20) 1473 | ) 1474 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1475 | labelt1.place(x=50, y=200) 1476 | 1477 | labelt2 = tk.Label(self, 1478 | text="调入等级:", 1479 | font=("楷体", 20) 1480 | ) 1481 | labelt2.pack(padx=5, pady=10, side=tk.LEFT) 1482 | labelt2.place(x=50, y=290) 1483 | 1484 | 1485 | var1 = StringVar() 1486 | e1 = Entry(self, 1487 | textvariable=var1, 1488 | ) 1489 | e1.pack() 1490 | e1.place(x=370, y=100) 1491 | 1492 | var2 = StringVar() 1493 | e2 = Entry(self, 1494 | textvariable=var2, 1495 | ) 1496 | e2.pack() 1497 | e2.place(x=200, y=210) 1498 | 1499 | var3 = StringVar() 1500 | e3 = Entry(self, 1501 | textvariable=var3, 1502 | ) 1503 | e3.pack() 1504 | e3.place(x=200, y=300) 1505 | 1506 | # 建立对象 1507 | def tran(): 1508 | wangwu = Trans(e1.get()) 1509 | wangwu.department_trans(e1.get(), e2.get()) 1510 | 1511 | def d_trans(): 1512 | wangwu = Trans(e1.get()) 1513 | wangwu.rank_trans(e1.get(), e3.get()) 1514 | 1515 | 1516 | b1=tk.Button(self, text="部门调动", width=8, font=("楷体",20), command=tran) 1517 | b1.pack(padx=2, pady=20) 1518 | b1.place(x=400, y=200) 1519 | 1520 | b1 = tk.Button(self, text="等级调动", width=8, font=("楷体", 20), command=d_trans) 1521 | b1.pack(padx=2, pady=20) 1522 | b1.place(x=400, y=290) 1523 | 1524 | b2=tk.Button(self, text="返回首页", width=8, font=("楷体",20), command=lambda: root.show_frame(PageTwo)) 1525 | b2.pack(padx=5, pady=40) 1526 | b2.place(x=500, y=410) 1527 | 1528 | # 创建部门调动与级别调动类 1529 | class Trans(): 1530 | def __init__(self, id): 1531 | self.id = id 1532 | def department_trans(self, id, cur_department): 1533 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1534 | cursor = db.cursor() 1535 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1536 | sql_0 = "insert into trans set trans_date='%s'"%(now) 1537 | sql_1 = "update trans set id=%s where trans_date='%s'"%(id,now) 1538 | sql_2 = """ update trans, member 1539 | set trans.name=member.name, trans.entry_time=member.entry_time, 1540 | trans.ori_department=member.department, trans.ori_rank=member.rank, 1541 | trans.cur_department=%s, trans.cur_rank=member.rank 1542 | where trans.id=%s and member.id=%s and trans.trans_date='%s' 1543 | """%(cur_department, id, id, now) 1544 | sql_3 = """ update member, clock, salary 1545 | set member.department=%s, clock.department=%s, salary.department=%s 1546 | where member.id=%s and clock.id=%s and salary.id=%s 1547 | """%(cur_department, cur_department, cur_department, id, id, id) 1548 | try: 1549 | cursor.execute(sql_0) 1550 | cursor.execute(sql_1) 1551 | cursor.execute(sql_2) 1552 | cursor.execute(sql_3) 1553 | db.commit() 1554 | tk.messagebox.showinfo(title='ok', message='部门调动完成!') 1555 | print('部门调动完成') 1556 | except Exception as e: 1557 | tk.messagebox.showinfo(title='no', message='error') 1558 | print('error:'+str(e)) 1559 | db.rollback() 1560 | cursor.close() 1561 | db.close() 1562 | def rank_trans(self, id, cur_rank): 1563 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1564 | cursor = db.cursor() 1565 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1566 | sql_4 = "insert into trans set trans_date='%s'"%(now) 1567 | sql_5 = "update trans set id = %s where trans_date='%s'"%(id,now) 1568 | sql_6 = """ update trans, member 1569 | set trans.name = member.name, trans.entry_time = member.entry_time, 1570 | trans.ori_department = member.department, trans.ori_rank = member.rank, 1571 | trans.cur_department = member.department, trans.cur_rank = %s 1572 | where trans.id = %s and member.id = %s and trans.trans_date='%s' 1573 | """%(cur_rank, id, id, now) 1574 | sql_7 = """ update member, clock, salary 1575 | set member.rank = %s, clock.rank = %s, salary.rank = %s 1576 | where member.id = %s and clock.id = %s and salary.id = %s 1577 | """%(cur_rank, cur_rank, cur_rank, id, id, id) 1578 | try: 1579 | cursor.execute(sql_4) 1580 | cursor.execute(sql_5) 1581 | cursor.execute(sql_6) 1582 | cursor.execute(sql_7) 1583 | db.commit() 1584 | tk.messagebox.showinfo(title='ok', message='等级调动完成!') 1585 | print('等级调动完成') 1586 | except Exception as e: 1587 | tk.messagebox.showinfo(title='no', message='error') 1588 | print('error:'+str(e)) 1589 | db.rollback() 1590 | cursor.close() 1591 | db.close() 1592 | 1593 | #考勤信息 1594 | class PageNine(tk.Frame): 1595 | def __init__(self, parent, root): 1596 | super().__init__(parent) 1597 | 1598 | labeltxt = tk.Label(self, 1599 | text="考勤", 1600 | font=("楷体", 40), 1601 | ) 1602 | labeltxt.pack() 1603 | labeltxt.place(x=200, y=10) 1604 | 1605 | labelt1 = tk.Label(self, 1606 | text="考勤id:", 1607 | font=("楷体", 20) 1608 | ) 1609 | labelt1.pack(padx=5, pady=10, side=tk.LEFT) 1610 | labelt1.place(x=100, y=100) 1611 | 1612 | var1 = StringVar() 1613 | e1 = Entry(self, 1614 | textvariable=var1, 1615 | ) 1616 | e1.pack() 1617 | e1.place(x=170, y=140) 1618 | 1619 | # 建立对象 1620 | def qiandao(): 1621 | wangwu = Clock(e1.get()) 1622 | wangwu.clock_in(e1.get()) 1623 | # wangwu.clock_out(e1.get()) 1624 | 1625 | def qiantui(): 1626 | wangwu = Clock(e1.get()) 1627 | # wangwu.clock_in(e1.get()) 1628 | wangwu.clock_out(e1.get()) 1629 | 1630 | b1 = tk.Button(self, text='签到', width=15, height=3, activeforeground="red", command=qiandao) 1631 | b1.pack(padx=5, pady=10) 1632 | b1.place(x=500, y=110) 1633 | 1634 | b2 = tk.Button(self, text='签退', width=15, height=3, activeforeground="red", command=qiantui) 1635 | b2.pack(padx=5, pady=10) 1636 | b2.place(x=500, y=210) 1637 | 1638 | # 创建考勤类 1639 | class Clock(): 1640 | def __init__(self, id): 1641 | self.id = id 1642 | def clock_in(self, id): 1643 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1644 | cursor = db.cursor() 1645 | # 考勤表中clock_in字段清零 1646 | try: 1647 | sql_0 = """ update clock, member 1648 | set clock_in='0000-00-00 00:00:00' 1649 | where clock.id=%s 1650 | """%(id) 1651 | cursor.execute(sql_0) 1652 | db.commit() 1653 | except Exception as e: 1654 | print('error:'+str(e)) 1655 | db.rollback() 1656 | # 签到 1657 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1658 | sql_1 = "update clock set clock_in='%s' where clock.id=%s"%(now, id) 1659 | if now[-8:]<='08:00:00': 1660 | sql_2 = "update history set clock_history=concat(clock_history,'未迟到 ') where history.id=%s"%(id) 1661 | try: 1662 | cursor.execute(sql_1) 1663 | cursor.execute(sql_2) 1664 | db.commit() 1665 | print("签到完成") 1666 | except Exception as e: 1667 | print('error:'+str(e)) 1668 | db.rollback() 1669 | cursor.close() 1670 | db.close() 1671 | else: 1672 | sql_3 = "update history set clock_history=concat(clock_history,'迟到 ') where history.id=%s"%(id) 1673 | try: 1674 | cursor.execute(sql_1) 1675 | cursor.execute(sql_3) 1676 | db.commit() 1677 | print('签到完成,已迟到') 1678 | except Exception as e: 1679 | print('error:'+str(e)) 1680 | db.rollback() 1681 | cursor.close() 1682 | db.close() 1683 | def clock_out(self, id): 1684 | db = pymysql.connect("103.248.223.58", "root", "h1613401", "test") 1685 | cursor = db.cursor() 1686 | # 考勤表中clock_out字段清零 1687 | try: 1688 | sql_0 = """ update clock, member 1689 | set clock_out='0000-00-00 00:00:00' 1690 | where clock.id=%s 1691 | """%(id) 1692 | cursor.execute(sql_0) 1693 | db.commit() 1694 | except Exception as e: 1695 | print('error:'+str(e)) 1696 | db.rollback() 1697 | # 签到 1698 | now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 1699 | sql_1 = "update clock set clock_out='%s' where clock.id=%s"%(now, id) 1700 | if now[-8:]>='18:00:00': 1701 | # sql_1 = "update history set clock_history = left(clock_history,LENGTH(clock_history) - 1) where history.id=%s"%(id) 1702 | sql_2 = "update history set clock_history=concat(clock_history,'未早退;') where history.id=%s"%(id) 1703 | try: 1704 | cursor.execute(sql_1) 1705 | cursor.execute(sql_2) 1706 | db.commit() 1707 | print("签退完成") 1708 | except Exception as e: 1709 | print('error:'+str(e)) 1710 | db.rollback() 1711 | cursor.close() 1712 | db.close() 1713 | else: 1714 | # sql_3 = "update history set clock_history = left(clock_history,LENGTH(clock_history) - 1) where history.id=%s"%(id) 1715 | sql_4 = "update history set clock_history=concat(clock_history,'早退;') where history.id=%s"%(id) 1716 | try: 1717 | cursor.execute(sql_3) 1718 | cursor.execute(sql_4) 1719 | db.commit() 1720 | print('签退完成,已早退') 1721 | except Exception as e: 1722 | print('error:'+str(e)) 1723 | db.rollback() 1724 | cursor.close() 1725 | db.close() 1726 | 1727 | if __name__ == '__main__': 1728 | 1729 | 1730 | StartPage0() 1731 | 1732 | --------------------------------------------------------------------------------