feat: 账户余额显示功能

This commit is contained in:
iridiumR 2023-06-05 17:48:12 +08:00
parent 67fec711f8
commit c5588f3a4a
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8

View file

@ -16,6 +16,10 @@ class AccountTab(TabPage):
self.accountComboBox = QComboBox() self.accountComboBox = QComboBox()
self.accountComboBox.currentIndexChanged.connect(self.onAccountIndexChanged) self.accountComboBox.currentIndexChanged.connect(self.onAccountIndexChanged)
self.accountBalanceLine = QLineEdit()
self.accountBalanceLine.setReadOnly(True)
# 默认宽度
self.accountBalanceLine.setFixedWidth(150)
self.accountModifyButton = QPushButton('Modify') self.accountModifyButton = QPushButton('Modify')
self.accountAddButton = QPushButton('Add') self.accountAddButton = QPushButton('Add')
self.accountModifyButton.clicked.connect(self.onAccountModifyClicked) self.accountModifyButton.clicked.connect(self.onAccountModifyClicked)
@ -24,6 +28,7 @@ class AccountTab(TabPage):
# 创建控件布局 # 创建控件布局
topLayout = QHBoxLayout() topLayout = QHBoxLayout()
topLayout.addWidget(self.accountComboBox) topLayout.addWidget(self.accountComboBox)
topLayout.addWidget(self.accountBalanceLine)
topLayout.addWidget(self.accountModifyButton) topLayout.addWidget(self.accountModifyButton)
topLayout.addWidget(self.accountAddButton) topLayout.addWidget(self.accountAddButton)
@ -220,11 +225,14 @@ class AccountTab(TabPage):
meta->>'description' FROM transaction \ meta->>'description' FROM transaction \
WHERE a_id = %s ORDER BY time DESC", (a_id,)) WHERE a_id = %s ORDER BY time DESC", (a_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', balance 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()
# 设置余额
self.accountBalanceLine.setText(str(self.accountData[index][2]))
# 初始化表格 # 初始化表格
self.accountTable.clear() self.accountTable.clear()
self.accountTable.setRowCount(len(self.transData)) self.accountTable.setRowCount(len(self.transData))