Year/month changement ok
This commit is contained in:
@@ -15,7 +15,7 @@ EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
||||
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID)
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
|
||||
{
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
@@ -193,20 +193,31 @@ void AccountPanel::ChangeUser()
|
||||
int curYear = -1;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<operation> >* >::iterator it;
|
||||
wxDateTime curDate;
|
||||
wxTreeItemId rootNode, curNode;
|
||||
|
||||
_tree.DeleteAllItems();
|
||||
rootNode = _tree.AddRoot(_(""));
|
||||
|
||||
curDate.SetToCurrent();
|
||||
for(it = user->_operations.begin(); it != user->_operations.end(); it++)
|
||||
{
|
||||
if ((int)it->first <= curDate.GetYear())
|
||||
curYear = it->first;
|
||||
_tree.AddRoot(wxString::Format(wxT("%d"), it->first));
|
||||
{
|
||||
curYear = it->first;
|
||||
curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||
}
|
||||
else
|
||||
_tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||
}
|
||||
|
||||
if (curYear != -1)
|
||||
LoadYear(curYear);
|
||||
{
|
||||
_tree.SelectItem(curNode, true);
|
||||
LoadYear(curYear);
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPanel::LoadYear(int year)
|
||||
void AccountPanel::LoadYear(int year, bool showMonth)
|
||||
{
|
||||
User* user = _kiss->GetUser();
|
||||
int curMonth = -1;
|
||||
@@ -214,13 +225,14 @@ void AccountPanel::LoadYear(int year)
|
||||
wxDateTime curDate;
|
||||
wxTreeItemId parentNode, curMonthNode;
|
||||
|
||||
_curYear = year ;
|
||||
if (user->_operations[year] != NULL)
|
||||
if (user->_operations[year])
|
||||
{
|
||||
ShowMonth(year, 0);
|
||||
if (showMonth)
|
||||
ShowMonth(year, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
_curYear = year ;
|
||||
_kiss->LoadYear(year);
|
||||
|
||||
curDate.SetToCurrent();
|
||||
@@ -228,24 +240,24 @@ void AccountPanel::LoadYear(int year)
|
||||
|
||||
for (it = user->_operations[year]->begin(); it != user->_operations[year]->end(); it++)
|
||||
{
|
||||
if (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth())
|
||||
if (curMonth == -1 || (year == curDate.GetYear() && (int)it->first <= curDate.GetMonth()))
|
||||
{
|
||||
curMonth = it->first;
|
||||
curMonthNode = _tree.AppendItem(parentNode, months[it->first]);
|
||||
}
|
||||
else if(curMonth == -1)
|
||||
{
|
||||
curMonthNode = _tree.AppendItem(parentNode, months[it->first]);
|
||||
curMonth++;
|
||||
}
|
||||
else
|
||||
_tree.AppendItem(parentNode, months[it->first]);
|
||||
}
|
||||
|
||||
_tree.Expand(parentNode);
|
||||
_tree.SelectItem(curMonthNode, true);
|
||||
|
||||
ShowMonth(year, curMonth);
|
||||
if (showMonth)
|
||||
{
|
||||
_tree.SelectItem(curMonthNode, true);
|
||||
ShowMonth(year, curMonth);
|
||||
}
|
||||
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||
@@ -262,8 +274,34 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||
User* user = _kiss->GetUser();
|
||||
DEFAULT_FONT(font);
|
||||
std::vector<category>::iterator categoryIt;
|
||||
//wxGridCellChoiceEditor* categoryEditor, *accountEditor;
|
||||
std::map<unsigned int, std::vector<operation> >::iterator monthIt;
|
||||
wxDateTime curDate;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
if (month == -1)
|
||||
{
|
||||
// Near month
|
||||
if (year == curDate.GetYear())
|
||||
{
|
||||
for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++)
|
||||
{
|
||||
if ((int)monthIt->first <= curDate.GetMonth())
|
||||
{
|
||||
month = monthIt->first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// First month
|
||||
if (month == -1)
|
||||
{
|
||||
monthIt = user->_operations[year]->begin();
|
||||
month = monthIt->first;
|
||||
}
|
||||
}
|
||||
|
||||
_curYear = year;
|
||||
_curMonth = month;
|
||||
_wxUI->SetTitle(user->_name + _(" - ") + months[month] + _(" ") + wxString::Format(wxT("%d"), year));
|
||||
|
||||
@@ -275,7 +313,7 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||
|
||||
it = _curOperations->begin();
|
||||
|
||||
for (;it->fix_cost && it != _curOperations->end(); it++)
|
||||
for (;it != _curOperations->end() && it->fix_cost; it++)
|
||||
InsertOperation(user, &(*it), ++curLine, true);
|
||||
|
||||
InsertOperation(user, NULL, ++curLine, true);
|
||||
@@ -742,9 +780,65 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
|
||||
|
||||
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
||||
{
|
||||
ShowMonth(2010,4);
|
||||
// ShowMonth(2010,4);
|
||||
}
|
||||
|
||||
void AccountPanel::OnTreeChange(wxTreeEvent& event)
|
||||
{
|
||||
int month=-1, year;
|
||||
int i;
|
||||
wxString monthString;
|
||||
static bool inModification = false ;
|
||||
|
||||
if (inModification) return;
|
||||
|
||||
inModification = true;
|
||||
|
||||
monthString = _tree.GetItemText(event.GetItem());
|
||||
for (i=0; i<12; i++)
|
||||
if (monthString == months[i])
|
||||
{
|
||||
month = i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (month == -1)
|
||||
{
|
||||
year = wxAtoi(monthString);
|
||||
|
||||
// Error
|
||||
if (year == 0)
|
||||
{
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (year == _curYear)
|
||||
{
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// _tree.CollapseAll();
|
||||
// _tree.Expand(event.GetItem());
|
||||
LoadYear(year, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(event.GetItem())));
|
||||
|
||||
// Error
|
||||
if (year == 0)
|
||||
{
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (year != _curYear || month != _curMonth)
|
||||
{
|
||||
ShowMonth(year, month);
|
||||
}
|
||||
}
|
||||
|
||||
inModification = false;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
AccountPanel(KissCount* kiss, wxUI *parent);
|
||||
~AccountPanel();
|
||||
void ChangeUser();
|
||||
void LoadYear(int year);
|
||||
void LoadYear(int year, bool showMonth=true);
|
||||
void ShowMonth(int year, int month);
|
||||
|
||||
void OnOperationModified(wxGridEvent& event);
|
||||
|
||||
Reference in New Issue
Block a user