Ejemplo n.º 1
0
        private void ConvertBtn_Click(object sender, EventArgs e)
        {
            try
            {
                IBalanceState fromCurrency = null;
                double        balanceCount = Convert.ToDouble(fromTxtBx.Text);

                if (fromUSDChkBx.Checked && !fromUAHChkBx.Checked && !fromEURChkBx.Checked)
                {
                    fromCurrency = (USDBalanceState)StateFactoryHolder.factory.GetBalanceState("USD");
                }
                else if (!fromUSDChkBx.Checked && fromUAHChkBx.Checked && !fromEURChkBx.Checked)
                {
                    fromCurrency = (UAHBalanceState)StateFactoryHolder.factory.GetBalanceState("UAH");
                }
                else if (!fromUSDChkBx.Checked && !fromUAHChkBx.Checked && fromEURChkBx.Checked)
                {
                    fromCurrency = (EURBalanceState)StateFactoryHolder.factory.GetBalanceState("EUR");
                }
                else
                {
                    throw new Exception();
                }

                IBalance balance = new Balance(balanceCount, fromCurrency);

                if (toUSDChkBx.Checked && !toUAHChkBx.Checked && !toEURChkBx.Checked)
                {
                    balance.ConvertToUSD();
                }
                else if (!toUSDChkBx.Checked && toUAHChkBx.Checked && !toEURChkBx.Checked)
                {
                    balance.ConvertToUAH();
                }
                else if (!toUSDChkBx.Checked && !toUAHChkBx.Checked && toEURChkBx.Checked)
                {
                    balance.ConvertToEUR();
                }
                else
                {
                    throw new Exception();
                }

                toTxtBx.Text = balance.GetStrValue();
            }
            catch
            {
                toTxtBx.Text = "error...";
            }
        }
Ejemplo n.º 2
0
        private void registerSaveBtn_Click(object sender, EventArgs e)
        {
            IBalanceState currency = null;

            if (USDChkBx.Checked)
            {
                currency = StateFactoryHolder.factory.GetBalanceState(CurrencyType
                                                                      .USD.ToString());
            }
            else if (EURChkBx.Checked)
            {
                currency = StateFactoryHolder.factory.GetBalanceState(CurrencyType
                                                                      .EUR.ToString());
            }
            else if (UAHChkBx.Checked)
            {
                currency = StateFactoryHolder.factory.GetBalanceState(CurrencyType
                                                                      .UAH.ToString());
            }
            Balance balance = new Balance(Convert.ToDouble(rAccountTxtBx.Text), currency);

            AccountManager.Register(rNameTxtBx.Text, rPassTxtBx.Text, balance);
        }
Ejemplo n.º 3
0
        private void Transaction(string transactionType)
        {
            try
            {
                msgLabel.Hide();
                if (AccountHolder.CurrentAccount != null)
                {
                    ITransaction transaction = new Transaction();
                    transaction.Name        = nameTxtBx.Text;
                    transaction.Description = descriptTxtBx.Text;
                    transaction.Time        = DateTime.Now.ToLongTimeString();

                    if (transactionType.Equals(TransactionTypes.Spending.ToString()))
                    {
                        transaction.Type = new TransactionType(TransactionTypes
                                                               .Spending.ToString());
                    }
                    else
                    {
                        transaction.Type = new TransactionType(TransactionTypes
                                                               .Earning.ToString());
                    }

                    double cost = 0;

                    if (GetBalanceFromString(costTxtBx.Text).Success == true)
                    {
                        cost = GetBalanceFromString(costTxtBx.Text).Data;
                    }
                    else
                    {
                        msgLabel.Text = GetBalanceFromString(costTxtBx.Text)
                                        .Message;
                        throw new Exception();
                    }

                    IBalanceState currency = null;
                    if (USDChkBx.Checked && !UAHChkBx.Checked && !EURChkBx.Checked)
                    {
                        currency = (USDBalanceState)StateFactoryHolder.factory
                                   .GetBalanceState(CurrencyType.USD.ToString());
                    }
                    else if (!USDChkBx.Checked && UAHChkBx.Checked && !EURChkBx.Checked)
                    {
                        currency = (UAHBalanceState)StateFactoryHolder.factory
                                   .GetBalanceState(CurrencyType.UAH.ToString());
                    }
                    else if (!USDChkBx.Checked && !UAHChkBx.Checked && EURChkBx.Checked)
                    {
                        currency = (EURBalanceState)StateFactoryHolder.factory
                                   .GetBalanceState(CurrencyType.EUR.ToString());
                    }
                    else
                    {
                        msgLabel.Text = MessageHolder.GetMessage(MessageType
                                                                 .MultiplyCheckError);
                        throw new Exception();
                    }


                    Balance balance = new Balance(cost, currency);
                    transaction.Amount = balance;

                    if (transactionType.Equals(TransactionTypes.Spending.ToString()))
                    {
                        AccountHolder.CurrentAccount.SpendMoney(transaction);
                    }
                    else
                    {
                        AccountHolder.CurrentAccount.ReceiveMoney(transaction);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

                msgLabel.Show();
            }
        }
 public Balance(double count, IBalanceState currency)
 {
     Count    = count;
     Currency = currency;
 }