feat(category): insert category

This commit is contained in:
iridiumR 2023-05-22 01:03:57 +08:00
parent 4bf9662efc
commit b12807031a
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8

View file

@ -1,4 +1,5 @@
from PyQt6.QtWidgets import *
import json
def initCategorytTab(self):
# 创建连接信息控件
@ -32,12 +33,18 @@ def onCategoryAddClicked(self):
label1 = QLabel("Category Name:")
line1 = QLineEdit()
label2 = QLabel("Category Type")
label2 = QLabel("Category Type:")
line2 =QComboBox()
label3 = QLabel("Description:")
line3 = QLineEdit()
line2.addItem("Income")
line2.addItem("Expense")
button1 = QPushButton("Confirm")
button2 = QPushButton("Abort")
buttonLayout = QHBoxLayout()
buttonLayout.addWidget(button1)
buttonLayout.addWidget(button2)
button1.clicked.connect(addDialog.accept)
button2.clicked.connect(addDialog.reject)
@ -45,14 +52,33 @@ def onCategoryAddClicked(self):
layout = QFormLayout()
layout.addRow(label1,line1)
layout.addRow(label2,line2)
layout.addRow(button1,button2)
layout.addRow(label3,line3)
layout.addRow(buttonLayout)
addDialog.setLayout(layout)
# 显示添加数据对话框
if addDialog.exec() == QDialog.DialogCode.Accepted:
try:
print("success")
# 获取输入数据
name = line1.text()
type = line2.currentText()
if (name == ''):
raise Exception('Category name cannot be empty')
if(type == "Income"):
type = True
else:
type = False
description = line3.text()
# JSONB插入数据
data = {"name": line1.text(), "income_type": type, "description": description}
data = json.dumps(data)
print("insert data:",data)
self.cur.execute("INSERT INTO category (meta) VALUES (%s)", (data,))
self.conn.commit()
except Exception as e:
# 处理插入数据错误
print(e)