[Python] 纯文本查看 复制代码
import tkinter as tk
import cx_Oracle as cx
def run1():
a = str(inp1.get())
b = str(inp2.get())
popup = tk.Toplevel()
popup.title("提示")
popup.geometry("230x80")
if a=='':
label = tk.Label(popup, text="身份证为空")
label.pack(pady=10)
elif b=='':
label = tk.Label(popup, text="税号为空")
label.pack(pady=10)
else:''
db = cx.connect('username/password@127.0.0.1:1521/prod')
cursor = db.cursor()
#sql = "update ACCOUT set yuliu='哈哈哈' where nsrsbh='"+b+"' and zjhm='"+a+"'"
sql1 = "delete from table_name_a where nsrsbh='" + b + "'"
sql2 = "delete from table_name_b where td_code='" + b + "'"
sql3 = "delete from table_name_c where td_code='" + b + "'"
sql4 = "delete from table_name_d where user_id='" + a + "'"
cursor.execute(sql1)
cursor.execute(sql2)
cursor.execute(sql3)
cursor.execute(sql4)
db.commit()
cursor.close()
db.close()
label = tk.Label(popup, text="已清除数据\n身份证号:" + a + "\n纳税号码:" + b,justify="center")
label.pack(pady=10)
inp1.delete(0, tk.END)
inp2.delete(0, tk.END)
def run2():
try:
db = cx.connect('username/password@127.0.0.1:1521/prod')
ver = str(db.version)
lb4 = tk.Label(root, text='连接成功,版本号:'+ver,fg="green")
lb4.place(relx=0.11, rely=0.87, relwidth=0.6, relheight=0.1)
except:
lb3 = tk.Label(root, text='连接失败,请检查环境!',fg="red")
lb3.place(relx=0.11, rely=0.87, relwidth=0.6, relheight=0.1)
finally:
# 关闭数据库
db.close()
root = tk.Tk()
#设置窗口属性
root.title("清除测试数据")
root.geometry("350x240")
lb = tk.Label(root, text='仅限测试环境使用!',fg="red",font=("Arial", 20),justify="center")
lb.place(relx=0, rely=0.12, relwidth=1.04, relheight=0.1)
lb1 = tk.Label(root, text='请输入身份证号')
lb1.place(relx=0, rely=0.3, relwidth=0.3, relheight=0.1)
inp1 = tk.Entry(root)
inp1.place(relx=0.3, rely=0.3, relwidth=0.6, relheight=0.1)
lb2 = tk.Label(root, text='输入纳税识别号')
lb2.place(relx=0, rely=0.5, relwidth=0.3, relheight=0.1)
inp2 = tk.Entry(root)
inp2.place(relx=0.3, rely=0.5, relwidth=0.6, relheight=0.1)
btn1 = tk.Button(root, text='清除数据', command=run1)
btn1.place(relx=0.5, rely=0.7, relwidth=0.3, relheight=0.15)
btn2 = tk.Button(root, text='测试连接', command=run2)
btn2.place(relx=0.12, rely=0.7, relwidth=0.3, relheight=0.15)
root.mainloop()