Merge branch 'main' of g.8f.al:ir/budget
This commit is contained in:
commit
67fec711f8
2 changed files with 20 additions and 14 deletions
|
@ -14,6 +14,7 @@ class AccountTab(TabPage):
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
# 创建顶部控件
|
# 创建顶部控件
|
||||||
self.accountComboBox = QComboBox()
|
self.accountComboBox = QComboBox()
|
||||||
|
self.accountComboBox.currentIndexChanged.connect(self.onAccountIndexChanged)
|
||||||
|
|
||||||
self.accountModifyButton = QPushButton('Modify')
|
self.accountModifyButton = QPushButton('Modify')
|
||||||
self.accountAddButton = QPushButton('Add')
|
self.accountAddButton = QPushButton('Add')
|
||||||
|
@ -211,29 +212,35 @@ class AccountTab(TabPage):
|
||||||
print(e)
|
print(e)
|
||||||
QMessageBox.critical(self, 'Error', str(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.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()
|
||||||
|
|
||||||
|
|
||||||
# 初始化表格
|
# 初始化表格
|
||||||
self.accountTable.clear()
|
self.accountTable.clear()
|
||||||
self.accountTable.setRowCount(len(self.accountData))
|
self.accountTable.setRowCount(len(self.transData))
|
||||||
self.accountTable.setColumnCount(3) # 账户名 账户平衡 备注
|
self.accountTable.setColumnCount(4) # 时间 账户 金额 描述
|
||||||
self.accountTable.setHorizontalHeaderLabels(['Account Name', 'Account Balance', 'Description'])
|
self.accountTable.setHorizontalHeaderLabels(['Time', 'category', 'Amount', 'Description'])
|
||||||
# 设置自动调整列宽
|
# 设置自动调整列宽
|
||||||
self.accountTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
self.accountTable.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
|
||||||
|
|
||||||
# 填充表格
|
# 填充表格
|
||||||
for i in range(len(self.accountData)):
|
for i in range(len(self.transData)):
|
||||||
self.accountTable.setItem(i, 0, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1]))
|
self.accountTable.setItem(i, 0, QTableWidgetItem(self.transData[i][4].strftime("%Y-%m-%d %H:%M:%S")))
|
||||||
# if self.transData[i][2] is None:
|
#self.accountTable.setItem(i, 1, QTableWidgetItem(self.accountData[self.transData[i][1]-1][1]))#amount 2
|
||||||
# self.accountTable.setItem(i, 1, QTableWidgetItem("None"))
|
if self.transData[i][2] is None:
|
||||||
# else:
|
self.accountTable.setItem(i, 1, QTableWidgetItem("None"))#category 3
|
||||||
# self.accountTable.setItem(i, 1, QTableWidgetItem(self.categoryData[self.transData[i][2]-1][1]))
|
else:
|
||||||
self.accountTable.setItem(i, 1, QTableWidgetItem(str(self.transData[i][5])))
|
self.accountTable.setItem(i, 1, QTableWidgetItem(self.categoryData[self.transData[i][2]-1][1]))
|
||||||
self.accountTable.setItem(i, 2, QTableWidgetItem(self.transData[i][6]))
|
self.accountTable.setItem(i, 2, QTableWidgetItem(str(self.transData[i][5])))
|
||||||
|
self.accountTable.setItem(i, 3, QTableWidgetItem(self.transData[i][6]))
|
||||||
|
|
||||||
|
|
|
@ -5,4 +5,3 @@ if __name__ == '__main__':
|
||||||
mw = MainWindow()
|
mw = MainWindow()
|
||||||
mw.show()
|
mw.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue