Implement Delete operation in AccountPanel contextual menu
Fix a bug in a SQL request Use nbCategories in AccountPanel to prevent buffer overflow
This commit is contained in:
parent
739ac0cbc2
commit
6c0c04cad5
|
@ -642,7 +642,7 @@ void Database::DeleteOperations(User* user, int month, int year)
|
|||
EXECUTE_SQL_UPDATE(req, );
|
||||
|
||||
it = user->_accounts.begin();
|
||||
req = "DELETE FROM operation WHERE (account IN('" + it->id;
|
||||
req = "DELETE FROM operation WHERE (account IN('" + QString::number(it->id);
|
||||
it++;
|
||||
for (;it != user->_accounts.end(); it++)
|
||||
{
|
||||
|
@ -653,7 +653,6 @@ void Database::DeleteOperations(User* user, int month, int year)
|
|||
req += " AND year='" + QString::number(year) + "'";
|
||||
if (month != -1)
|
||||
req += " AND month='" + QString::number(month) + "'";
|
||||
|
||||
EXECUTE_SQL_UPDATE(req, );
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
if (!query.exec(req)) \
|
||||
{ \
|
||||
QMessageBox::critical(0, _("Error"), _("Update failed !\n") + req); \
|
||||
std::cerr << __FUNCTION__ << "\n" ; \
|
||||
std::cerr << __FUNCTION__ << " " << __FILE__ << " " << __LINE__ << "\n" ; \
|
||||
std::cerr << req.toStdString() << "\n" ; \
|
||||
std::cerr << query.lastError().text().toStdString() << "\n" ; \
|
||||
code_if_fail; \
|
||||
|
|
|
@ -86,9 +86,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
|||
|
||||
nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
||||
|
||||
_dataset = new QStandardItemModel(user->GetCategoriesNumber(), 2, this);
|
||||
_categoriesValues = new double[user->GetCategoriesNumber()];
|
||||
for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||
_dataset = new QStandardItemModel(nbCategories, 2, this);
|
||||
_categoriesValues = new double[nbCategories];
|
||||
for(i=0; i<nbCategories; i++)
|
||||
{
|
||||
_categoriesValues[i] = 0.0;
|
||||
_dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]);
|
||||
|
@ -916,58 +916,72 @@ void AccountPanel::OnMenuGenerate()
|
|||
|
||||
void AccountPanel::OnMenuDelete()
|
||||
{
|
||||
// int month, year;
|
||||
// wxString message;
|
||||
// wxTreeItemId curNode, node ;
|
||||
// std::map<int, std::vector<int> > ops ;
|
||||
int month, year, i;
|
||||
QString message;
|
||||
QTreeWidgetItem* curNode, *node ;
|
||||
std::map<int, std::vector<int> > ops ;
|
||||
|
||||
GetTreeSelection(&month, &year);
|
||||
|
||||
// GetTreeSelection(&month, &year);
|
||||
ops = _kiss->GetAllOperations();
|
||||
|
||||
// ops = _kiss->GetAllOperations();
|
||||
if (ops.size() == 1 && (ops[year].size() == 1 || month == -1))
|
||||
{
|
||||
QMessageBox::critical(0, _("Error"), _("It must be at least one month !"));
|
||||
return;
|
||||
}
|
||||
|
||||
// if (ops.size() == 1 && (ops[year].size() == 1 || month == -1))
|
||||
// {
|
||||
// wxMessageBox(_("It must be at least one month !"), _("Error"), wxICON_ERROR | wxOK);
|
||||
// return;
|
||||
// }
|
||||
message = _("Are you sure want to delete ");
|
||||
if (month != -1)
|
||||
message += wxUI::months[month] + " ";
|
||||
message += QString::number(year);
|
||||
|
||||
// message = _("Are you sure want to delete ");
|
||||
// if (month != -1)
|
||||
// message += wxUI::months[month] + wxT(" ");
|
||||
// message += wxString::Format(wxT("%d"), year);
|
||||
message += _(" operations ?");
|
||||
|
||||
// message += _(" operations ?");
|
||||
if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
|
||||
return;
|
||||
|
||||
// wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO);
|
||||
// if (dialog.ShowModal() == wxID_NO)
|
||||
// return;
|
||||
curNode = _tree->currentItem();
|
||||
|
||||
// curNode = _tree.GetSelection();
|
||||
if (ops[year].size() == 1 && month != -1)
|
||||
curNode = curNode->parent();
|
||||
|
||||
// if (ops[year].size() == 1 && month != -1)
|
||||
// curNode = _tree.GetItemParent(curNode);
|
||||
_kiss->DeleteOperations(month, year);
|
||||
|
||||
// _kiss->DeleteOperations(month, year);
|
||||
i = _tree->indexOfTopLevelItem(curNode);
|
||||
if (i == -1)
|
||||
{
|
||||
node = _tree->itemBelow(curNode);
|
||||
|
||||
// node = _tree.GetNextSibling(curNode);
|
||||
if (!node)
|
||||
node = _tree->itemAbove(curNode);
|
||||
|
||||
// if (!node.IsOk())
|
||||
// node = _tree.GetPrevSibling(curNode);
|
||||
|
||||
// _tree.Delete(curNode);
|
||||
|
||||
// if (!node.IsOk())
|
||||
// ChangeUser();
|
||||
// else
|
||||
// {
|
||||
// _tree.SelectItem(node);
|
||||
// GetTreeSelection(&month, &year);
|
||||
// if (month == -1)
|
||||
// month = ops[year][0];
|
||||
// ShowMonth(month, year);
|
||||
// }
|
||||
// _wxUI->NeedReload();
|
||||
curNode->parent()->removeChild(curNode);
|
||||
_tree->setCurrentItem(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete _tree->takeTopLevelItem(i);
|
||||
if (i) i--;
|
||||
_tree->setCurrentItem(_tree->topLevelItem(i));
|
||||
curNode = _tree->topLevelItem(i);
|
||||
if (!curNode->childCount())
|
||||
LoadYear(curNode->text(0).toInt());
|
||||
_tree->setCurrentItem(curNode->child(curNode->childCount()-1));
|
||||
}
|
||||
|
||||
if (!node)
|
||||
ChangeUser();
|
||||
else
|
||||
{
|
||||
GetTreeSelection(&month, &year);
|
||||
if (month == -1)
|
||||
month = ops[year][0];
|
||||
ShowMonth(month, year);
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPanel::GenerateMonth(int month, int year)
|
||||
{
|
||||
QString s;
|
||||
|
|
|
@ -26,7 +26,6 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea
|
|||
int i, a, toSelect=-1;
|
||||
QDate curDate = QDate::currentDate();
|
||||
std::vector<int>::iterator monthIt;
|
||||
QString s;
|
||||
|
||||
// wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
gridLayout = new QGridLayout(this);
|
||||
|
@ -64,7 +63,7 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea
|
|||
|
||||
for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++)
|
||||
{
|
||||
_yearFrom->addItem(s.sprintf("%d", it->first));
|
||||
_yearFrom->addItem(QString::number(it->first));
|
||||
if (year == it->first)
|
||||
toSelect = i;
|
||||
}
|
||||
|
@ -91,12 +90,12 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea
|
|||
_yearFrom->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
for(i=2000; i<=2050; i++)
|
||||
_yearTo->addItem(s.sprintf("%d", i));
|
||||
for(i=curDate.year()-10; i<=curDate.year()+10; i++)
|
||||
_yearTo->addItem(QString::number(i));
|
||||
|
||||
if (year == -1)
|
||||
{
|
||||
_yearTo->setCurrentIndex(curDate.year()-2000);
|
||||
_yearTo->setCurrentIndex(9);
|
||||
_monthTo->setCurrentIndex(curDate.month());
|
||||
}
|
||||
else
|
||||
|
@ -104,7 +103,7 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea
|
|||
if (month == 11)
|
||||
year++;
|
||||
|
||||
_yearTo->setCurrentIndex(year-2000);
|
||||
_yearTo->setCurrentIndex(year-(curDate.year()-10));
|
||||
|
||||
if (month == -1)
|
||||
_monthTo->setCurrentIndex(0);
|
||||
|
|
|
@ -21,16 +21,13 @@
|
|||
|
||||
#include "DateDelegate.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
QWidget * DateDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
QComboBox* combo = new QComboBox(parent);
|
||||
QDate date(_year, _month, _day);
|
||||
QString s;
|
||||
|
||||
for(int i=0; i<date.daysInMonth(); i++)
|
||||
combo->addItem(s.sprintf("%d", i+1));
|
||||
combo->addItem(QString::number(i+1));
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user