职工管理系统
初接触Python所写,可能代码、功能实现存在很多问题~~可以运行可行
- 系统介绍:所设计的系统为职工管理系统,主要作用是存储某企业人员信息,主要信息包括员工号(独一无二)、姓名、年龄、性别、职位、学历、薪资,主要功能有查询、更新、删除、增添、排序。
- 主要界面展示:
- 主要代码展示:(仅有部分代码…树的构造过程未展示)
#查询
def inquiry():
cursor=conn.cursor()
tmpName=emname.get().strip()
tmpeno=emeno.get().strip()
tmpnum=emage.get().strip()
sql=''
if(len(tmpName)==0 and len(tmpeno)==0 and len(tmpnum)!=11):
sql="select * from employee"
elif(len(tmpeno)==0 and len(tmpnum)!=11):
sql="select * from employee where Ename like "+"'%"+tmpName+"%'"
elif(len(tmpName)==0 and len(tmpnum)!=11):
sql="select * from employee where Eno="+""+tmpeno+""
elif(len(tmpName)==0 and len(tmpeno)==0):
sql="select * from employee where Enum="+""+tmpnum+""
cursor.execute(sql)
list=cursor.fetchall()
def tree_view_sort_column(tv,col,reverse):
l=[(tv.set(k,col),k) for k in tv.get_children
l.sort(reverse=reverse)
for index,(val,k) in enumerate(l):
tv.move(k,'',index)
#print(k)
tv.heading(col,command=lambda:tree_view_sort_column(tv,col,not reverse)) f
or col in columns: tree_view.heading(col,text=col,command=lambda _col=col:tree_view_sort_column(tree_view,_col,False))
#增加
def getadd():
cursor=conn.cursor()
Eno=str(emeno.get())
Ename=str(emname.get())
Esex=str(emsex.get())
Eage=eval(emage.get())
Enum=str(emnum.get())
Pname=str(posname.get())
educated=str(Educate.get())
salary=eval(sassalary.get())
sql1="select * from employee "
cursor.execute(sql1)
list=cursor.fetchall()
#print(sql1)
conn.commit()
i=0
#查找是否有重复的编号
for row in list:
if Eno==row[0].strip():
i=1
break
else:
i=0
if i==1:
messagebox.showerror('警告',message="该员工号已存在,请重新录入!")
else:
try:
sql="insert into employee(Eno,Ename,Eage,Esex,Enum,Pname,educated,salary)\ values('%s','%s',%d,'%s','%s','%s','%s',%d)"%\ (Eno,Ename,Eage,Esex,Enum,Pname,educated,salary)
cursor.execute(sql)
#cursor.fetchall()
conn.commit()
messagebox.showinfo('提示',message="信息成功录入!") except:
messagebox.showerror('提示',message="信息录入失败")
#删除
def getdelete():
cursor=conn.cursor()
if(len(emeno.get())==0):
messagebox.showinfo("提示",message="未检测到相关信息,请重试!")
else:
try:
cursor.execute("delete from employee where Eno='%s'"%str(emeno.get()))
#cursor.fetchall()
conn.commit()
messagebox.showinfo("提示",message="删除成功!")
except:
messagebox.showerror("提示",message="删除失败!")
#排序
def order():
messagebox.showinfo("提示",message="单击列标题进行排序")
#更新
def getupdate():
cursor=conn.cursor()
Eno=str(emeno.get())
if(len(Eno)==0):
messagebox.showinfo("提示",message="请输入员工号再进行更新!")
else:
try:
sql="update employee set Ename='%s',Eage=%d,Esex='%s',Enum='%s',Pname='%s',salary=%d,educated='%s' where Eno='%s'"%\
(str(emname.get()),eval(emage.get()),str(emsex.get()),str(emnum.get()),str(posname.get()),eval(sassalary.get()),str(Educate.get()),Eno)
cursor.execute(sql)
conn.commit()
messagebox.showinfo("提示",message="修改成功!")
except:
messagebox.showerror("提示",message="修改失败!")
#清除
def clear():
E1.delete(0,"end")
E2.delete(0,"end")
E3.delete(0,"end")
E4.delete(0,"end")
E5.delete(0,"end")
E6.delete(0,"end")
E7.delete(0,"end")
E8.delete(0,"end")