예제 #1
0
        public void Start()
        {
            while (true)
            {
                _view.PrintText("Выберите язык(Choose language): \n1 - RUS\n2 - ENG");

                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.NumPad1:
                case ConsoleKey.D1:
                    _phrases = new RusPhrases();
                    LogicWork(_phrases, true);
                    break;


                case ConsoleKey.NumPad2:
                case ConsoleKey.D2:
                    _phrases = new EngPhrases();
                    LogicWork(_phrases, false);
                    break;


                default:
                    _view.PrintText("Нажмите 1 или 2 (Press 1 or 2)");
                    _view.InputUser();
                    break;
                }
            }
        }
예제 #2
0
        private string NumPhrase(IPhrases phrases, ulong value, bool isMale, bool toUpper, bool culture)
        {
            if (value == 0UL)
            {
                return(phrases.NullNumber);
            }

            string phrase = "";

            for (byte th = 1; value > 0; th++)
            {
                ushort gr = (ushort)(value % 1000);
                value = (value - gr) / 1000;
                if (gr > 0)
                {
                    byte d3 = (byte)((gr - gr % 100) / 100);
                    byte d1 = (byte)(gr % 10);
                    byte d2 = (byte)((gr - d3 * 100 - d1) / 10);
                    if (d2 == 1)
                    {
                        d1 += (byte)10;
                    }
                    bool ismale = (th > 2) || ((th == 1) && isMale);
                    if (culture)
                    {
                        phrase = phrases.Hundreds[d3] + phrases.Ten[d2] + phrases.Units[d1] + EndDek1(d1, ismale) + phrases.Millions[th] + EndTh(th, d1) + phrase;
                    }
                    else
                    {
                        phrase = phrases.Hundreds[d3] + phrases.Ten[d2] + phrases.Units[d1] + phrases.Millions[th] + phrase;
                    }
                }
                ;
            }
            ;

            if (toUpper)
            {
                phrase = phrase.Substring(1, 1).ToUpper() + phrase.Substring(2);
            }

            return(phrase);
        }
예제 #3
0
        private string CurPhrase(decimal money, IPhrases phrases, bool culture)
        {
            money = decimal.Round(money, 2);
            decimal decIntPart = decimal.Truncate(money);
            ulong   intPart    = decimal.ToUInt64(decIntPart);
            string  str        = NumPhrase(phrases, intPart, true, true, culture) + " ";
            byte    endPart    = (byte)(intPart % 100UL);

            if (endPart > 19)
            {
                endPart = (byte)(endPart % 10);
            }
            switch (endPart)
            {
            case 1: str += phrases.Сurrency[0]; break;

            case 2:
            case 3:
            case 4: str += phrases.Сurrency[1]; break;

            default: str += phrases.Сurrency[2]; break;
            }
            byte fracPart = decimal.ToByte((money - decIntPart) * 100M);

            str += " " + NumPhrase(phrases, fracPart, true, false, culture) + " ";
            if (fracPart > 19)
            {
                fracPart = (byte)(fracPart % 10);
            }
            switch (fracPart)
            {
            case 1: str += phrases.Сurrency[3]; break;

            case 2:
            case 3:
            case 4: str += phrases.Сurrency[4]; break;

            default: str += phrases.Сurrency[5]; break;
            }
            ;
            return(str);
        }
예제 #4
0
        private void LogicWork(IPhrases phrase, bool culture)
        {
            _view.PrintText(phrase.InputUser);
            decimal inputNumber = 0;

            if (decimal.TryParse(_view.InputUser(), out inputNumber))
            {
                if (inputNumber > 0 && inputNumber < 2000000000m)
                {
                    _view.PrintText(_logicNumberToString.NumberToStringPhrases(inputNumber, _phrases, culture));
                    _view.InputUser();
                    return;
                }

                _view.PrintText(phrase.ExceededValueError);
                _view.InputUser();
            }
            else
            {
                _view.PrintText(phrase.InputError);
                _view.InputUser();
            }
        }
예제 #5
0
 public MyProfile()
 {
     _users   = new MUsers();
     _tools   = new MTools();
     _phrases = new MPhrases();
 }
예제 #6
0
 public string NumberToStringPhrases(decimal money, IPhrases phrase, bool culture)
 {
     return(CurPhrase(money, phrase, culture));
 }