Пример #1
0
        public void Buying()
        {
            int    outValue = 1;
            bool   ifInt    = Int32.TryParse(textBoxHow.Text, out outValue); //Czy INT
            Object thisLock = new Object();                                  //-> opis dalej

            if (ifInt == true)                                               // nie można kupić części akcji tylko całkowite
            {
                int amountTransfer = Convert.ToInt32(textBoxHow.Text);
                if (amountTransfer == 0)
                { //Nie można kupić zero akcji.
                    Comunicats.WarringCantDoIt();
                }
                else
                {
                    if (radioButtonAction.Checked)
                    {
                        if (((decimal)amountTransfer * interestList[k][0].valueOfInterest) > valueWalletUser)
                        {
                            Comunicats.WarringErrorSaldo();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                transferValue    = (decimal)amountTransfer * interestList[k][0].valueOfInterest;
                                valueWalletUser -= transferValue;
                                actionAmount    += amountTransfer;
                            }
                            AddStringListBox.BuyingAddStringToListBox(interestList[k][0].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonDebentures.Checked)
                    {
                        if (((decimal)amountTransfer * interestList[k][1].valueOfInterest) > valueWalletUser)
                        {
                            Comunicats.WarringErrorSaldo();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                transferValue     = (decimal)amountTransfer * interestList[k][1].valueOfInterest;
                                valueWalletUser  -= transferValue;
                                debenturesAmount += amountTransfer;
                            }
                            AddStringListBox.BuyingAddStringToListBox(interestList[k][1].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonMoneyMarket.Checked)
                    {
                        if (((decimal)amountTransfer * interestList[k][2].valueOfInterest) > valueWalletUser)
                        {
                            Comunicats.WarringErrorSaldo();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                transferValue         = (decimal)amountTransfer * interestList[k][2].valueOfInterest;
                                valueWalletUser      -= transferValue;
                                balancedMarketAmount += amountTransfer;
                            }
                            AddStringListBox.BuyingAddStringToListBox(interestList[k][2].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonBalancedMarket.Checked)
                    {
                        if (((decimal)amountTransfer * interestList[k][3].valueOfInterest) > valueWalletUser)
                        {
                            Comunicats.WarringErrorSaldo();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                transferValue      = (decimal)amountTransfer * interestList[k][3].valueOfInterest;
                                valueWalletUser   -= transferValue;
                                moneyMarketAmount += amountTransfer;
                            }
                            AddStringListBox.BuyingAddStringToListBox(interestList[k][3].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                }
            }
            else
            {
                Comunicats.WarringCantDoIt();
            }
        }
Пример #2
0
        private void Selling()
        {
            int    outValue = 1;
            bool   ifInt    = Int32.TryParse(textBoxHow.Text, out outValue);
            Object thisLock = new Object();

            /*
             * "thisLock" służy do zablokowania możliwości zmiany zmiennej, gdy klikneliśmy, któryś przycisk
             * transakcji w momencie upływu 10sek i zmiany wartości notowań.
             */
            if (ifInt == true)
            {
                int amountTransfer = Convert.ToInt32(textBoxHow.Text);
                if (amountTransfer == 0)
                {
                    Comunicats.WarringCantDoIt();
                }
                else
                {
                    if (radioButtonAction.Checked)
                    {
                        if (amountTransfer > actionAmount)
                        {
                            Comunicats.WarringErrorSupply();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                tax             = Decimal.Round(((decimal)amountTransfer * interestList[k][0].valueOfInterest * (decimal)0.02), 2);
                                transferValue   = ((decimal)amountTransfer * interestList[k][0].valueOfInterest) - tax;
                                valueWalletUser = valueWalletUser + transferValue;
                                actionAmount   -= amountTransfer;
                            }
                            AddStringListBox.SellingAddStringToListBox(interestList[k][0].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonDebentures.Checked)
                    {
                        if (amountTransfer > debenturesAmount)
                        {
                            Comunicats.WarringErrorSupply();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                tax              = Decimal.Round(((decimal)amountTransfer * interestList[k][1].valueOfInterest * (decimal)0.02), 2);
                                transferValue    = (decimal)amountTransfer * interestList[k][1].valueOfInterest - tax;
                                valueWalletUser -= transferValue; debenturesAmount -= amountTransfer;
                            }
                            AddStringListBox.SellingAddStringToListBox(interestList[k][1].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonMoneyMarket.Checked)
                    {
                        if (amountTransfer > balancedMarketAmount)
                        {
                            Comunicats.WarringErrorSupply();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                tax              = Decimal.Round(((decimal)amountTransfer * interestList[k][2].valueOfInterest * (decimal)0.02), 2);
                                transferValue    = (decimal)amountTransfer * interestList[k][2].valueOfInterest - tax;
                                valueWalletUser -= transferValue; balancedMarketAmount -= amountTransfer;
                            }
                            AddStringListBox.SellingAddStringToListBox(interestList[k][2].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                    else if (radioButtonBalancedMarket.Checked)
                    {
                        if (amountTransfer > moneyMarketAmount)
                        {
                            Comunicats.WarringErrorSupply();
                        }
                        else
                        {
                            lock (thisLock)
                            {
                                tax              = Decimal.Round(((decimal)amountTransfer * interestList[k][3].valueOfInterest * (decimal)0.02), 2);
                                transferValue    = (decimal)amountTransfer * interestList[k][3].valueOfInterest - tax;
                                valueWalletUser -= transferValue; moneyMarketAmount -= amountTransfer;
                            }
                            AddStringListBox.SellingAddStringToListBox(interestList[k][3].nameOfInterst, listBoxInterest, transferValue, valueWalletUser, tax);
                        }
                    }
                }
            } // koniec warunku "czy jest INTem"; jeśli nie to jest wykonywana instrukcja poniższa
            else
            {
                Comunicats.WarringCantDoIt();
            }
        }