Exemplo n.º 1
0
        public void AddOperation(DateTime date, MoneyOperation operation)
        {
            if (Operations.ContainsKey(date))
            {
                Operations[date].Add(operation);
            }
            else
            {
                Operations.Add(date, new List <MoneyOperation> {
                    operation
                });
            }

            OperationAdded?.Invoke();
        }
Exemplo n.º 2
0
        private void btnAddCategory_Click(object sender, EventArgs e)
        {
            if (Monefy.OperType == OperationType.Category)
            {
                var value = Convert.ToDouble(tbAmount.Text);
                if (value != 0)
                {
                    var      account = cbSelectAccount.SelectedValue as Account;
                    Currency curr    = (Currency)cbAddCategoryCurrency.SelectedValue;
                    value = Monefy.CurRate.EquateRates(account.AccCurrency, curr, value);


                    var operation = new MoneyOperation(curr, cbSelectCategory.SelectedValue.ToString(), account.AccName, Convert.ToInt32(account.AccountID), tbAddCategoryNote.Text, value);
                    Monefy.ReduceAccountBalance(account.AccountID, value);
                    Monefy.AddOperation(dtpAddCategory.Value.Date, operation);

                    MessageBox.Show(
                        $"{Monefy.Interface["spent"]}:    {value} {account.AccCurrency}\n{Monefy.Interface["category"]}:    {Monefy.Categories[cbSelectCategory.SelectedValue.ToString()]}",
                        Monefy.Interface["successOperation"], MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show(Monefy.Interface["sumError"], Monefy.Interface["error"], MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
            else if (Monefy.OperType == OperationType.Account)
            {
                if (tbAddAccName.Text != string.Empty)
                {
                    var value = Convert.ToDouble(tbAmount.Text);

                    Currency curr = (Currency)cbAddAccCurr.SelectedValue;
                    Monefy.AddAccount(new Account(curr, tbAddAccName.Text, value));
                    var operation = new MoneyOperation(curr, "newAccountAdd", tbAddAccName.Text, Monefy.GetLastAddedAccountID(), tbAddAccName.Text, value, OperationType.Account);
                    Monefy.AddOperation(DateTime.Now.Date, operation);

                    MessageBox.Show(
                        $"{Monefy.Interface["accountAdded"]}",
                        Monefy.Interface["successOperation"], MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show(Monefy.Interface["emptyAccNameWarning"], Monefy.Interface["error"], MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (Monefy.OperType == OperationType.AddBalance)
            {
                var value = Convert.ToDouble(tbAmount.Text);
                if (value != 0)
                {
                    Currency curr    = (Currency)cbAddToBalanceCurr.SelectedValue;
                    var      account = cbAddToBalanceAcc.SelectedValue as Account;
                    value = Monefy.CurRate.EquateRates(account.AccCurrency, curr, value);
                    var operation = new MoneyOperation(curr, "balanceIncrease", account.AccName, Convert.ToInt32(account.AccountID), tbAddToBalanceNote.Text, value, OperationType.AddBalance);
                    Monefy.AddOperation(dtpAddToBalance.Value.Date, operation);
                    Monefy.IncreaseBalanceToAccount(account.AccountID, value);

                    MessageBox.Show(
                        $"{Monefy.Interface["added"]}:    {value} {account.AccCurrency}\n{Monefy.Interface["account"]}:    {account.AccName}",
                        Monefy.Interface["successOperation"], MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show(Monefy.Interface["sumError"], Monefy.Interface["error"], MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }

            PanelsVisibility(false);
            pnlMain.Visible = true;
        }