Skip to content

Commit a45e203

Browse files
authored
Add files via upload
0 parents  commit a45e203

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

autofind.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'''
2+
Author: 木白广木林
3+
Date: 2024-05-18 09:02:09
4+
LastEditTime: 2024-05-18 09:04:07
5+
LastEditors: 木白广木林
6+
Description: None
7+
FilePath: \Desktop\db-SQLserver-autofind.py
8+
检查自己的代码是非常愚蠢的行为,这是对本身实力的不信任。
9+
'''
10+
import tkinter as tk
11+
12+
def on_key_release(event):
13+
# 获取文本框中的输入内容
14+
input_text = entry.get()
15+
# 检查输入长度是否达到10个字符
16+
if len(input_text) >= 10:
17+
print("输入长度达到或超过10个字符,清空输入框。")
18+
# 清空输入框
19+
entry.delete(0, tk.END)
20+
21+
# 创建主窗口
22+
root = tk.Tk()
23+
root.title("清空输入框示例")
24+
25+
# 创建一个文本框,允许用户输入文本
26+
entry = tk.Entry(root, width=50)
27+
entry.pack(pady=20)
28+
29+
# 绑定键盘释放事件到on_key_release函数
30+
entry.bind('<KeyRelease>', on_key_release)
31+
32+
# 启动事件循环
33+
root.mainloop()

db-SQLserver-autofind.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2+
'''
3+
Author: 木白广木林
4+
Date: 2024-05-18 08:19:40
5+
LastEditTime: 2024-05-18 09:32:30
6+
LastEditors: 木白广木林
7+
Description: None
8+
FilePath: \Desktop\db-SQLserver copy.py
9+
检查自己的代码是非常愚蠢的行为,这是对本身实力的不信任。
10+
'''
11+
import sys
12+
import pyodbc
13+
import tkinter as tk
14+
from tkinter import messagebox
15+
16+
# 连接SQL Server数据库
17+
# conn = pyodbc.connect('DRIVER={SQL Server};SERVER=Your_Server_Name;DATABASE=Your_Database_Name;UID=Your_Username;PWD=Your_Password')
18+
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=DESKTOP-FCCVVU8;DATABASE=db;UID=sa;PWD=root')
19+
cursor = conn.cursor()
20+
21+
# def showMessage(message, type='info', timeout=2500):
22+
# import tkinter as tk
23+
# from tkinter import messagebox
24+
25+
# root = tk.Tk()
26+
# root.withdraw()
27+
# try:
28+
# root.after(timeout, root.destroy)
29+
# if type == 'info':
30+
# messagebox.showinfo('Info', message, master=root)
31+
# elif type == 'warning':
32+
# messagebox.showwarning('Warning', message, master=root)
33+
# elif type == 'error':
34+
# messagebox.showerror('Error', message, master=root)
35+
# except:
36+
# pass
37+
38+
# showMessage("Hello, world", timeout=1000)
39+
40+
# 查询数据库中是否已存在序列号
41+
def check_duplicate(serial):
42+
cursor.execute("SELECT * FROM number WHERE numbers = ?", (serial,))
43+
if cursor.fetchall():
44+
return True
45+
else:
46+
return False
47+
48+
# 写入数据到数据库
49+
def insert_serial(entry):
50+
serial = entry.get()
51+
if len(serial) != 6:
52+
messagebox.showerror("错误", "序列号长度必须为6位")
53+
elif check_duplicate(serial):
54+
messagebox.showinfo("提示", f"序列号 {serial} 已存在,不重复写入数据库")
55+
else:
56+
cursor.execute("INSERT INTO number (numbers) VALUES (?)", (serial,))
57+
conn.commit()
58+
messagebox.showinfo("提示", f"序列号 {serial} 已成功写入数据库")
59+
60+
61+
# 创建UI界面
62+
def create_ui():
63+
64+
def on_key_release(event):
65+
# 获取文本框中的输入内容
66+
input_text = entry.get()
67+
# 检查输入长度是否达到6个字符
68+
if len(input_text) >= 6:
69+
insert_serial(entry)
70+
print("输入长度达到6个字符,写入数据。")
71+
# 清空输入框
72+
entry.delete(0, tk.END)
73+
74+
75+
root = tk.Tk()
76+
root.title("序列号查询软件")
77+
78+
label = tk.Label(root, text="手动输入序列号并查重写入数据库")
79+
label.pack()
80+
81+
entry = tk.Entry(root)
82+
entry.pack()
83+
84+
# 绑定键盘释放事件到on_key_release函数
85+
entry.bind('<KeyRelease>', on_key_release)
86+
87+
button = tk.Button(root, text="写入序列号", command=lambda: insert_serial(entry))
88+
button.pack()
89+
90+
root.mainloop()
91+
92+
# 主程序
93+
if __name__ == "__main__":
94+
create_ui()
95+
96+
# 关闭数据库连接
97+
cursor.close()
98+
conn.close()

db-SQLserver.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'''
2+
Author: 木白广木林
3+
Date: 2024-05-18 08:19:40
4+
LastEditTime: 2024-05-18 08:59:00
5+
LastEditors: 木白广木林
6+
Description: None
7+
FilePath: \Desktop\db-SQLserver.py
8+
检查自己的代码是非常愚蠢的行为,这是对本身实力的不信任。
9+
'''
10+
import sys
11+
import pyodbc
12+
import tkinter as tk
13+
from tkinter import messagebox
14+
15+
# 连接SQL Server数据库
16+
# conn = pyodbc.connect('DRIVER={SQL Server};SERVER=Your_Server_Name;DATABASE=Your_Database_Name;UID=Your_Username;PWD=Your_Password')
17+
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=DESKTOP-FCCVVU8;DATABASE=db;UID=sa;PWD=root')
18+
cursor = conn.cursor()
19+
20+
# 查询数据库中是否已存在序列号
21+
def check_duplicate(serial):
22+
cursor.execute("SELECT * FROM number WHERE numbers = ?", (serial,))
23+
if cursor.fetchall():
24+
return True
25+
else:
26+
return False
27+
28+
# 写入数据到数据库
29+
def insert_serial(entry):
30+
serial = entry.get()
31+
if len(serial) != 6:
32+
messagebox.showerror("错误", "序列号长度必须为6位")
33+
elif check_duplicate(serial):
34+
messagebox.showinfo("提示", f"序列号 {serial} 已存在,不重复写入数据库")
35+
else:
36+
cursor.execute("INSERT INTO number (numbers) VALUES (?)", (serial,))
37+
conn.commit()
38+
messagebox.showinfo("提示", f"序列号 {serial} 已成功写入数据库")
39+
40+
# 创建UI界面
41+
def create_ui():
42+
root = tk.Tk()
43+
root.title("序列号查询软件")
44+
45+
label = tk.Label(root, text="手动输入序列号并查重写入数据库")
46+
label.pack()
47+
48+
entry = tk.Entry(root)
49+
entry.pack()
50+
51+
button = tk.Button(root, text="写入序列号", command=lambda: insert_serial(entry))
52+
button.pack()
53+
54+
root.mainloop()
55+
56+
# 主程序
57+
if __name__ == "__main__":
58+
create_ui()
59+
60+
# 关闭数据库连接
61+
cursor.close()
62+
conn.close()

0 commit comments

Comments
 (0)