Пример #1
0
void
Category::Save(ofstream& file)
{
  
  for (Category::Iterator i = Begin(); i != End(); i++) {
    
    Transaction* t = i->second;

    csv_fwrite(file, Name());
    file << ',';

    csv_fwrite(file, t->Timestamp());
    file << ',';

    csv_fwrite(file, t->Reason());
    file << ',';

    ostringstream amount;
    amount.setf(ios::showpoint);
    amount.setf(ios::fixed);
    amount << setprecision(2) << t->Amount();
    csv_fwrite(file, amount.str());
    file << ',';

    csv_fwrite(file, t->Action());
    file << "\r\n"; // Carriage return + line feed (DOS style newline)
  }
}
Пример #2
0
void
RemoveCategoryCommand::Undo()
{
  if (_document == NULL) {
    return;
  }
  
  // Add the category and all of its transactions
  // back into the budget
  list<Transaction*>::const_iterator it;
  
  for (it = _transactions.begin(); it != _transactions.end(); it++) {
    Transaction* t = *it;
    _document->AddTransaction(_category, t->Timestamp(), t->Reason(), t->Amount(), t->Action());
  }
}
Пример #3
0
void
RemoveCategoryCommand::SetDocument(Budget* document)
{
  Command::SetDocument(document);
  
  list<Transaction*>::iterator list_it;
  
  // Delete any old transactions (there probably aren't any)
  for (list_it = _transactions.begin(); list_it != _transactions.end(); list_it++) {
    delete *list_it;
  }
  
  Category* c = _document->Categories()->find(_category)->second;
  
  // Save all of the transactions that are in this category
  for (Category::Iterator i = c->Begin(); i != c->End(); i++) {
    Transaction* t = i->second;
    Transaction* new_t = new Transaction(t->Timestamp(), t->Reason(), t->Amount(), t->Action());
    _transactions.push_back(new_t);
  }
}