From 102c0bd1be29eb95efbb524064b433b280fbea58 Mon Sep 17 00:00:00 2001 From: Piyush Aditya Kar <74527230+HilariousSoupXD@users.noreply.github.com> Date: Fri, 11 Apr 2025 00:34:35 +0530 Subject: [PATCH 1/2] Added complaint tracking system, updated the code elsewhere for stability. --- ComplaintBox.cpp | 35 +++++++++++++++++++++++++++++------ ComplaintBox.h | 1 + complaints_export.csv | 9 +++++---- main.cpp | 26 ++++++++++++++++++++------ 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/ComplaintBox.cpp b/ComplaintBox.cpp index 6abd894..0034579 100644 --- a/ComplaintBox.cpp +++ b/ComplaintBox.cpp @@ -96,12 +96,14 @@ void ComplaintBox::fileComplaint() { cout << YELLOW << "Enter complaint message: " << RESET; getline(cin, message); - string sql = "INSERT INTO complaints (category, subCategory, message) VALUES ('" + category + "', '" + subCategory + "', '" + message + "');"; + string sql = "INSERT INTO complaints (category, subCategory, message, status) VALUES ('" + + category + "', '" + subCategory + "', '" + message + "', 'Pending');"; + if (sqlite3_exec(db, sql.c_str(), 0, 0, &errMsg) != SQLITE_OK) { cout << RED << "Error: " << errMsg << RESET << endl; sqlite3_free(errMsg); } else { - cout << BOLDGREEN << "Complaint filed successfully!\n" << RESET; + cout << BOLDGREEN << "Complaint filed successfully with status 'Pending'!\n" << RESET; } } @@ -112,8 +114,8 @@ void ComplaintBox::exportComplaintsToCSV() { return; } - file << "complaint_id,category,subCategory,message\n"; - string sql = "SELECT complaint_id, category, subCategory, message FROM complaints;"; + file << "complaint_id,category,subCategory,message,status\n"; + string sql = "SELECT complaint_id, category, subCategory, message, status FROM complaints;"; auto callback = [](void *data, int argc, char **argv, char **colName) -> int { ofstream *f = static_cast(data); for (int i = 0; i < argc; i++) { @@ -138,10 +140,11 @@ void ComplaintBox::searchComplaints() { cin.ignore(); getline(cin, keyword); - string sql = "SELECT complaint_id, category, subCategory, message FROM complaints " + string sql = "SELECT complaint_id, category, subCategory, message, status FROM complaints " "WHERE category LIKE '%" + keyword + "%' OR " "subCategory LIKE '%" + keyword + "%' OR " - "message LIKE '%" + keyword + "%';"; + "message LIKE '%" + keyword + "%' OR " + "status LIKE '%" + keyword + "%';"; cout << CYAN << "\nSearch Results:\n" << RESET; auto callback = [](void *data, int argc, char **argv, char **colName) -> int { @@ -157,3 +160,23 @@ void ComplaintBox::searchComplaints() { sqlite3_free(errMsg); } } + + +void ComplaintBox::updateComplaintStatus(int complaint_id, const std::string& new_status) { + sqlite3_stmt* stmt; + std::string sql = "UPDATE complaints SET status = ? WHERE complaint_id = ?"; + + if (sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, nullptr) == SQLITE_OK) { + sqlite3_bind_text(stmt, 1, new_status.c_str(), -1, SQLITE_STATIC); + sqlite3_bind_int(stmt, 2, complaint_id); + + if (sqlite3_step(stmt) == SQLITE_DONE) { + cout << GREEN << "Status updated successfully.\n" << RESET; + } else { + cerr << RED << "Failed to update status.\n" << RESET; + } + } else { + cerr << RED << "SQL Prepare Failed: " << sqlite3_errmsg(db) << "\n" << RESET; + } + sqlite3_finalize(stmt); +} \ No newline at end of file diff --git a/ComplaintBox.h b/ComplaintBox.h index 4dbc09a..7e2a703 100644 --- a/ComplaintBox.h +++ b/ComplaintBox.h @@ -26,6 +26,7 @@ class ComplaintBox { void fileComplaint(); void exportComplaintsToCSV(); void searchComplaints(); + void updateComplaintStatus(int complaint_id, const std::string& new_status); private: sqlite3 *db; diff --git a/complaints_export.csv b/complaints_export.csv index eb444d4..468864e 100644 --- a/complaints_export.csv +++ b/complaints_export.csv @@ -1,4 +1,5 @@ -complaint_id,category,subCategory,message -1,Infrastructural,Hostel,Washrooms are not being regularly cleaned. -2,Management,College Events,Admin paisa kha gaya bc -3,Infrastructure,Hostel,MMC change karo mc +complaint_id,category,subCategory,message,status +1,Infrastructural,Hostel,Washrooms are not being regularly cleaned.,Pending +2,Management,College Events,Admin paisa kha gaya bc,Resolved +3,Infrastructure,Hostel,MMC change karo mc,Pending +4,College,Clasroom,ACs need to be installed,Pending diff --git a/main.cpp b/main.cpp index d9c12f7..8836659 100644 --- a/main.cpp +++ b/main.cpp @@ -8,15 +8,18 @@ int main() { do { cout << BOLDVIOLET << "\n==== Complaint Box Menu ====\n" << RESET; - cout << CYAN << "1. Register User\n" + cout << CYAN + << "1. Register User\n" << "2. Register Admin\n" << "3. User Login\n" << "4. Admin Login\n" << "5. File Complaint\n" << "6. Export Complaints to CSV\n" << "7. Search Complaints\n" - << "8. Exit\n" << RESET; - + << "8. Update Complaint Status (Admin Only)\n" + << "9. Exit\n" + << RESET; + cout << WHITE << "Choice: " << RESET; cin >> choice; @@ -42,13 +45,24 @@ int main() { case 7: cb.searchComplaints(); break; - case 8: + case 8: { + int id; + string status; + cout << YELLOW << "Enter Complaint ID to update: " << RESET; + cin >> id; + cout << YELLOW << "Enter new status (Pending/In Progress/Resolved): " << RESET; + cin.ignore(); + getline(cin, status); + cb.updateComplaintStatus(id, status); + break; + } + case 9: cout << BOLDGREEN << "Exiting..." << RESET << endl; break; default: cout << BOLDRED << "Invalid choice!\n" << RESET; } - } while (choice != 8); + } while (choice != 9); return 0; -} +} \ No newline at end of file From 3969413f3ec02bdba9d1fd4bbf0c27a3abfc6f21 Mon Sep 17 00:00:00 2001 From: Piyush Aditya Kar <74527230+HilariousSoupXD@users.noreply.github.com> Date: Fri, 11 Apr 2025 12:55:00 +0530 Subject: [PATCH 2/2] Updated main.cpp Made slight changes to maintain stability --- main.cpp | 89 +++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/main.cpp b/main.cpp index 3bc680b..1690d7f 100644 --- a/main.cpp +++ b/main.cpp @@ -4,8 +4,7 @@ using namespace std; int main() { ComplaintBox cb; - string choice; - int choiceNum = 0; + int choice; do { cout << BOLDVIOLET << "\n==== Complaint Box Menu ====\n" << RESET; @@ -24,56 +23,46 @@ int main() { cout << WHITE << "Choice: " << RESET; cin >> choice; - try { - choiceNum = stoi(choice); - switch (choiceNum) { - case 1: - cb.registerUser(); - break; - case 2: - cb.registerUser(true); - break; - case 3: - cb.loginUser(); - break; - case 4: - cb.loginUser(true); - break; - case 5: - cb.fileComplaint(); - break; - case 6: - cb.exportComplaintsToCSV(); - break; - case 7: - cb.searchComplaints(); - break; - case 8: - if (!cb.isAdminLoggedIn()) { - cout << RED << "Only admins can update complaint status.\n" << RESET; - break; - } else { - int id; - string status; - cout << YELLOW << "Enter Complaint ID to update: " << RESET; - cin >> id; - cin.ignore(); - cout << YELLOW << "Enter new status (Pending/In Progress/Resolved): " << RESET; - getline(cin, status); - cb.updateComplaintStatus(id, status); - break; - } - case 9: - cout << BOLDGREEN << "Exiting..." << RESET << endl; - break; - default: - cout << BOLDRED << "Invalid choice!\n" << RESET; + switch (choice) { + case 1: + cb.registerUser(); + break; + case 2: + cb.registerUser(true); + break; + case 3: + cb.loginUser(); + break; + case 4: + cb.loginUser(true); + break; + case 5: + cb.fileComplaint(); + break; + case 6: + cb.exportComplaintsToCSV(); + break; + case 7: + cb.searchComplaints(); + break; + case 8: { + int id; + string status; + cout << YELLOW << "Enter Complaint ID to update: " << RESET; + cin >> id; + cout << YELLOW << "Enter new status (Pending/In Progress/Resolved): " << RESET; + cin.ignore(); + getline(cin, status); + cb.updateComplaintStatus(id, status); + break; } - } catch (exception& e) { - cout << RED << "Invalid input! Please enter a number.\n" << RESET; + case 9: + cout << BOLDGREEN << "Exiting..." << RESET << endl; + break; + default: + cout << BOLDRED << "Invalid choice!\n" << RESET; } - - } while (choiceNum != 9); + } while (choice != 9); return 0; }