コード例 #1
0
void mmFilterTransactionsDialog::OnButtonokClick( wxCommandEvent& /*event*/ )
{
    if (accountCheckBox_->IsChecked())
    {
        refAccountStr_ = accountDropDown_->GetStringSelection();
        Model_Account::Data* account = Model_Account::instance().get(refAccountStr_);
        if (account) refAccountID_ = account->ACCOUNTID;
    }

    if (payeeCheckBox_->IsChecked())
    {
        Model_Payee::Data* payee = Model_Payee::instance().get(cbPayee_->GetValue());
        if (payee)
        {
            payeeID_ = payee->PAYEEID;
            payeeStr_ = payee->PAYEENAME;
        }
    }

    if (amountRangeCheckBox_->IsChecked())
    {
        Model_Currency::Data *currency = Model_Currency::GetBaseCurrency();
        Model_Account::Data *account = Model_Account::instance().get(refAccountID_);
        if (account) currency = Model_Account::currency(account);

        wxString minamt = amountMinEdit_->GetValue().Trim();
        wxString maxamt = amountMaxEdit_->GetValue().Trim();
        if (!minamt.IsEmpty())
        {
            double amount;
            if (!Model_Currency::fromString(minamt, amount, currency) || amount < 0)
            {
                mmShowErrorMessage(this, _("Invalid Amount Entered "), _("Error"));
                return;
            }
        }

        if (!maxamt.IsEmpty())
        {
            double amount;
            if (!Model_Currency::fromString(maxamt, amount, currency) || amount < 0)
            {
                mmShowErrorMessage(this, _("Invalid Amount Entered "), _("Error"));
                return;
            }
        }
    }

    EndModal(wxID_OK);
}
コード例 #2
0
void mmStocksPanel::OnRefreshQuotes(wxCommandEvent& WXUNUSED(event))
{
    wxString sError = "";
    if (onlineQuoteRefresh(sError))
    {
        const wxString header = _("Stock prices successfully updated");
        stock_details_->SetLabelText(header);
        stock_details_short_->SetLabelText(wxString::Format(_("Last updated %s"), strLastUpdate_));
        wxMessageDialog msgDlg(this, sError, header);
        msgDlg.ShowModal();
    }
    else
    {
        refresh_button_->SetBitmapLabel(wxBitmap(wxImage(led_red_xpm).Scale(16,16)));
        stock_details_->SetLabelText(sError);
        stock_details_short_->SetLabelText(_("Error"));
        mmShowErrorMessage(this, sError, _("Error"));
    }
}
コード例 #3
0
void mmStockDialog::OnHistoryDownloadButton(wxCommandEvent& /*event*/)
{
    /*
    Example stock history download:
    https://code.google.com/p/yahoo-finance-managed/wiki/csvHistQuotesDownload
    */

    if (m_stock->SYMBOL.IsEmpty())
        return;

    const wxDateTime& StartDate = Model_Stock::PURCHASEDATE(m_stock);
    wxDateTime EndDate = wxDate::Today();
    const wxTimeSpan time = EndDate - StartDate;
    long intervalMonths = EndDate.GetMonth() - StartDate.GetMonth()
        + 12 * (EndDate.GetYear() - StartDate.GetYear())
        - (EndDate.GetDay() < StartDate.GetDay());

    //Define frequency
    enum { DAILY, WEEKLY, MONTHLY };
    wxArrayString FreqStrs;
    FreqStrs.Add(_("Days"));
    FreqStrs.Add(_("Weeks"));
    if (intervalMonths > 0) FreqStrs.Add(_("Months"));

    int freq = wxGetSingleChoiceIndex(_("Specify type frequency of stock history")
        , _("Stock History Update"), FreqStrs);

    long interval = 0;
    switch (freq)
    {
    case DAILY: interval = time.GetDays(); break;
    case WEEKLY: interval = time.GetWeeks(); break;
    case MONTHLY: interval = intervalMonths; break;
    default: return;
    }

    int nrPrices = (int) wxGetNumberFromUser(_("Specify how many stock history prices download from purchase date")
        , wxString::Format(_("Number of %s:"), FreqStrs.Item(freq).Lower()), _("Stock History Update")
        , interval, 1L, 9999L, this, wxDefaultPosition);

    if (nrPrices <= 0)
    {
        mmShowErrorMessageInvalid(this, FreqStrs[freq]);
        return;
    }
    else
    {
        switch (freq)
        {
        case DAILY: EndDate = wxDate(StartDate).Add(wxDateSpan::Days(nrPrices)); break;
        case WEEKLY: EndDate = wxDate(StartDate).Add(wxDateSpan::Weeks(nrPrices)); break;
        case MONTHLY: EndDate = wxDate(StartDate).Add(wxDateSpan::Months(nrPrices)); break;
        default: break;
        }
    }

    if (EndDate > wxDate::Today())
    {
        mmShowWarningMessage(this, _("End date is in the future\nQuotes will be updated until today")
            , _("Stock History Error"));
        EndDate = wxDate::Today();
    }

    wxString CSVQuotes;
    wxString URL = mmex::weblink::YahooQuotesHistory;
    URL += m_stock->SYMBOL;
    URL += wxString::Format("&a=%i", StartDate.GetMonth());
    URL += wxString::Format("&b=%i", StartDate.GetDay());
    URL += wxString::Format("&c=%i", StartDate.GetYear());
    URL += wxString::Format("&d=%i", EndDate.GetMonth());
    URL += wxString::Format("&e=%i", EndDate.GetDay());
    URL += wxString::Format("&f=%i", EndDate.GetYear());
    switch (freq)
    {
    case DAILY: URL += "&g=d"; break;
    case WEEKLY: URL += "&g=w"; break;
    case MONTHLY: URL += "&g=m"; break;
        default: break;
    }
    URL += "&ignore=.csv";
    wxLogDebug("Start Date:%s End Date:%s URL:%s", StartDate.FormatISODate(), EndDate.FormatISODate(), URL);

    int err_code = site_content(URL, CSVQuotes);
    if (err_code != wxURL_NOERR)
    {
        if (err_code == -1) CSVQuotes = _("Stock history not found!");
        mmShowErrorMessage(this, CSVQuotes, _("Stock History Error"));
        return;
    }

    double dPrice;
    wxString dateStr;
    Model_StockHistory::Data *data;

    wxStringTokenizer tkz(CSVQuotes, "\r\n");
    Model_StockHistory::instance().Begin();
    while (tkz.HasMoreTokens())
    {
        wxStringTokenizer tkzSingleLine(tkz.GetNextToken(), ",");
        std::vector<wxString> tokens;
        while (tkzSingleLine.HasMoreTokens())
        {
            const wxString& token = tkzSingleLine.GetNextToken();
            tokens.push_back(token);
        }

        if (tokens[0].Contains("-"))
        {
            dateStr = tokens[0];
            tokens[6].ToDouble(&dPrice);

            if (Model_StockHistory::instance().find(
                    Model_StockHistory::SYMBOL(m_stock->SYMBOL),
                    Model_StockHistory::DB_Table_STOCKHISTORY_V1::DATE(dateStr)
                ).size() == 0
                && dPrice > 0)
            {
                data = Model_StockHistory::instance().create();
                data->SYMBOL = m_stock->SYMBOL;
                data->DATE = dateStr;
                data->VALUE = dPrice;
                data->UPDTYPE = Model_StockHistory::ONLINE;
                Model_StockHistory::instance().save(data);
            }
        }
    }
    Model_StockHistory::instance().Commit();
    showStockHistory();
}