From 936d7a95ebc45194d97652475a1876db58711d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory?= Date: Wed, 16 Jun 2010 19:15:49 +0200 Subject: [PATCH] wip --- init.sql | 10 ++++---- model/Database.cpp | 5 ++++ model/User.h | 3 ++- view/AccountPanel.cpp | 55 ++++++++++++++++++++++++++++++------------- view/AccountPanel.h | 2 +- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/init.sql b/init.sql index af9ca9b..c8261fe 100644 --- a/init.sql +++ b/init.sql @@ -1,7 +1,7 @@ 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_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)); +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 preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), 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"); @@ -18,10 +18,10 @@ INSERT INTO default_preference ("type", "name", "value") VALUES ("category_color 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_amount("id", "account", "year", "month", "amount") VALUES("0", "0", "2010", "5", "1000"); -INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1"); -INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("1", "0", "0", "2010", "5", "1", "-56", "Opé 2", "2", "0"); -INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("2", "0", "0", "2010", "5", "8", "12", "Opé 3", "3", "0"); -INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("3", "0", "0", "2010", "5", "29", "-2056", "Opé 4", "4", "0"); +INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("0", "0", "0", "2010", "5", "0", "1234", "Opé 1", "1", "1", "0"); +INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost", "checked") VALUES ("1", "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 ("2", "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 ("3", "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 preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Courses"); INSERT INTO preference ("user", "type", "name", "value") VALUES ("0", "category", "name", "Loisirs"); diff --git a/model/Database.cpp b/model/Database.cpp index 93b97e1..8151210 100644 --- a/model/Database.cpp +++ b/model/Database.cpp @@ -251,6 +251,7 @@ void Database::LoadYear(User* user, int year) op.description = set.GetAsString(_("description")); op.category = set.GetAsString(_("category")); op.fix_cost = set.GetBool(_("fix_cost")); + op.checked = set.GetBool(_("checked")); (*user->_operations[op.year])[op.month].push_back(op); } @@ -291,6 +292,10 @@ void Database::UpdateOperation(struct operation op) req += _(", amount='") + wxString::Format(_("%.2lf"), op.amount) + _("'"); req += _(", description=\"") + op.description + _("\""); req += _(", category='") + op.category + _("'"); + if (op.checked) + req += _(", checked='1'"); + else + req += _(", checked='0'"); req += _(" WHERE id='") + op.id + _("'"); //std::cout << req.mb_str() << "\n"; diff --git a/model/User.h b/model/User.h index f38a7a6..1d09709 100644 --- a/model/User.h +++ b/model/User.h @@ -14,7 +14,8 @@ struct operation { wxString description; wxString category; bool fix_cost; - wxString account; + wxString account; + bool checked; } ; struct Account { diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 972a1c4..6f70e58 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -293,7 +293,7 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, NUMBER_COLS_O _grid->AutoSizeColumn(DATE, false); _grid->AutoSizeColumn(ACCOUNT, false); _grid->AutoSizeColumn(DELETE, false); - _grid->AutoSizeColumn(VIEW, false); + _grid->AutoSizeColumn(CHECKED, false); InitAccountsGrid(user, month, year); @@ -307,6 +307,8 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix { std::vector::iterator it; int curLine, curWeek, week, i; + int r, g, b; + wxColour color; _grid->InsertRows(line, 1); @@ -339,10 +341,21 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix _grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category)); _grid->SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ()); _grid->SetCellEditor(line, DELETE, new wxGridCellBoolEditor ()); - _grid->SetCellRenderer(line, VIEW, new wxGridCellBoolRenderer ()); - _grid->SetCellEditor(line, VIEW, new wxGridCellBoolEditor ()); + _grid->SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); + _grid->SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ()); - SET_ROW_COLOR(line, user->_preferences._colors[user->GetCategoryName(op->category)]); + color = user->_preferences._colors[user->GetCategoryName(op->category)]; + + if (op->checked) + { + r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; + g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; + b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; + color.Set(r, g, b, color.Alpha()); + _grid->SetCellValue(line, CHECKED, _("1")); + } + + SET_ROW_COLOR(line, color); } else { @@ -356,7 +369,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix _grid->SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE); _grid->SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE); _grid->SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - _grid->SetCellAlignment(line, VIEW, wxALIGN_CENTRE, wxALIGN_CENTRE); + _grid->SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE); if (op) { @@ -496,7 +509,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) int row = event.GetRow()-1; int col = event.GetCol(); struct operation new_op, cur_op; - int op_complete = 5, i; + int op_complete = 6, i; wxString value ; wxDateTime date; bool need_insertion = false, fix_op=false; @@ -560,28 +573,36 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) op_complete--; } - if (col == VIEW || col == CATEGORY) + value = _grid->GetCellValue(event.GetRow(), CHECKED); + if (value != _("")) { - color = _grid->GetCellBackgroundColour(event.GetRow(), col); + new_op.checked = (value == _("1")); + op_complete--; + } - if (_grid->GetCellValue(event.GetRow(), col) == _("1")) + if (col == CHECKED || col == CATEGORY) + { + color = user->_preferences._colors[user->GetCategoryName(new_op.category)]; + + if (new_op.checked) { r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; color.Set(r, g, b, color.Alpha()); } - else - { - color = user->_preferences._colors[user->GetCategoryName(new_op.category)]; - } SET_ROW_COLOR(event.GetRow(), color); + } - inModification = false; - - if (col == VIEW) - return ; + if (col == DELETE) + { + wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_op.description, _("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) + { + _grid->SetCellValue(event.GetRow(), event.GetCol(), _("0")); + return; + } } // Penser au fix implosif diff --git a/view/AccountPanel.h b/view/AccountPanel.h index 3045a90..320e32e 100644 --- a/view/AccountPanel.h +++ b/view/AccountPanel.h @@ -17,7 +17,7 @@ #define DEFAULT_FONT_SIZE 12 #define DEFAULT_FONT(font_name) wxFont font_name(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT_NAME); -enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, VIEW, NUMBER_COLS_OPS}; +enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS}; enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS}; enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS};