aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI/UI_DatabaseView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/UI/UI_DatabaseView.cpp')
-rw-r--r--core/src/UI/UI_DatabaseView.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp
index 884ab51..4009e5b 100644
--- a/core/src/UI/UI_DatabaseView.cpp
+++ b/core/src/UI/UI_DatabaseView.cpp
@@ -56,6 +56,8 @@ private:
/// index by offsetting by \c mFirstCachedRowId.
std::vector<int> mActiveEntries;
+ /// Number of rows in the table.
+ int mRowCount;
/// Last possible page for the current set table and filter (inclusive).
int mLastPage;
/// The current page the user is on.
@@ -71,6 +73,13 @@ public:
void OnProjectChanged(Project* newProject) {
mProject = newProject;
+ auto& stmt = newProject->GetTransactionsModel().GetSales().GetRowCountStatement;
+ if (stmt.executeStep()) {
+ mRowCount = stmt.getColumn(0).getInt();
+ } else {
+ // TODO report error
+ }
+
mFirstCachedRowId = 0;
mLastCachedRowId = 0;
@@ -116,6 +125,7 @@ public:
auto ls = LocaleStrings::Instance.get();
if (ImGui::Button(ICON_FA_ARROW_LEFT, mCurrentPage == 0)) {
+ mSelectedEntryRowId = -1;
SetPage(mCurrentPage - 1);
}
@@ -125,6 +135,7 @@ public:
ImGui::SameLine();
if (ImGui::Button(ICON_FA_ARROW_RIGHT, mCurrentPage == mLastPage)) {
+ mSelectedEntryRowId = -1;
SetPage(mCurrentPage + 1);
}
@@ -165,6 +176,9 @@ public:
void DrawEntry(const SaleEntry& entry, int rowId) {
auto ls = LocaleStrings::Instance.get();
+ ImGui::PushID(rowId);
+ ImGui::TableNextRow();
+
ImGui::TableNextColumn();
if (ImGui::Selectable(entry.Customer.c_str(), mSelectedEntryRowId == rowId, ImGuiSelectableFlags_SpanAllColumns)) {
mSelectedEntryRowId = rowId;
@@ -179,6 +193,8 @@ public:
} else {
ImGui::Text("%s", entry.DeliveryTime.c_str());
}
+
+ ImGui::PopID();
}
const SaleEntry& GetEntry(int64_t rowId) const {
@@ -197,7 +213,7 @@ private:
void UpdateLastPage() {
mLastPage = mActiveEntries.empty()
- ? 0 // TODO calc page
+ ? CalcPageForRowId(mRowCount)
: CalcPageForRowId(mActiveEntries.back());
}
@@ -267,7 +283,10 @@ private:
auto t = chrono::system_clock::to_time_t(tp);
char data[32];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // C++ doesn't have std::localtime_s
std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
+#pragma clang diagnostic pop
return std::string(data);
};
@@ -351,7 +370,6 @@ void UI::DatabaseViewTab() {
purchasesView.Draw();
ImGui::EndTabItem();
}
-
ImGui::EndTabBar();
}
}