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