示例#1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (numExchangeRate.Value == 0)
            {
                MessageBox.Show(Resources.Labels.NonZeroExchangeRateText, Resources.Labels.ErrorSavingTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (existingItem != null)
            {
                if (existingItem.ID.StartsWith(Consts.Keeper.UserMetadataPrefix))
                {
                    existingItem.Title               = tbTitle.Text.Trim();
                    existingItem.CurrencyCulture     = tbCulture.Text.Trim();
                    existingItem.IsSymbolAfterAmount = cbIsSymbolAfterAmount.Checked;
                }
                existingItem.ExchangeRate = (double)numExchangeRate.Value;
                existingItem.SortOrder    = (int)numSortOrder.Value;
            }
            else
            {
                String ID = tbID.Text.Trim().ToUpper();
                if (keeper.DataSet.Currencies.FindByID(ID) != null)
                {
                    MessageBox.Show(String.Format(Resources.Labels.RecordExistFormat, ID),
                                    Resources.Labels.ErrorSavingTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (!ID.StartsWith(Consts.Keeper.UserMetadataPrefix))
                {
                    MessageBox.Show(String.Format(Resources.Labels.UserIDShouldHavePrefixFormat, Consts.Keeper.UserMetadataPrefix),
                                    Resources.Labels.ErrorSavingTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                MoneyDataSet.CurrenciesRow currency = keeper.DataSet.Currencies.NewCurrenciesRow();
                currency.ID                  = ID;
                currency.Title               = tbTitle.Text.Trim();
                currency.CurrencyCulture     = tbCulture.Text.Trim();
                currency.ExchangeRate        = (double)numExchangeRate.Value;
                currency.SortOrder           = (int)numSortOrder.Value;
                currency.IsSymbolAfterAmount = cbIsSymbolAfterAmount.Checked;
                keeper.DataSet.Currencies.AddCurrenciesRow(currency);
            }
            keeper.DataSet.AcceptChanges();

            if (keeper.GetDefaultCurrency() == null)
            {
                MessageBox.Show(Resources.Labels.NoDefaultCurrencyText, Resources.Labels.NoDefaultCurrencyTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#2
0
        private void updateStatsDay()
        {
            double earned = 0;
            double spent  = 0;

            foreach (MoneyDataSet.TransactionsRow transaction in
                     keeper.Transactions.Where(t => (
                                                   (t.TransactionTime.Year == statsDay.Year) &&
                                                   (t.TransactionTime.DayOfYear == statsDay.DayOfYear) &&
                                                   (t.IsStasticicCountable))))
            {
                if (transaction.TransactionTypesRow.IsIncome)
                {
                    earned += transaction.Amount * transaction.AccountRow.CurrenciesRow.ExchangeRate;
                }
                else
                {
                    spent += transaction.Amount * transaction.AccountRow.CurrenciesRow.ExchangeRate;
                }
            }
            lblStatsDay.Text       = String.Format(Resources.Labels.StatsDay, statsDay.ToShortDateString());
            lblStatsDayEarned.Text = String.Format(Consts.UI.EarnedFormat, earned, keeper.GetDefaultCurrency().CurrencyCultureInfo);
            lblStatsDaySpent.Text  = String.Format(Consts.UI.SpentFormat, spent, keeper.GetDefaultCurrency().CurrencyCultureInfo);
        }