feat(category): insert category
This commit is contained in:
parent
4bf9662efc
commit
b12807031a
1 changed files with 29 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
from PyQt6.QtWidgets import *
|
from PyQt6.QtWidgets import *
|
||||||
|
import json
|
||||||
|
|
||||||
def initCategorytTab(self):
|
def initCategorytTab(self):
|
||||||
# 创建连接信息控件
|
# 创建连接信息控件
|
||||||
|
@ -32,12 +33,18 @@ def onCategoryAddClicked(self):
|
||||||
|
|
||||||
label1 = QLabel("Category Name:")
|
label1 = QLabel("Category Name:")
|
||||||
line1 = QLineEdit()
|
line1 = QLineEdit()
|
||||||
label2 = QLabel("Category Type")
|
label2 = QLabel("Category Type:")
|
||||||
line2 =QComboBox()
|
line2 =QComboBox()
|
||||||
|
label3 = QLabel("Description:")
|
||||||
|
line3 = QLineEdit()
|
||||||
line2.addItem("Income")
|
line2.addItem("Income")
|
||||||
line2.addItem("Expense")
|
line2.addItem("Expense")
|
||||||
|
|
||||||
button1 = QPushButton("Confirm")
|
button1 = QPushButton("Confirm")
|
||||||
button2 = QPushButton("Abort")
|
button2 = QPushButton("Abort")
|
||||||
|
buttonLayout = QHBoxLayout()
|
||||||
|
buttonLayout.addWidget(button1)
|
||||||
|
buttonLayout.addWidget(button2)
|
||||||
|
|
||||||
button1.clicked.connect(addDialog.accept)
|
button1.clicked.connect(addDialog.accept)
|
||||||
button2.clicked.connect(addDialog.reject)
|
button2.clicked.connect(addDialog.reject)
|
||||||
|
@ -45,14 +52,33 @@ def onCategoryAddClicked(self):
|
||||||
layout = QFormLayout()
|
layout = QFormLayout()
|
||||||
layout.addRow(label1,line1)
|
layout.addRow(label1,line1)
|
||||||
layout.addRow(label2,line2)
|
layout.addRow(label2,line2)
|
||||||
layout.addRow(button1,button2)
|
layout.addRow(label3,line3)
|
||||||
|
layout.addRow(buttonLayout)
|
||||||
|
|
||||||
addDialog.setLayout(layout)
|
addDialog.setLayout(layout)
|
||||||
|
|
||||||
# 显示添加数据对话框
|
# 显示添加数据对话框
|
||||||
if addDialog.exec() == QDialog.DialogCode.Accepted:
|
if addDialog.exec() == QDialog.DialogCode.Accepted:
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
# 处理插入数据错误
|
# 处理插入数据错误
|
||||||
print(e)
|
print(e)
|
||||||
|
|
Loading…
Reference in a new issue