|
|
|
@ -0,0 +1,196 @@
|
|
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
|
import sqlite3
|
|
|
|
|
conn1 = sqlite3.connect('职工信息.db')
|
|
|
|
|
print ("数据库打开成功")
|
|
|
|
|
c = conn1.cursor()
|
|
|
|
|
# sql_text_1 = '''CREATE TABLE scores
|
|
|
|
|
# (姓名 TEXT,
|
|
|
|
|
# 性别 TEXT,
|
|
|
|
|
# 出生年月 DATE,
|
|
|
|
|
# 工作年月 DATE,
|
|
|
|
|
# 学历 TEXT,
|
|
|
|
|
# 职务 TEXT,
|
|
|
|
|
# 住所 TEXT,
|
|
|
|
|
# 电话 TEXT);'''
|
|
|
|
|
# c.execute(sql_text_1)
|
|
|
|
|
# print ("数据表创建成功")
|
|
|
|
|
def denglu():
|
|
|
|
|
print('--------------------------------')
|
|
|
|
|
print(' 欢迎来到职工管理系统! ')
|
|
|
|
|
print('--------------------------------')
|
|
|
|
|
print('请选择您要办理的事项:')
|
|
|
|
|
print('1.新增职工信息')
|
|
|
|
|
print('2.删除职工信息')
|
|
|
|
|
print('3.查询职工信息')
|
|
|
|
|
print('4.修改职工信息')
|
|
|
|
|
print('5.排序职工信息')
|
|
|
|
|
print('0:退出程序')
|
|
|
|
|
print('--------------------------------')
|
|
|
|
|
def select():
|
|
|
|
|
a=input('请输入序号:')
|
|
|
|
|
return a
|
|
|
|
|
global name,xingbie,birthdate,workdate,xueli,turn,address,phone
|
|
|
|
|
def add():
|
|
|
|
|
xinxi_list = []
|
|
|
|
|
while True:
|
|
|
|
|
name = input('请输入职工姓名:')
|
|
|
|
|
if not name:
|
|
|
|
|
break
|
|
|
|
|
try:
|
|
|
|
|
xingbie = input('请输入职工性别:')
|
|
|
|
|
if xingbie!='男' and xingbie!='女':
|
|
|
|
|
print('请正确输入!')
|
|
|
|
|
continue
|
|
|
|
|
birthdate = input('请输入职工出生年月(xxxx.xx.xx):')
|
|
|
|
|
workdate = input('请输入职工工作年月(xxxx.xx.xx):')
|
|
|
|
|
xueli=input('请输入职工学历:')
|
|
|
|
|
turn=input('请输入职工职务')
|
|
|
|
|
address=input('请输入职工住址')
|
|
|
|
|
phone=input('请输入职工电话:')
|
|
|
|
|
except:
|
|
|
|
|
print("输入无效,请重新输入")
|
|
|
|
|
xinxi={'name': name, 'xingbie': xingbie, 'birthdate': birthdate, 'workdate':workdate,'xueli':xueli, 'turn':turn, 'address':address, 'phone':phone}
|
|
|
|
|
xinxi_list .append(xinxi)
|
|
|
|
|
answer = input("是否继续添加y/n?")
|
|
|
|
|
if answer == 'y':
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
for i in xinxi_list:
|
|
|
|
|
c.execute("INSERT INTO scores (姓名,性别,出生年月,工作年月,学历,职务,住所,电话) VALUES(?,?,?,?,?,?,?,?)",(i['name'],i['xingbie'],i['birthdate'],i['workdate'],i['xueli'],i['turn'],i['address'],i['phone']))
|
|
|
|
|
print('添加成功!')
|
|
|
|
|
def delete():
|
|
|
|
|
while True:
|
|
|
|
|
xinxi_name = input("请输入删除职工的姓名:")
|
|
|
|
|
xinxi_n={'姓名':f'{xinxi_name}'}
|
|
|
|
|
cursor = c.execute("SELECT 姓名,性别,出生年月,工作年月,学历,职务,住所,电话 from scores")
|
|
|
|
|
T = False
|
|
|
|
|
jieguo = []
|
|
|
|
|
for row in cursor:
|
|
|
|
|
if row[0] == xinxi_name:
|
|
|
|
|
jieguo = row
|
|
|
|
|
T = True
|
|
|
|
|
break
|
|
|
|
|
if xinxi_name !='':
|
|
|
|
|
if T==True:
|
|
|
|
|
#c.execute("delete from scores where 姓名='456'")
|
|
|
|
|
c.execute('delete from scores where 姓名=?', (xinxi_name,))
|
|
|
|
|
else:
|
|
|
|
|
print('数据库中无此人!')
|
|
|
|
|
answer = input("是否继续删除?y/n")
|
|
|
|
|
if answer == 'y':
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
def find():
|
|
|
|
|
while True:
|
|
|
|
|
xinxi_name = input("请输入要查询职工的姓名:")
|
|
|
|
|
cursor = c.execute("SELECT 姓名,性别,出生年月,工作年月,学历,职务,住所,电话 from scores")
|
|
|
|
|
T=False
|
|
|
|
|
jieguo=[]
|
|
|
|
|
for row in cursor:
|
|
|
|
|
if row[0]==xinxi_name:
|
|
|
|
|
jieguo=row
|
|
|
|
|
T=True
|
|
|
|
|
break
|
|
|
|
|
if xinxi_name != '':
|
|
|
|
|
if T==True:
|
|
|
|
|
print('姓名:',jieguo[0])
|
|
|
|
|
print('性别:',jieguo[1])
|
|
|
|
|
print('出生年月:',jieguo[2])
|
|
|
|
|
print('工作年月:',jieguo[3])
|
|
|
|
|
print('学历:',jieguo[4])
|
|
|
|
|
print('职务:',jieguo[5])
|
|
|
|
|
print('住所:',jieguo[6])
|
|
|
|
|
print('电话:',jieguo[7])
|
|
|
|
|
else:
|
|
|
|
|
print('数据库中无此人!')
|
|
|
|
|
answer = input("是否继续查询 ?y/n")
|
|
|
|
|
if answer == 'y':
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
def modify():
|
|
|
|
|
while True:
|
|
|
|
|
xinxi_name = input("请输入要修改职工的姓名:")
|
|
|
|
|
xinxi_n = {'姓名': f'{xinxi_name}'}
|
|
|
|
|
cursor = c.execute("SELECT 姓名,性别,出生年月,工作年月,学历,职务,住所,电话 from scores")
|
|
|
|
|
T = False
|
|
|
|
|
jieguo = []
|
|
|
|
|
for row in cursor:
|
|
|
|
|
if row[0] == xinxi_name:
|
|
|
|
|
jieguo = row
|
|
|
|
|
T = True
|
|
|
|
|
break
|
|
|
|
|
if xinxi_name != '':
|
|
|
|
|
if T==True:
|
|
|
|
|
print(jieguo)
|
|
|
|
|
liebiao=[]
|
|
|
|
|
for i in jieguo:
|
|
|
|
|
liebiao.append(i)
|
|
|
|
|
print(liebiao)
|
|
|
|
|
liebiao[1] = input('请输入职工性别:')
|
|
|
|
|
liebiao[2] = input('请输入职工出生年月(xxxx.xx.xx):')
|
|
|
|
|
liebiao[3] = input('请输入职工工作年月(xxxx.xx.xx):')
|
|
|
|
|
liebiao[4] = input('请输入职工学历:')
|
|
|
|
|
liebiao[5] = input('请输入职工职务')
|
|
|
|
|
liebiao[6] = input('请输入职工住址')
|
|
|
|
|
liebiao[7] = input('请输入职工电话:')
|
|
|
|
|
c.execute("UPDATE scores set 性别=?,出生年月=?,工作年月=?,学历=?,职务=?,住所=?,电话=? where 姓名=?",(liebiao[1],liebiao[2],liebiao[3],liebiao[4],liebiao[5],liebiao[6],liebiao[7],liebiao[0]))
|
|
|
|
|
else:
|
|
|
|
|
print('数据库中无此人!')
|
|
|
|
|
answer = input("是否继续修改 ?y/n")
|
|
|
|
|
if answer == 'y':
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
def sortt():#按姓名排序
|
|
|
|
|
print('----------------------------------------')
|
|
|
|
|
print(' 1.姓名 ')
|
|
|
|
|
print(' 2.出生年月 ')
|
|
|
|
|
print(' 3.工作年月 ')
|
|
|
|
|
print('----------------------------------------')
|
|
|
|
|
while True:
|
|
|
|
|
choice=input('选择那种排序方法?')
|
|
|
|
|
if choice=='1':
|
|
|
|
|
c.execute("SELECT * FROM scores ORDER BY 姓名 ASC")
|
|
|
|
|
elif choice=='2':
|
|
|
|
|
c.execute("SELECT * FROM scores ORDER BY 出生年月 ASC")
|
|
|
|
|
elif choice=='3':
|
|
|
|
|
c.execute("SELECT * FROM scores ORDER BY 工作年月 ASC")
|
|
|
|
|
print(c.fetchall())
|
|
|
|
|
answer = input("是否继续排序 ?y/n")
|
|
|
|
|
if answer == 'y':
|
|
|
|
|
continue
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
def main():
|
|
|
|
|
while True:
|
|
|
|
|
denglu()
|
|
|
|
|
choice = int(input('请选择功能'))
|
|
|
|
|
if choice in [0, 1, 2, 3, 4, 5, 6, 7]:
|
|
|
|
|
if choice == 0:
|
|
|
|
|
answer = input('您确定退出系统吗?y/n')
|
|
|
|
|
if answer == 'y' or answer == 'Y':
|
|
|
|
|
print("欢迎您的使用!!")
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
continue
|
|
|
|
|
elif choice == 1:
|
|
|
|
|
add()
|
|
|
|
|
conn1.commit()
|
|
|
|
|
elif choice == 2:
|
|
|
|
|
delete()
|
|
|
|
|
conn1.commit()
|
|
|
|
|
elif choice == 3:
|
|
|
|
|
find()
|
|
|
|
|
conn1.commit()
|
|
|
|
|
elif choice == 4:
|
|
|
|
|
modify()
|
|
|
|
|
conn1.commit()
|
|
|
|
|
elif choice == 5:
|
|
|
|
|
sortt()
|
|
|
|
|
conn1.commit()
|
|
|
|
|
input()
|
|
|
|
|
'''姓名、性别、出生年月、工作年月、学历、职务、住址、电话'''
|
|
|
|
|
main()
|