Merge branch 'main' of g.8f.al:ir/budget

This commit is contained in:
iridiumR 2023-06-05 17:43:10 +08:00
commit 67fec711f8
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8
2 changed files with 20 additions and 14 deletions

View file

@ -14,6 +14,7 @@ class AccountTab(TabPage):
def initUI(self):
# 创建顶部控件
self.accountComboBox = QComboBox()
self.accountComboBox.currentIndexChanged.connect(self.onAccountIndexChanged)
self.accountModifyButton = QPushButton('Modify')
self.accountAddButton = QPushButton('Add')
@ -211,29 +212,35 @@ class AccountTab(TabPage):
print(e)
QMessageBox.critical(self, 'Error', str(e))
self.pg.execute("SELECT t_id, a_id, c_id, s_id, time, translate(amount::varchar,'$',''), meta->>'description' FROM transaction ORDER BY time DESC")
def onAccountIndexChanged(self, index):
# 获取comboBox中的a_id
a_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 a_id = %s ORDER BY time DESC", (a_id,))
self.transData = self.pg.fetchall()
self.pg.execute("SELECT a_id, meta ->> 'name' FROM account ORDER BY a_id")
self.accountData = self.pg.fetchall()
self.pg.execute("SELECT c_id, meta ->> 'name' FROM category ORDER BY c_id")
self.categoryData = self.pg.fetchall()
# 初始化表格
self.accountTable.clear()
self.accountTable.setRowCount(len(self.accountData))
self.accountTable.setColumnCount(3) # 账户名 账户平衡 备注
self.accountTable.setHorizontalHeaderLabels(['Account Name', 'Account Balance', 'Description'])
self.accountTable.setRowCount(len(self.transData))
self.accountTable.setColumnCount(4) # 时间 账户 金额 描述
self.accountTable.setHorizontalHeaderLabels(['Time', 'category', 'Amount', 'Description'])
# 设置自动调整列宽
self.accountTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
# 填充表格
for i in range(len(self.accountData)):
self.accountTable.setItem(i, 0, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1]))
# if self.transData[i][2] is None:
# self.accountTable.setItem(i, 1, QTableWidgetItem("None"))
# else:
# self.accountTable.setItem(i, 1, QTableWidgetItem(self.categoryData[self.transData[i][2]-1][1]))
self.accountTable.setItem(i, 1, QTableWidgetItem(str(self.transData[i][5])))
self.accountTable.setItem(i, 2, QTableWidgetItem(self.transData[i][6]))
for i in range(len(self.transData)):
self.accountTable.setItem(i, 0, QTableWidgetItem(self.transData[i][4].strftime("%Y-%m-%d %H:%M:%S")))
#self.accountTable.setItem(i, 1, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1]))#amount 2
if self.transData[i][2] is None:
self.accountTable.setItem(i, 1, QTableWidgetItem("None"))#category 3
else:
self.accountTable.setItem(i, 1, QTableWidgetItem(self.categoryData[self.transData[i][2]-1][1]))
self.accountTable.setItem(i, 2, QTableWidgetItem(str(self.transData[i][5])))
self.accountTable.setItem(i, 3, QTableWidgetItem(self.transData[i][6]))

View file

@ -5,4 +5,3 @@ if __name__ == '__main__':
mw = MainWindow()
mw.show()
sys.exit(app.exec())