feat: 删除无用print & 按类别显示记录

This commit is contained in:
iridiumR 2023-06-05 00:05:18 +08:00
parent ada1f226a9
commit 6dfac9cc82
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8
4 changed files with 29 additions and 35 deletions

View file

@ -88,11 +88,11 @@ class AccountTab(TabPage):
# 构造查询语句 # 构造查询语句
a_id = self.rows[index][0] a_id = self.rows[index][0]
print(a_id)
self.pg.execute( self.pg.execute(
"SELECT meta->>'name', replace(substring(balance::text, 2), ',', ''), meta->'description' FROM account WHERE a_id=%s", (a_id,)) "SELECT meta->>'name', replace(substring(balance::text, 2), ',', ''), meta->'description' FROM account WHERE a_id=%s", (a_id,))
data = self.pg.fetchall() data = self.pg.fetchall()
print(data)
oldBalance = float(data[0][1]) oldBalance = float(data[0][1])
@ -149,7 +149,6 @@ class AccountTab(TabPage):
# JSONB插入数据 # JSONB插入数据
data = {"name": accountNameLine.text(), "balance": balance, "description": description} data = {"name": accountNameLine.text(), "balance": balance, "description": description}
data = json.dumps(data) data = json.dumps(data)
print("insert data:",data)
self.pg.execute("UPDATE account SET meta=%s WHERE a_id=%s", (data, a_id)) self.pg.execute("UPDATE account SET meta=%s WHERE a_id=%s", (data, a_id))
@ -217,7 +216,6 @@ class AccountTab(TabPage):
# JSONB插入数据 # JSONB插入数据
data = {"name": accountNameLine.text(), "description": description} data = {"name": accountNameLine.text(), "description": description}
data = json.dumps(data) data = json.dumps(data)
print("insert data:",data)
self.pg.execute("INSERT INTO account (balance, meta) VALUES (%s, %s) RETURNING a_id", (balance, data,)) self.pg.execute("INSERT INTO account (balance, meta) VALUES (%s, %s) RETURNING a_id", (balance, data,))
a_id = self.pg.fetchall()[0][0] a_id = self.pg.fetchall()[0][0]
@ -244,7 +242,7 @@ class AccountTab(TabPage):
try: try:
self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id") self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id")
self.rows = self.pg.cur.fetchall() self.rows = self.pg.cur.fetchall()
print(self.rows)
for row in self.rows: for row in self.rows:
data = row[1] data = row[1]
self.accountComboBox.addItem(data) self.accountComboBox.addItem(data)
@ -259,7 +257,6 @@ class AccountTab(TabPage):
self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id") self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
self.categoryData = self.pg.fetchall() self.categoryData = self.pg.fetchall()
print(self.accountData)
# 初始化表格 # 初始化表格
self.accountTable.clear() self.accountTable.clear()

View file

@ -16,6 +16,7 @@ class CategoryTab(TabPage):
def initUI(self): def initUI(self):
# 创建连接信息控件 # 创建连接信息控件
self.categoryComboBox = QComboBox() self.categoryComboBox = QComboBox()
self.categoryComboBox.currentIndexChanged.connect(self.onCategoryIndexChanged)
self.categoryModifyButton = QPushButton('Modify') self.categoryModifyButton = QPushButton('Modify')
self.categoryModifyButton.clicked.connect(self.onCategoryModifyClicked) self.categoryModifyButton.clicked.connect(self.onCategoryModifyClicked)
@ -57,11 +58,11 @@ class CategoryTab(TabPage):
# 构造查询语句 # 构造查询语句
c_id = self.rows[index][0] c_id = self.rows[index][0]
print(c_id)
self.pg.execute( self.pg.execute(
"SELECT meta->>'name', meta->>'type', meta->'description' FROM category WHERE c_id=%s", (c_id,)) "SELECT meta->>'name', meta->>'type', meta->'description' FROM category WHERE c_id=%s", (c_id,))
data = self.pg.fetchall() data = self.pg.fetchall()
print(data)
# 绘制界面并填充数据 # 绘制界面并填充数据
label1 = QLabel("Category Name:") label1 = QLabel("Category Name:")
@ -122,7 +123,7 @@ class CategoryTab(TabPage):
data = {"name": line1.text(), "type": type, data = {"name": line1.text(), "type": type,
"description": description} "description": description}
data = json.dumps(data) data = json.dumps(data)
print("insert data:", data)
self.pg.execute("UPDATE category SET meta=%s WHERE c_id=%s",(data,c_id,)) self.pg.execute("UPDATE category SET meta=%s WHERE c_id=%s",(data,c_id,))
@ -187,7 +188,7 @@ class CategoryTab(TabPage):
data = {"name": line1.text(), "type": type, data = {"name": line1.text(), "type": type,
"description": description} "description": description}
data = json.dumps(data) data = json.dumps(data)
print("insert data:", data)
self.pg.execute( self.pg.execute(
"INSERT INTO category (meta) VALUES (%s)", (data,)) "INSERT INTO category (meta) VALUES (%s)", (data,))
@ -208,7 +209,7 @@ class CategoryTab(TabPage):
self.pg.execute( self.pg.execute(
"SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id") "SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
self.rows = self.pg.cur.fetchall() self.rows = self.pg.cur.fetchall()
print(self.rows)
for row in self.rows: for row in self.rows:
data = row[1] data = row[1]
self.categoryComboBox.addItem(data) self.categoryComboBox.addItem(data)
@ -216,35 +217,34 @@ class CategoryTab(TabPage):
print(e) print(e)
QMessageBox.critical(self, 'Error', str(e)) QMessageBox.critical(self, 'Error', str(e))
# self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
# self.categoryData = self.pg.fetchall() def onCategoryIndexChanged(self, index):
self.pg.execute("SELECT t_id, a_id, c_id, s_id, time, translate(amount::varchar,'$',''), meta->>'description' FROM transaction ORDER BY time DESC") # 获取comboBox中的c_id
c_id = self.rows[index][0]
self.pg.execute("SELECT t_id, a_id, c_id, s_id, time, translate(amount::varchar,'$',''),\
meta->>'description' FROM transaction \
WHERE c_id = %s ORDER BY time DESC", (c_id,))
self.transData = self.pg.fetchall() self.transData = self.pg.fetchall()
self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id") self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id")
self.accountData = self.pg.fetchall() self.accountData = self.pg.fetchall()
self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id") self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
self.categoryData = self.pg.fetchall() self.categoryData = self.pg.fetchall()
print(self.rows)
# 初始化表格 # 初始化表格
self.categoryTable.clear() self.categoryTable.clear()
self.categoryTable.setRowCount(len(self.transData)) self.categoryTable.setRowCount(len(self.transData))
self.categoryTable.setColumnCount(3) # 类别名称 类别 描述 self.categoryTable.setColumnCount(4) # 时间 账户 金额 描述
self.categoryTable.setHorizontalHeaderLabels(['Category Name', 'Category Type','Description']) self.categoryTable.setHorizontalHeaderLabels(['Time', 'Account', 'Amount', 'Description'])
# 设置自动调整列宽 # 设置自动调整列宽
self.categoryTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch) self.categoryTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
# 填充表格 # 填充表格
for i in range(len(self.transData)): for i in range(len(self.transData)):
# self.categoryTable.setItem(i, 2, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1])) self.categoryTable.setItem(i, 0, QTableWidgetItem(self.transData[i][4].strftime("%Y-%m-%d %H:%M:%S")))
self.categoryTable.setItem(i, 1, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1]))
if self.transData[i][2] is None: if self.transData[i][2] is None:
self.categoryTable.setItem(i, 0, QTableWidgetItem("None")) self.categoryTable.setItem(i, 2, QTableWidgetItem("None"))
else: else:
self.categoryTable.setItem(i, 0, QTableWidgetItem(data)) self.categoryTable.setItem(i, 2, QTableWidgetItem(self.categoryData[self.transData[i][2]-1][1]))
# self.categoryTable.setItem(i, 0, QTableWidgetItem(self.accountData[self.transData[i][2]-1][1])) self.categoryTable.setItem(i, 3, QTableWidgetItem(self.transData[i][6]))
# self.categoryTable.setItem(i, 0, QTableWidgetItem(data[0][0]))
self.categoryTable.setItem(i, 1, QTableWidgetItem(str(self.transData[i][5])))
self.categoryTable.setItem(i, 2, QTableWidgetItem(self.transData[i][6]))

View file

@ -68,7 +68,6 @@ class StatTab(TabPage):
time BETWEEN %s AND %s GROUP BY c_id ORDER BY c_id", \ time BETWEEN %s AND %s GROUP BY c_id ORDER BY c_id", \
(datetime.date(year, month, 1), datetime.date(year, month+1, 1),)) (datetime.date(year, month, 1), datetime.date(year, month+1, 1),))
self.statData = self.pg.fetchall() self.statData = self.pg.fetchall()
print(self.statData)
# 获取此月所有交易类别 # 获取此月所有交易类别
self.pg.execute("SELECT c_id, meta->>'type', meta->>'name' FROM category \ self.pg.execute("SELECT c_id, meta->>'type', meta->>'name' FROM category \
@ -76,7 +75,6 @@ class StatTab(TabPage):
ORDER BY c_id", \ ORDER BY c_id", \
(datetime.date(year, month, 1), datetime.date(year, month+1, 1),)) (datetime.date(year, month, 1), datetime.date(year, month+1, 1),))
self.categoryData = self.pg.fetchall() self.categoryData = self.pg.fetchall()
print(self.categoryData)
# 填充饼状图 # 填充饼状图
self.chart.removeAllSeries() self.chart.removeAllSeries()

View file

@ -107,7 +107,7 @@ class TransTab(TabPage):
# JSONB插入数据 # JSONB插入数据
data = {"type":type, "description": description} data = {"type":type, "description": description}
data = json.dumps(data) data = json.dumps(data)
print("insert data:", data)
self.pg.execute( self.pg.execute(
"INSERT INTO transaction (c_id, a_id, time, amount, meta) VALUES (%s,%s,now(), %s,%s)", (category, account, amount, data,)) "INSERT INTO transaction (c_id, a_id, time, amount, meta) VALUES (%s,%s,now(), %s,%s)", (category, account, amount, data,))
@ -181,7 +181,7 @@ class TransTab(TabPage):
if num != amountLine.text(): if num != amountLine.text():
amount = float(amountLine.text()) amount = float(amountLine.text())
amount = amount - float(num) amount = amount - float(num)
print(amount)
self.pg.execute("UPDATE account SET balance = balance + (%s::NUMERIC)::MONEY WHERE a_id = %s",\ self.pg.execute("UPDATE account SET balance = balance + (%s::NUMERIC)::MONEY WHERE a_id = %s",\
(amount, self.transData[self.rows[0].row()][1],)) (amount, self.transData[self.rows[0].row()][1],))
@ -216,7 +216,7 @@ class TransTab(TabPage):
def onDialogTypeChanged(self, index): def onDialogTypeChanged(self, index):
# 获取当前选择的类型 # 获取当前选择的类型
type = self.dialogLayout.itemAt(1).widget().currentText() type = self.dialogLayout.itemAt(1).widget().currentText()
print(type)
if(type=="Income"): if(type=="Income"):
self.pg.execute( self.pg.execute(
"SELECT c_id, meta->>'name' FROM category WHERE meta->>'type'='in' ORDER BY c_id") "SELECT c_id, meta->>'name' FROM category WHERE meta->>'type'='in' ORDER BY c_id")
@ -224,7 +224,7 @@ class TransTab(TabPage):
self.pg.execute( self.pg.execute(
"SELECT c_id, meta->>'name' FROM category WHERE meta->>'type'='out' ORDER BY c_id") "SELECT c_id, meta->>'name' FROM category WHERE meta->>'type'='out' ORDER BY c_id")
self.categoryData = self.pg.fetchall() self.categoryData = self.pg.fetchall()
print(self.categoryData)
self.dialogLayout.itemAt(3).widget().clear() self.dialogLayout.itemAt(3).widget().clear()
for i in range(len(self.categoryData)): for i in range(len(self.categoryData)):
self.dialogLayout.itemAt(3).widget().addItem(self.categoryData[i][1]) self.dialogLayout.itemAt(3).widget().addItem(self.categoryData[i][1])
@ -232,7 +232,7 @@ class TransTab(TabPage):
# 填充账户 # 填充账户
self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id") self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id")
self.accountData = self.pg.fetchall() self.accountData = self.pg.fetchall()
print(self.accountData)
self.dialogLayout.itemAt(5).widget().clear() self.dialogLayout.itemAt(5).widget().clear()
for i in range(len(self.accountData)): for i in range(len(self.accountData)):
self.dialogLayout.itemAt(5).widget().addItem(self.accountData[i][1]) self.dialogLayout.itemAt(5).widget().addItem(self.accountData[i][1])
@ -245,7 +245,6 @@ class TransTab(TabPage):
self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id") self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
self.categoryData = self.pg.fetchall() self.categoryData = self.pg.fetchall()
print(self.transData)
# 初始化表格 # 初始化表格
self.transTable.clear() self.transTable.clear()