#include "FileHandler.h"
- Read everything in the csv file as an array.
vector<string> read_csv(const string& filename,bool keep_header = false)
vector<string> data = read_csv("carlist.csv");
cout << data[0] << endl;
- Read everything in the csv file as a two-dimensional array
vector<vector<string>> read_csv_2D(const string& filename, bool keep_header = false)
vector<vector<string>> data = read_csv_2D("carlist.csv");
cout << data[0][0] << endl;
- Read specific lines / line in the csv file.
vector<vector<string>> get_lines( const string& filename, int start, int range )
vector<vector<string>> data = get_lines("carlist.csv", 0, 2);
cout << data[0][0] << endl;
vector<string> get_line(const string& filename, int line)
vector<string> data = get_line("carlist.csv", 1);
cout << data[2] << endl;
- Read specific columns / column in the csv file.
vector<vector<string>> get_cols( const string& filename, int start, int range )
vector<vector<string>> data = get_cols("carlist.csv", 0, 2);
cout << data[7][1] << endl;
vector<string> get_col(const string& filename, int col)
vector<string> data = get_col("carlist.csv", 0);
cout << data[0][0] << endl;
- Read specific columns in the csv file.
string get_cell(const string& filename, int line, int col)
string data = get_cell("carlist.csv", 1, 2);
cout << data << endl;
- Append data to the end of the csv file.
bool append_line(const string& filename, vector<string> data)
vector<string> data = { "1", "2", "3" };
bool res = append_line("carlist.csv", data);
cout << res;
- Upload line to the csv file.
bool update_line(const string& filename, vector<string> data, int line)
vector<string> data = { "1", "2", "3" };
bool res = update_line("carlist.csv", data, 0);
cout << res;
- Delete the original data in the csv file.
bool delete_line(const string& filename, int line, int range =1 )
bool res = delete_line("carlist.csv", 0);
cout << res;
- Write data to specific cells.
bool update_cell(const string& filename, string value, int line, int row)
bool res = update_cell("carlist.csv", "666", 0, 0);
cout << res;
- A. Sort the data in the csv file by row in ascending order.
- B. Sort the data in the csv file by row in descending order.
vector<int> query(const string& filename, string condition[])
string condition[] = { "Registration Date", "==", "2007" };
vector<int> res = query("carlist.csv", condition);
cout << res.size() << endl;
#include "Authentication.h"
#define USER_FILE "users.csv"
#define USER_Name_ROW 0
#define USER_Password_ROW 2
#include "FileHandler.h"
/// <summary>
/// user login function
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns>
/// 100 success
/// 200 can't find user
/// 300 password incorrect
/// 400 unknown error
///</returns>
int login(string username, string password)
#include "Console.h"
void Console::error(string message)
void Console::success(string message)
void Console::warning(string message)
#include "DateTime.h"
cont << get_now() << endl;
// 2023-02-10 00:46:44
#define SIGN "-"
// Sign used to orm the divider
int show_invoice(vector<string> data){
int len = 61;
// The length of this form
string divider = "";
for (int i = 0; i < len; i++)
{
divider += SIGN;
}
cout << center_print("Receipt", SIGN, len) << endl;
cout << divider << endl;
cout << setiosflags(ios::left)
<< setw(12) << "Invoice ID" << "|"
<< resetiosflags(ios::left)
<< setiosflags(ios::right)
<< setw(10) << "car ID" << "|"
<< setw(25) << "Booking Time" << "|"
<< setw(10) << "Price" << "|"
<< resetiosflags(ios::right) << endl;
cout << divider << endl;
cout << setiosflags(ios::left)
<< setw(12) << data[0] << "|"
<< resetiosflags(ios::left)
<< setiosflags(ios::right)
<< setw(10) << data[1] << "|"
<< setw(25) << data[2] << "|"
<< setw(10) << data[3] << "|"
<< resetiosflags(ios::right) << endl;
cout << divider << endl;
return 1;
}
string number_to_string(int number)
int string_to_number(string str)
std::string zfill(std::string data, int length, char fill = '0')
std::string zfill(int data, int length, char fill = '0')
string trade_id = zfill(1, 8);
cout << trade_id << endl;
// 00000001
string toLowerCase(string str)
class User {
public:
string username = "unknown";
string role = "saleperson";
string password = "unknown";
string phone = "unknown";
int login_status;
User(string username, string password);
void init_user();
};
#include "User.h"
class StatusContainer
{
public:static User current_user;
};
User StatusContainer::current_user = User("unknown", "unknown");