Replace GetDateFormat() method by GetDateLocalFormat() cause of Win32

Forgot to set start and end dates when adding an account
This commit is contained in:
Gregory Soutadé 2018-03-11 15:57:22 +01:00
parent b51c4d2d2d
commit e9ec135b27
7 changed files with 31 additions and 20 deletions

View File

@ -386,7 +386,12 @@ void KissCount::NewUser(const QString& name)
/*.shared = */false,
/*.blocked = */false,
/*._default = */true,
/*.is_owner = */true};
/*.is_owner = */true,
/* ._virtual = */false,
/* .hidden = */false,
/* .start_date = */QDate::currentDate(),
/* .end_date = */QDate::currentDate().addYears(50),
};
Category cat ;
_db->NewUser(name);
@ -717,12 +722,12 @@ QLocale* KissCount::GetLocale()
return _wxUI->GetLocale();
}
QString KissCount::GetDateFormat()
QString KissCount::GetDateLocalFormat()
{
return _wxUI->GetDateFormat();
return _wxUI->GetDateLocalFormat();
}
QString KissCount::FormatDate(int day, int month, int year)
{
return QDate(year, month, day).toString(_wxUI->GetDateFormat());
return QDate(year, month, day).toString(_wxUI->GetDateLocalFormat());
}

View File

@ -152,7 +152,7 @@ public:
bool ChangeDatabase(QString filename);
QLocale* GetLocale();
QString GetDateFormat();
QString GetDateLocalFormat();
QString FormatDate(int day, int month, int year);
private:

View File

@ -90,16 +90,15 @@ void Database::CreateDatabase()
QFile file(sPath);
QString message;
message = _("A new database will be created, continue ?");
message = _("A new database will be created, continue ?");
if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
throw std::string("Abort") ;
if (!init_script.exists() || !init_script.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::critical(0, _("Error"), _(INIT_SCRIPT " not found, aborting"));
QMessageBox::critical(0, _("Error"), INIT_SCRIPT + _(" not found, aborting"));
throw "init.sql not found, aborting";
}
if (!dirname.exists() && !dirname.mkdir(dirname.absolutePath()))
{
QMessageBox::critical(0, _("Error"), _("Unable to Create ") + dirname.absolutePath() );
@ -784,8 +783,9 @@ int Database::AddAccount(User* user, Account& ac)
{
QString req;
QSqlQuery query(_db);
int id;
req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual', 'hidden') VALUES " ;
req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual', 'hidden') VALUES " ;
req += "('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8')";
req = req.arg(QString::number(user->_id), ac.name, ac.number, QString::number(ac.shared), QString::number(ac.blocked),
QString::number(ac._default), QString::number(ac._virtual), QString::number(ac.hidden));
@ -799,7 +799,13 @@ int Database::AddAccount(User* user, Account& ac)
return 0;
}
return query.lastInsertId().toInt();
id = query.lastInsertId().toInt();
req = "UPDATE account SET start='%1', end='%2' WHERE id='%3'";
req = req.arg(ac.start_date.toString("yyyy-MM-dd"), ac.end_date.toString("yyyy-MM-dd"), QString::number(id));
EXECUTE_SQL_UPDATE(req, 0);
return id;
}
void Database::UpdateAccount(Account& ac)

View File

@ -104,10 +104,10 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
_accountsGrid = new QTableWidget();
CalendarDelegate* calendarDelegate = new CalendarDelegate(this, &user->_accounts, true, _kiss->GetDateFormat());
CalendarDelegate* calendarDelegate = new CalendarDelegate(this, &user->_accounts, true, _kiss->GetDateLocalFormat());
_accountsGrid->setItemDelegateForColumn(ACCOUNT_START, calendarDelegate);
calendarDelegate = new CalendarDelegate(this, &user->_accounts, false, _kiss->GetDateFormat());
calendarDelegate = new CalendarDelegate(this, &user->_accounts, false, _kiss->GetDateLocalFormat());
_accountsGrid->setItemDelegateForColumn(ACCOUNT_END, calendarDelegate);
InitAccounts(user);
@ -370,8 +370,8 @@ void PreferencesPanel::AddAccount(int line, Account ac)
_hiddenAccountSignalMapper.setMapping(checkBox, ac.id);
connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map()));
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(ac.start_date.toString(_kiss->GetDateFormat())));
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(ac.end_date.toString(_kiss->GetDateFormat())));
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(ac.start_date.toString(_kiss->GetDateLocalFormat())));
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(ac.end_date.toString(_kiss->GetDateLocalFormat())));
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
if (!_accountsGrid->item(line, i))
@ -403,9 +403,9 @@ void PreferencesPanel::AddAccount(int line, Account ac)
else
{
QDate date = QDate::currentDate();
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(date.toString(_kiss->GetDateFormat())));
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(date.toString(_kiss->GetDateLocalFormat())));
date = date.addYears(30);
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(date.toString(_kiss->GetDateFormat())));
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(date.toString(_kiss->GetDateLocalFormat())));
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
if (!_accountsGrid->item(line, i))

View File

@ -261,7 +261,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts);
setItemDelegateForColumn(ACCOUNT, accountEditor);
DateDelegate* dateEditor = new DateDelegate(this, month+1, year, _kiss->GetDateFormat());
DateDelegate* dateEditor = new DateDelegate(this, month+1, year, _kiss->GetDateLocalFormat());
setItemDelegateForColumn(OP_DATE, dateEditor);
FormulaDelegate* formulaEditor = new FormulaDelegate(this, &_displayedOperations);
@ -1011,7 +1011,7 @@ void GridAccount::OnOperationModified(int row, int col)
value = item(row, OP_DATE)->text();
if (value.length())
{
date = QDate::fromString(value, _kiss->GetDateFormat());
date = QDate::fromString(value, _kiss->GetDateLocalFormat());
new_op.day = date.day()-1;
new_op.month = date.month()-1;
new_op.year = date.year();

View File

@ -378,7 +378,7 @@ void wxUI::NeedReload(KissPanel* panel)
}
}
QString wxUI::GetDateFormat()
QString wxUI::GetDateLocalFormat()
{
return _curLanguage.dateFormat;
}

View File

@ -75,7 +75,7 @@ public:
void NeedReload(KissPanel* panel);
QLocale* GetLocale() {return _locale;}
QString GetDateFormat();
QString GetDateLocalFormat();
QString _language;
SupportedLanguages::language _curLanguage;