Refactor database handling: remove db_handler module, implement file_handler for CSV operations, and update TUI to integrate new export functionality.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "db_handler.h"
|
||||
#include "file_handler.h"
|
||||
|
||||
int loadListFromCSV(char *_filename, list_t *_list)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ int saveListToCSV(char *_filename, list_t *_list)
|
||||
{
|
||||
if (cursor->user.uuid != 0)
|
||||
{
|
||||
fprintf(f_out, "%hu,%s,%s,%u,%ld,%ld,%hhu", cursor->user.uuid, cursor->user.name, cursor->user.surname, cursor->user.department, cursor->user.last_time_event, cursor->user.total, cursor->user.available);
|
||||
fprintf(f_out, "%hu,%s,%s,%u,%ld,%ld,%hhu\n", cursor->user.uuid, cursor->user.name, cursor->user.surname, cursor->user.department, cursor->user.last_time_event, cursor->user.total, cursor->user.available);
|
||||
}
|
||||
cursor = cursor->next;
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "users.h"
|
||||
#include "tui.h"
|
||||
#include "rfid_handler.h"
|
||||
#include "db_handler.h"
|
||||
#include "file_handler.h"
|
||||
|
||||
void handle_sigint(int sig)
|
||||
{
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "db_handler.h"
|
||||
#include "file_handler.h"
|
||||
#include "tui.h"
|
||||
|
||||
void uartDialog(char *uart_adress, int terminal_x, int terminal_y)
|
||||
@@ -183,6 +184,10 @@ void mainMenu(list_t *person_list, int terminal_x, int terminal_y)
|
||||
personSearch(person_list, terminal_x, terminal_y);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
exportDialog(person_list, terminal_x, terminal_y);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (keyboard_input == '\n')
|
||||
{
|
||||
@@ -562,6 +567,111 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y)
|
||||
}
|
||||
}
|
||||
|
||||
void exportDialog(list_t _list, int terminal_x, int terminal_y){
|
||||
|
||||
void exportDialog(list_t *_list, int terminal_x, int terminal_y)
|
||||
{
|
||||
int win_height = 8;
|
||||
int win_width = 80;
|
||||
int start_y = (terminal_y - win_height) / 2;
|
||||
int start_x = (terminal_x - win_width) / 2;
|
||||
|
||||
WINDOW *exportdialog = newwin(win_height, win_width, start_y, start_x);
|
||||
|
||||
wbkgd(exportdialog, COLOR_PAIR(6));
|
||||
|
||||
int max_rows = win_height - 2;
|
||||
int total_count = 0;
|
||||
box(exportdialog, 0, 0);
|
||||
|
||||
wattron(exportdialog, COLOR_PAIR(1));
|
||||
wattron(exportdialog, A_BOLD);
|
||||
mvwprintw(exportdialog, 0, (win_width - strlen("Copy database and save")) / 2, "%s", "Copy database and save");
|
||||
wattroff(exportdialog, A_BOLD);
|
||||
wattroff(exportdialog, COLOR_PAIR(1));
|
||||
keypad(exportdialog, TRUE);
|
||||
|
||||
wattron(exportdialog, COLOR_PAIR(1));
|
||||
mvwprintw(exportdialog, 2, (win_width - strlen("Enter name of exported database")) / 2, "%s", "Enter name of exported database");
|
||||
wattroff(exportdialog, COLOR_PAIR(1));
|
||||
wrefresh(exportdialog);
|
||||
|
||||
char choice;
|
||||
int highlight = 0;
|
||||
|
||||
int text_x = (win_width - 52) / 2;
|
||||
int button_x = (win_width - 7) / 2;
|
||||
|
||||
char filename[51];
|
||||
|
||||
keypad(exportdialog, true);
|
||||
while (1)
|
||||
{
|
||||
// Input array
|
||||
if (highlight == 0)
|
||||
wattron(exportdialog, COLOR_PAIR(2));
|
||||
else
|
||||
wattron(exportdialog, COLOR_PAIR(1));
|
||||
|
||||
mvwprintw(exportdialog, 4, text_x, "[%50s]", filename);
|
||||
if (!strcmp(filename, "\0"))
|
||||
mvwprintw(exportdialog, 4, text_x, "[__________________________________________________]");
|
||||
|
||||
if (highlight == 0)
|
||||
wattroff(exportdialog, COLOR_PAIR(2));
|
||||
else
|
||||
wattroff(exportdialog, COLOR_PAIR(1));
|
||||
|
||||
// Enter button
|
||||
if (highlight == 1)
|
||||
wattron(exportdialog, COLOR_PAIR(2));
|
||||
else
|
||||
wattron(exportdialog, COLOR_PAIR(1));
|
||||
wattron(exportdialog, A_BOLD);
|
||||
|
||||
mvwprintw(exportdialog, 6, button_x - 2, " %s ", "<Enter>");
|
||||
if (highlight == 1)
|
||||
wattroff(exportdialog, COLOR_PAIR(2));
|
||||
else
|
||||
wattroff(exportdialog, COLOR_PAIR(1));
|
||||
wattroff(exportdialog, A_BOLD);
|
||||
|
||||
wrefresh(exportdialog);
|
||||
|
||||
flushinp();
|
||||
choice = wgetch(exportdialog);
|
||||
|
||||
if (choice == '\t')
|
||||
{
|
||||
highlight = !highlight;
|
||||
}
|
||||
|
||||
else if (choice == '\n')
|
||||
{
|
||||
if (highlight == 0)
|
||||
{
|
||||
mvwprintw(exportdialog, 4, (win_width - 52) / 2, "[__________________________________________________]");
|
||||
echo();
|
||||
wmove(exportdialog, 4, ((win_width - 52) / 2) + 1);
|
||||
curs_set(1);
|
||||
flushinp();
|
||||
wgetnstr(exportdialog, filename, 50);
|
||||
curs_set(0);
|
||||
noecho();
|
||||
}
|
||||
else if (highlight == 1)
|
||||
{
|
||||
|
||||
if (choice == '\n')
|
||||
{
|
||||
saveListToCSV(filename, _list);
|
||||
wclear(exportdialog);
|
||||
wrefresh(exportdialog);
|
||||
touchwin(stdscr);
|
||||
refresh();
|
||||
delwin(exportdialog);
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user