Move categories from map to vector
This commit is contained in:
@@ -148,6 +148,8 @@ User* Database::LoadUser(wxString name)
|
||||
wxString req;
|
||||
User* user;
|
||||
struct Account account;
|
||||
struct category category;
|
||||
|
||||
std::vector<Account>::iterator it;
|
||||
|
||||
req = _("SELECT * FROM user WHERE name='") + name + _("'");
|
||||
@@ -204,7 +206,14 @@ User* Database::LoadUser(wxString name)
|
||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||
|
||||
while (set.NextRow())
|
||||
user->_preferences._categories[set.GetAsString(_("id"))] = set.GetAsString(_("value"));
|
||||
{
|
||||
category.id = set.GetAsString(_("id"));
|
||||
category.name = set.GetAsString(_("value"));
|
||||
if (category.name != _("Fixe"))
|
||||
user->_preferences._categories.push_back(category);
|
||||
else
|
||||
user->_preferences._categories.insert(user->_preferences._categories.begin(), category);
|
||||
}
|
||||
|
||||
set.Finalize();
|
||||
|
||||
@@ -212,7 +221,15 @@ User* Database::LoadUser(wxString name)
|
||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||
|
||||
while (set.NextRow())
|
||||
user->_preferences._colors[set.GetAsString(_("name"))] = wxColour(set.GetAsString(_("value")));
|
||||
{
|
||||
std::vector<struct category>::iterator it;
|
||||
for (it=user->_preferences._categories.begin(); it !=user->_preferences._categories.end(); it++)
|
||||
if (it->name == set.GetAsString(_("name")))
|
||||
{
|
||||
it->color = wxColour(set.GetAsString(_("value")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set.Finalize();
|
||||
|
||||
@@ -437,27 +454,50 @@ void Database::DeleteAccount(struct Account ac)
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
void Database::AddCategory(User* user, wxString name, wxString color)
|
||||
wxString Database::AddCategory(User* user, struct category category)
|
||||
{
|
||||
wxString req;
|
||||
wxString req, res;
|
||||
wxSQLite3ResultSet set;
|
||||
wxString color;
|
||||
|
||||
color = _("#") ;
|
||||
color += wxString::Format(_("%02X"), category.color.Red());
|
||||
color += wxString::Format(_("%02X"), category.color.Green());
|
||||
color += wxString::Format(_("%02X"), category.color.Blue());
|
||||
|
||||
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
||||
req += user->_id + _("'");
|
||||
req += _(", 'category'");
|
||||
req += _(", 'name'");
|
||||
req += _(", '") + name + _("'");
|
||||
req += _(", '") + category.name + _("'");
|
||||
req += _(")");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||
|
||||
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
||||
req += user->_id + _("'");
|
||||
req += _(", 'category_color'");
|
||||
req += _(", '") + name + _("'");
|
||||
req += _(", '") + category.name + _("'");
|
||||
req += _(", '") + color + _("'");
|
||||
req += _(")");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||
|
||||
req = _("SELECT id FROM preference WHERE user='") + user->_id + _("'") ;
|
||||
req += _(" AND type='category'");
|
||||
req += _(" AND name='name'");
|
||||
req += _(" AND value='") + category.name + _("'");
|
||||
|
||||
EXECUTE_SQL_QUERY(req , set, _("0"));
|
||||
|
||||
if (set.NextRow())
|
||||
res = set.GetAsString(_("id"));
|
||||
else
|
||||
res = _("0");
|
||||
|
||||
set.Finalize();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Database::UpdateCategory(User* user, wxString oldName, wxString name, wxString color)
|
||||
@@ -497,19 +537,19 @@ void Database::UpdateCategory(User* user, wxString oldName, wxString name, wxStr
|
||||
}
|
||||
}
|
||||
|
||||
void Database::DeleteCategory(User* user, wxString name)
|
||||
void Database::DeleteCategory(User* user, struct category category)
|
||||
{
|
||||
wxString req;
|
||||
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
|
||||
req += _(" AND type='category'");
|
||||
req += _(" AND name='name'");
|
||||
req += _(" AND value='") + name + _("'");
|
||||
req += _(" AND value='") + category.name + _("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
|
||||
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
|
||||
req += _(" AND type='category_color'");
|
||||
req += _(" AND name='") + name + _("'");
|
||||
req += _(" AND name='") + category.name + _("'");
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ class Database
|
||||
void UpdateAccount(struct Account ac);
|
||||
void DeleteAccount(struct Account ac);
|
||||
|
||||
void AddCategory(User* user, wxString name, wxString color);
|
||||
wxString AddCategory(User* user, struct category category);
|
||||
void UpdateCategory(User* user, wxString oldName, wxString name, wxString color);
|
||||
void DeleteCategory(User* user, wxString name);
|
||||
void DeleteCategory(User* user, struct category category);
|
||||
|
||||
private:
|
||||
wxSQLite3Database _db;
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
#include "Preferences.h"
|
||||
|
||||
|
||||
@@ -2,13 +2,19 @@
|
||||
#define PREFERENCES_H
|
||||
|
||||
#include <wx/colour.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
struct category
|
||||
{
|
||||
wxString id;
|
||||
wxString name;
|
||||
wxColour color;
|
||||
};
|
||||
|
||||
class Preferences
|
||||
{
|
||||
public:
|
||||
std::map<wxString, wxColour> _colors;
|
||||
std::map<wxString, wxString> _categories;
|
||||
std::vector<category> _categories;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,19 +14,36 @@ User::~User()
|
||||
}
|
||||
}
|
||||
|
||||
struct category User::GetCategory(wxString catId)
|
||||
{
|
||||
struct category cat;
|
||||
std::vector<category>::iterator it;
|
||||
|
||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
||||
if (it->id == catId)
|
||||
return *it;
|
||||
|
||||
cat.id = _("0");
|
||||
return cat;
|
||||
|
||||
}
|
||||
|
||||
wxString User::GetCategoryName(wxString catId)
|
||||
{
|
||||
if (_preferences._categories.find(catId) == _preferences._categories.end())
|
||||
return _("Unknown") ;
|
||||
return _preferences._categories[catId];
|
||||
std::vector<category>::iterator it;
|
||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
||||
if (it->id == catId)
|
||||
return it->name;
|
||||
|
||||
return _("Unknown") ;
|
||||
}
|
||||
|
||||
wxString User::GetCategoryId(wxString catName)
|
||||
{
|
||||
std::map<wxString, wxString>::iterator it;
|
||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
||||
if (it->second == catName)
|
||||
return it->first;
|
||||
std::vector<category>::iterator it;
|
||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
||||
if (it->name == catName)
|
||||
return it->id;
|
||||
|
||||
return _("0") ;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef USER_H
|
||||
#define USER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <wx/wx.h>
|
||||
#include "Preferences.h"
|
||||
@@ -38,6 +39,7 @@ public:
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* > _operations;
|
||||
Preferences _preferences;
|
||||
|
||||
struct category GetCategory(wxString catId);
|
||||
wxString GetCategoryName(wxString catId);
|
||||
wxString GetCategoryId(wxString catName);
|
||||
wxString GetAccountName(wxString accountId);
|
||||
|
||||
Reference in New Issue
Block a user