修正数据填充错误2
This commit is contained in:
parent
152255428a
commit
aaac52b2d2
1 changed files with 20 additions and 13 deletions
|
@ -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')
|
||||
|
@ -250,29 +251,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]))
|
||||
|
||||
|
|
Loading…
Reference in a new issue