Change category representation into Database and fix two bug for category deletion and account creation. There is still bugs during account deletion
This commit is contained in:
parent
7bdf6bd1e4
commit
e08865e01f
|
@ -139,27 +139,19 @@ wxString KissCount::AddCategory(struct category category)
|
||||||
id = _db->AddCategory(_user, category);
|
id = _db->AddCategory(_user, category);
|
||||||
category.id = id;
|
category.id = id;
|
||||||
|
|
||||||
_user->_preferences._categories.push_back(category);
|
_user->_categories.push_back(category);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KissCount::UpdateCategory(wxString oldName, struct category category)
|
void KissCount::UpdateCategory(struct category category)
|
||||||
{
|
{
|
||||||
wxString color;
|
_db->UpdateCategory(category);
|
||||||
std::vector<struct category>::iterator it;
|
|
||||||
|
|
||||||
color = _("#") ;
|
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
||||||
color += wxString::Format(_("%02X"), category.color.Red());
|
if (_user->_categories[i].id == category.id)
|
||||||
color += wxString::Format(_("%02X"), category.color.Green());
|
|
||||||
color += wxString::Format(_("%02X"), category.color.Blue());
|
|
||||||
|
|
||||||
_db->UpdateCategory(_user, oldName, category.name, color);
|
|
||||||
|
|
||||||
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
|
|
||||||
if (_user->_preferences._categories[i].name == oldName)
|
|
||||||
{
|
{
|
||||||
_user->_preferences._categories[i] = category;
|
_user->_categories[i] = category;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,10 +160,10 @@ void KissCount::DeleteCategory(struct category category)
|
||||||
{
|
{
|
||||||
_db->DeleteCategory(_user, category);
|
_db->DeleteCategory(_user, category);
|
||||||
|
|
||||||
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
|
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
||||||
if (_user->_preferences._categories[i].name == category.name)
|
if (_user->_categories[i].id == category.id)
|
||||||
{
|
{
|
||||||
_user->_preferences._categories.erase(_user->_preferences._categories.begin()+i);
|
_user->_categories.erase(_user->_categories.begin()+i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class KissCount
|
||||||
void DeleteAccount(struct Account ac);
|
void DeleteAccount(struct Account ac);
|
||||||
|
|
||||||
wxString AddCategory(struct category category);
|
wxString AddCategory(struct category category);
|
||||||
void UpdateCategory(wxString oldName, struct category category);
|
void UpdateCategory(struct category category);
|
||||||
void DeleteCategory(struct category category);
|
void DeleteCategory(struct category category);
|
||||||
|
|
||||||
std::map<int, std::vector<int> > GetAllOperations();
|
std::map<int, std::vector<int> > GetAllOperations();
|
||||||
|
|
40
init.sql
40
init.sql
|
@ -1,19 +1,19 @@
|
||||||
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
|
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
|
||||||
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), default_account CHAR(1));
|
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), default_account CHAR(1));
|
||||||
CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT);
|
CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT);
|
||||||
CREATE TABLE operation(id INTEGER PRIMARY KEY, user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount FLOAT, description VARCHAR(255), category REFERENCES preference(id), fix_cost CHAR(1), checked CHAR(1));
|
CREATE TABLE operation(id INTEGER PRIMARY KEY, user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount FLOAT, description VARCHAR(255), category REFERENCES category(id), fix_cost CHAR(1), checked CHAR(1));
|
||||||
CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
|
CREATE TABLE category(id INTEGER PRIMARY KEY, user REFERENCES user(id), parent REFERENCES category(id), name VARCHAR(255), color VARCHAR(255), font VARCHAR(255));
|
||||||
|
CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), value VARCHAR(255));
|
||||||
CREATE TABLE default_preference(id INTEGER PRIMARY KEY, type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
|
CREATE TABLE default_preference(id INTEGER PRIMARY KEY, type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Fixe");
|
CREATE TABLE default_category(id INTEGER PRIMARY KEY, parent REFERENCES category(id), name VARCHAR(255), color VARCHAR(255), font VARCHAR(255));
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Courses");
|
-- INSERT INTO default_preference ("name", "value") VALUES ("category", "name", "Fixe");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Loisirs");
|
-- INSERT INTO default_preference ("name", "value") VALUES ("category", "name", "Courses");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Frais de fonctionnement");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Fixe", "#FFFF99", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category", "name", "Exceptionnel");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Courses", "#3DEB3D", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Fixe", "#FFFF99");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Loisirs", "#3DEB3D", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Courses", "#3DEB3D");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Frais de fonctionnement", "#3DEB3D", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Loisirs", "#3DEB3D");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Exceptionnel", "#3DEB3D", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Frais de fonctionnement", "#3DEB3D");
|
INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Autre", "#3DEB3D", "");
|
||||||
INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color", "Exceptionnel", "#3DEB3D");
|
|
||||||
-- No password
|
-- No password
|
||||||
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||||
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
|
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte Courant", "000" , "0", "1");
|
||||||
|
@ -30,13 +30,9 @@ INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount"
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
|
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("5", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0", "0");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
|
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("6", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0", "1");
|
||||||
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("7", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
|
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("7", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0", "0");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Fixe");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Fixe", "#FFFF99", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Courses");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Courses", "#3DEB3D", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Loisirs");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Loisirs", "#3DEB3D", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Frais de fonctionnement");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Frais de fonctionnement", "#3DEB3D", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Exceptionnel");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Exceptionnel", "#3DEB3D", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Fixe", "#FFFF99");
|
INSERT INTO category ("user", "parent", "name", "color", "font") VALUES ("0", "0", "Autre", "#3DEB3D", "");
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Courses", "#3DEB3D");
|
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Loisirs", "#3DEB3D");
|
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Frais de fonctionnement", "#3DEB3D");
|
|
||||||
INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category_color", "Exceptionnel", "#3DEB3D");
|
|
||||||
|
|
|
@ -224,34 +224,29 @@ User* Database::LoadUser(wxString name)
|
||||||
set.Finalize();
|
set.Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
req = _("SELECT id, value FROM preference WHERE type='category' AND name='name' AND user='") + user->_id + _("' ORDER BY value ASC");
|
req = _("SELECT * FROM category WHERE user='") + user->_id + _("' ORDER BY name ASC");
|
||||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||||
|
|
||||||
while (set.NextRow())
|
while (set.NextRow())
|
||||||
{
|
{
|
||||||
category.id = set.GetAsString(_("id"));
|
category.id = set.GetAsString(_("id"));
|
||||||
category.name = set.GetAsString(_("value"));
|
category.parent = set.GetAsString(_("parent"));
|
||||||
|
category.name = set.GetAsString(_("name"));
|
||||||
|
category.color = wxColour(set.GetAsString(_("color")));
|
||||||
|
category.font = set.GetAsString(_("font"));
|
||||||
if (category.name != _("Fixe"))
|
if (category.name != _("Fixe"))
|
||||||
user->_preferences._categories.push_back(category);
|
user->_categories.push_back(category);
|
||||||
else
|
else
|
||||||
user->_preferences._categories.insert(user->_preferences._categories.begin(), category);
|
user->_categories.insert(user->_categories.begin(), category);
|
||||||
}
|
}
|
||||||
|
|
||||||
set.Finalize();
|
set.Finalize();
|
||||||
|
|
||||||
req = _("SELECT name, value FROM preference WHERE type='category_color' AND user='") + user->_id + _("' ORDER BY value ASC");
|
req = _("SELECT name, value FROM preference WHERE user='") + user->_id + _("' ORDER BY value ASC");
|
||||||
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;});
|
||||||
|
|
||||||
while (set.NextRow())
|
while (set.NextRow())
|
||||||
{
|
user->_preferences[set.GetAsString(_("name"))] = 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();
|
set.Finalize();
|
||||||
|
|
||||||
|
@ -543,28 +538,18 @@ wxString Database::AddCategory(User* user, struct category category)
|
||||||
color += wxString::Format(_("%02X"), category.color.Green());
|
color += wxString::Format(_("%02X"), category.color.Green());
|
||||||
color += wxString::Format(_("%02X"), category.color.Blue());
|
color += wxString::Format(_("%02X"), category.color.Blue());
|
||||||
|
|
||||||
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
req = _("INSERT INTO category ('user', 'parent', 'name', 'color', font) VALUES ('") ;
|
||||||
req += user->_id + _("'");
|
req += user->_id + _("'");
|
||||||
req += _(", 'category'");
|
req += _(", '") + category.parent + _("'");
|
||||||
req += _(", 'name'");
|
|
||||||
req += _(", '") + category.name + _("'");
|
|
||||||
req += _(")");
|
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
|
||||||
|
|
||||||
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
|
||||||
req += user->_id + _("'");
|
|
||||||
req += _(", 'category_color'");
|
|
||||||
req += _(", '") + category.name + _("'");
|
req += _(", '") + category.name + _("'");
|
||||||
req += _(", '") + color + _("'");
|
req += _(", '") + color + _("'");
|
||||||
|
req += _(", '") + category.font + _("'");
|
||||||
req += _(")");
|
req += _(")");
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||||
|
|
||||||
req = _("SELECT id FROM preference WHERE user='") + user->_id + _("'") ;
|
req = _("SELECT id FROM preference WHERE user='") + user->_id + _("'") ;
|
||||||
req += _(" AND type='category'");
|
req += _(" AND name='") + category.name + _("'");
|
||||||
req += _(" AND name='name'");
|
|
||||||
req += _(" AND value='") + category.name + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_QUERY(req , set, _("0"));
|
EXECUTE_SQL_QUERY(req , set, _("0"));
|
||||||
|
|
||||||
|
@ -578,57 +563,37 @@ wxString Database::AddCategory(User* user, struct category category)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::UpdateCategory(User* user, wxString oldName, wxString name, wxString color)
|
void Database::UpdateCategory(struct category category)
|
||||||
{
|
{
|
||||||
wxString req;
|
wxString req;
|
||||||
|
wxString color;
|
||||||
|
|
||||||
if (oldName != name)
|
color = _("#") ;
|
||||||
{
|
color += wxString::Format(_("%02X"), category.color.Red());
|
||||||
req = _("UPDATE preference SET ") ;
|
color += wxString::Format(_("%02X"), category.color.Green());
|
||||||
req += _("value='") + name + _("'");
|
color += wxString::Format(_("%02X"), category.color.Blue());
|
||||||
req += _(" WHERE user='") + user->_id + _("'");
|
|
||||||
req += _(" AND type='category'");
|
|
||||||
req += _(" AND name='name'");
|
|
||||||
req += _(" AND value='") + oldName + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
req = _("UPDATE category SET") ;
|
||||||
}
|
req += _(" parent='") + category.parent + _("'");
|
||||||
|
req += _(", name='") + category.name + _("'");
|
||||||
|
req += _(", color='") + color + _("'");
|
||||||
|
req += _(", font='") + category.font + _("'");
|
||||||
|
req += _(" WHERE id='") + category.id + _("'");
|
||||||
|
|
||||||
req = _("UPDATE preference SET ") ;
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
req += _("value='") + color + _("'");
|
|
||||||
req += _(" WHERE user='") + user->_id + _("'");
|
|
||||||
req += _(" AND type='category_color'");
|
|
||||||
req += _(" AND name='") + oldName + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
|
||||||
|
|
||||||
if (oldName != name)
|
|
||||||
{
|
|
||||||
req = _("UPDATE preference SET ") ;
|
|
||||||
req += _("name='") + name + _("'");
|
|
||||||
req += _(" WHERE user='") + user->_id + _("'");
|
|
||||||
req += _(" AND type='category_color'");
|
|
||||||
req += _(" AND name='") + oldName + _("'");
|
|
||||||
req += _(" AND value='") + color + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::DeleteCategory(User* user, struct category category)
|
void Database::DeleteCategory(User* user, struct category category)
|
||||||
{
|
{
|
||||||
wxString req;
|
wxString req;
|
||||||
|
|
||||||
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
|
req = _("DELETE FROM category WHERE id='") + category.id + _("'");
|
||||||
req += _(" AND type='category'");
|
|
||||||
req += _(" AND name='name'");
|
|
||||||
req += _(" AND value='") + category.name + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
|
req = _("UPDATE category SET") ;
|
||||||
req += _(" AND type='category_color'");
|
req += _(" parent='0'");
|
||||||
req += _(" AND name='") + category.name + _("'");
|
req += _(" WHERE parent='") + category.id + _("'");
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
}
|
}
|
||||||
|
@ -810,10 +775,9 @@ void Database::NewUser(wxString name)
|
||||||
|
|
||||||
while (set.NextRow())
|
while (set.NextRow())
|
||||||
{
|
{
|
||||||
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
req = _("INSERT INTO preference ('user', 'name', 'value') VALUES ('") ;
|
||||||
req += id + _("'");
|
req += id + _("'");
|
||||||
req += _(", '") + set.GetAsString(_("type")) + _("'");
|
req += _(", '") + set.GetAsString(_("type")) + _("'");
|
||||||
req += _(", '") + set.GetAsString(_("name")) + _("'");
|
|
||||||
req += _(", '") + set.GetAsString(_("value")) + _("'");
|
req += _(", '") + set.GetAsString(_("value")) + _("'");
|
||||||
req += _(")");
|
req += _(")");
|
||||||
|
|
||||||
|
@ -822,6 +786,25 @@ void Database::NewUser(wxString name)
|
||||||
|
|
||||||
set.Finalize();
|
set.Finalize();
|
||||||
|
|
||||||
|
req = _("SELECT * FROM default_category");
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req, set,);
|
||||||
|
|
||||||
|
while (set.NextRow())
|
||||||
|
{
|
||||||
|
req = _("INSERT INTO category ('user', 'parent', 'name', 'color', 'font') VALUES ('") ;
|
||||||
|
req += id + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("parent")) + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("name")) + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("color")) + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("font")) + _("'");
|
||||||
|
req += _(")");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
set.Finalize();
|
||||||
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -861,6 +844,9 @@ void Database::KillMe(User* user)
|
||||||
req = _("DELETE FROM account WHERE user='") + user->_id + _("'");
|
req = _("DELETE FROM account WHERE user='") + user->_id + _("'");
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
req = _("DELETE FROM category WHERE user='") + user->_id + _("'");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
req = _("DELETE FROM user WHERE id='") + user->_id + _("'");
|
req = _("DELETE FROM user WHERE id='") + user->_id + _("'");
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Database
|
||||||
void DeleteAccount(struct Account ac);
|
void DeleteAccount(struct Account ac);
|
||||||
|
|
||||||
wxString AddCategory(User* user, struct category category);
|
wxString AddCategory(User* user, struct category category);
|
||||||
void UpdateCategory(User* user, wxString oldName, wxString name, wxString color);
|
void UpdateCategory(struct category category);
|
||||||
void DeleteCategory(User* user, struct category category);
|
void DeleteCategory(User* user, struct category category);
|
||||||
|
|
||||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#include "Preferences.h"
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
#ifndef PREFERENCES_H
|
|
||||||
#define PREFERENCES_H
|
|
||||||
|
|
||||||
#include <wx/colour.h>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
struct category
|
|
||||||
{
|
|
||||||
wxString id;
|
|
||||||
wxString name;
|
|
||||||
wxColour color;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Preferences
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::vector<struct category> _categories;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -19,19 +19,23 @@ struct category User::GetCategory(wxString catId)
|
||||||
struct category cat;
|
struct category cat;
|
||||||
std::vector<category>::iterator it;
|
std::vector<category>::iterator it;
|
||||||
|
|
||||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||||
if (it->id == catId)
|
if (it->id == catId)
|
||||||
return *it;
|
return *it;
|
||||||
|
|
||||||
cat.id = _("0");
|
cat.id = _("0");
|
||||||
return cat;
|
cat.parent = _("0");
|
||||||
|
cat.name = _("Unknown");
|
||||||
|
cat.font = _("");
|
||||||
|
cat.color = wxColour(0xFF, 0xFF, 0xFF);
|
||||||
|
|
||||||
|
return cat;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString User::GetCategoryName(wxString catId)
|
wxString User::GetCategoryName(wxString catId)
|
||||||
{
|
{
|
||||||
std::vector<category>::iterator it;
|
std::vector<category>::iterator it;
|
||||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||||
if (it->id == catId)
|
if (it->id == catId)
|
||||||
return it->name;
|
return it->name;
|
||||||
|
|
||||||
|
@ -41,7 +45,7 @@ wxString User::GetCategoryName(wxString catId)
|
||||||
wxString User::GetCategoryId(wxString catName)
|
wxString User::GetCategoryId(wxString catName)
|
||||||
{
|
{
|
||||||
std::vector<category>::iterator it;
|
std::vector<category>::iterator it;
|
||||||
for (it=_preferences._categories.begin(); it !=_preferences._categories.end(); it++)
|
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||||
if (it->name == catName)
|
if (it->name == catName)
|
||||||
return it->id;
|
return it->id;
|
||||||
|
|
||||||
|
@ -70,7 +74,7 @@ wxString User::GetAccountId(wxString accountName)
|
||||||
|
|
||||||
int User::GetCategoriesNumber()
|
int User::GetCategoriesNumber()
|
||||||
{
|
{
|
||||||
return _preferences._categories.size();
|
return _categories.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int User::GetAccountsNumber()
|
int User::GetAccountsNumber()
|
||||||
|
|
40
model/User.h
40
model/User.h
|
@ -4,27 +4,36 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include "Preferences.h"
|
#include <wx/colour.h>
|
||||||
|
|
||||||
struct operation {
|
struct operation {
|
||||||
wxString id;
|
wxString id;
|
||||||
unsigned int day;
|
unsigned int day;
|
||||||
unsigned int month;
|
unsigned int month;
|
||||||
unsigned int year;
|
unsigned int year;
|
||||||
double amount;
|
double amount;
|
||||||
wxString description;
|
wxString description;
|
||||||
wxString category;
|
wxString category;
|
||||||
bool fix_cost;
|
bool fix_cost;
|
||||||
wxString account;
|
wxString account;
|
||||||
bool checked;
|
bool checked;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
struct Account {
|
struct Account {
|
||||||
wxString id;
|
wxString id;
|
||||||
wxString name;
|
wxString name;
|
||||||
wxString number;
|
wxString number;
|
||||||
bool shared;
|
bool shared;
|
||||||
bool _default;
|
bool _default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct category
|
||||||
|
{
|
||||||
|
wxString id;
|
||||||
|
wxString parent;
|
||||||
|
wxString name;
|
||||||
|
wxColour color;
|
||||||
|
wxString font;
|
||||||
};
|
};
|
||||||
|
|
||||||
class User
|
class User
|
||||||
|
@ -37,7 +46,8 @@ public:
|
||||||
wxString _password;
|
wxString _password;
|
||||||
std::vector<Account> _accounts;
|
std::vector<Account> _accounts;
|
||||||
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* > _operations;
|
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* > _operations;
|
||||||
Preferences _preferences;
|
std::vector<struct category> _categories;
|
||||||
|
std::map<wxString, wxString> _preferences;
|
||||||
|
|
||||||
struct category GetCategory(wxString catId);
|
struct category GetCategory(wxString catId);
|
||||||
wxString GetCategoryName(wxString catId);
|
wxString GetCategoryName(wxString catId);
|
||||||
|
|
|
@ -65,8 +65,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*
|
||||||
_accounts[i] = accountIt->name;
|
_accounts[i] = accountIt->name;
|
||||||
|
|
||||||
_categories = new wxString[user->GetCategoriesNumber()] ;
|
_categories = new wxString[user->GetCategoriesNumber()] ;
|
||||||
for(i=0, categoryIt = user->_preferences._categories.begin();
|
for(i=0, categoryIt = user->_categories.begin();
|
||||||
categoryIt != user->_preferences._categories.end();
|
categoryIt != user->_categories.end();
|
||||||
categoryIt++, i++)
|
categoryIt++, i++)
|
||||||
{
|
{
|
||||||
_categories[i] = categoryIt->name ;
|
_categories[i] = categoryIt->name ;
|
||||||
|
@ -319,7 +319,10 @@ void AccountPanel::ShowMonth(int month, int year)
|
||||||
if (month == -1)
|
if (month == -1)
|
||||||
{
|
{
|
||||||
monthIt = user->_operations[year]->begin();
|
monthIt = user->_operations[year]->begin();
|
||||||
month = monthIt->first;
|
if (user->_operations[year]->size() == 0 && year == curDate.GetYear())
|
||||||
|
month = curDate.GetMonth();
|
||||||
|
else
|
||||||
|
month = monthIt->first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ void PreferencesPanel::InitCategories(User* user)
|
||||||
_categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font"));
|
_categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font"));
|
||||||
_categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete"));
|
_categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete"));
|
||||||
|
|
||||||
for (it=user->_preferences._categories.begin(); it!=user->_preferences._categories.end(); it++, curLine++)
|
for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++)
|
||||||
{
|
{
|
||||||
_categoriesGrid->AppendRows();
|
_categoriesGrid->AppendRows();
|
||||||
|
|
||||||
|
@ -337,11 +337,13 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||||
}
|
}
|
||||||
|
|
||||||
new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col);
|
new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col);
|
||||||
|
new_cat.font = _("");
|
||||||
|
new_cat.parent = _("0");
|
||||||
|
|
||||||
// Categories modification
|
// Categories modification
|
||||||
if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
|
if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
|
||||||
{
|
{
|
||||||
new_cat.id = user->_preferences._categories[row].id;
|
new_cat.id = user->_categories[row].id;
|
||||||
if (col == CATEGORY_DELETE)
|
if (col == CATEGORY_DELETE)
|
||||||
{
|
{
|
||||||
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_cat.name, _("KissCount"), wxYES_NO);
|
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_cat.name, _("KissCount"), wxYES_NO);
|
||||||
|
@ -352,7 +354,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_categoriesGrid->DeleteRows(row, 1);
|
_categoriesGrid->DeleteRows(row, 1);
|
||||||
_kiss->DeleteCategory(user->_preferences._categories[row]);
|
_kiss->DeleteCategory(user->_categories[row]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wxUI->Layout();
|
_wxUI->Layout();
|
||||||
|
@ -360,7 +362,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||||
inModification = false;
|
inModification = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_kiss->UpdateCategory(user->_preferences._categories[row].name, new_cat);
|
_kiss->UpdateCategory(new_cat);
|
||||||
}
|
}
|
||||||
// New category
|
// New category
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user