コード例 #1
0
        /* Przekazuje dzialanie do obliczenia */
        public void ExecuteCalculations()
        {
            string tempTODELETE = CurrentEquationState;

            if (NumberBaseSystem.Decimal != CurrentNumberBaseSystem)
            {
                string[] parsedEquation = CurrentEquationState.ParseEquation();
                AnalyzeParsedEquation(parsedEquation);
            }

            ONP myONP = new ONP(CurrentEquationState);

            CurrentEquationState = myONP.ONPCalculationResult();

            /* W przypadku bledu we wprowadzonym dzialaniu wyslij eventa (GUI go odbiera i wyswietla) */
            if (CurrentEquationState == "ERROR")
            {
                ErrorOccurred(this, new MyEventArgs("Blad we wprowadzonym dzialaniu!"));
                CurrentEquationState = "0";
            }
            else
            {
                CutDecimalPortion();
                // ewentualne skrocenie liczby gdyby byla za duza dla danego rozmiaru slowa
                TrimOutcomeNumber();
                ChangeNumberBaseSystem(CurrentEquationState, NumberBaseSystem.Decimal, CurrentNumberBaseSystem);
            }
            ChangeWordButton(this, new MyEventArgs("true"));
            UpdateDisplay(this, eUpdateArgs);
        }
コード例 #2
0
        /* Dodaje nawias do dzialania */
        public void AddParenthesisToEquation(char Parenthesis)
        {
            int numberOfOpeningdParenthesis = CurrentEquationState.Split('(').Length - 1;
            int numberOfClosingdParenthesis = CurrentEquationState.Split(')').Length - 1;

            if (Parenthesis == ')')
            {
                if (numberOfOpeningdParenthesis > numberOfClosingdParenthesis)
                {
                    if (true == (CurrentEquationState[CurrentEquationState.Length - 1]).IsHex() ||
                        CurrentEquationState[CurrentEquationState.Length - 1] == ')')
                    {
                        CurrentEquationState += Parenthesis;
                    }
                }
            }
            else
            {
                if (CurrentEquationState == "0")
                {
                    CurrentEquationState = Parenthesis.ToString();
                }
                else
                {
                    if (CurrentEquationState[CurrentEquationState.Length - 1].IsMathematicalOperator())
                    {
                        CurrentEquationState += Parenthesis;
                    }
                }
            }
            UpdateDisplay(this, eUpdateArgs);
        }
コード例 #3
0
        /* Usuwa czesc dziesietna (ulamkowa) z liczby */
        public void CutDecimalPortion()
        {
            int resultIndex = CurrentEquationState.IndexOf(',');

            if (-1 != resultIndex)
            {
                CurrentEquationState = CurrentEquationState.Substring(0, resultIndex);
            }
        }
コード例 #4
0
 /* Dodaje znak do dzialania */
 public void AddSignToEquation(char Operator)
 {
     if (true == CurrentEquationState[CurrentEquationState.Length - 1].IsMathematicalOperator())
     {
         CurrentEquationState = CurrentEquationState.Remove(CurrentEquationState.Length - 1, 1);
     }
     CurrentEquationState += Operator;
     ChangeWordButton(this, new MyEventArgs("false"));
     UpdateDisplay(this, eUpdateArgs);
 }
コード例 #5
0
 /* Usuwa ostatni wprowadzony znak */
 public void DeleteLastSignInEquation()
 {
     if (CurrentEquationState != "0" && CurrentEquationState.Length > 1)
     {
         CurrentEquationState = CurrentEquationState.Remove(CurrentEquationState.Length - 1);
     }
     else if (CurrentEquationState != "0" && CurrentEquationState.Length == 1)
     {
         CurrentEquationState = "0";
     }
     if (false == CurrentEquationState.IsThereAnyMathematicalOperatorInString())
     {
         ChangeWordButton(this, new MyEventArgs("true"));
     }
     UpdateDisplay(this, eUpdateArgs);
 }
コード例 #6
0
        /* Zmienia wyswietlana liczbe (w dowolnym systemie liczbowym w zaleznosci
         * od wybranej dlugosci slowa. Na wejsciu przyjmuje liczbe w systemie
         * dziesietnym. */
        public void ChangeNumberBaseSystem(string decNumber, NumberBaseSystem fromBase, NumberBaseSystem goalBase)
        {
            switch (CurrentWordLength)
            {
            case WordLengths.QWORD:
                CurrentEquationState = Convert.ToString(Convert.ToInt64((long.Parse(decNumber)).ToString(), (int)fromBase), (int)goalBase).ToUpper();
                break;

            case WordLengths.DWORD:
                CurrentEquationState = Convert.ToString(Convert.ToInt32(((int)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper();
                break;

            case WordLengths.WORD:
                CurrentEquationState = Convert.ToString(Convert.ToInt16(((short)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper();
                break;

            case WordLengths.BYTE:
                CurrentEquationState = Convert.ToString(Convert.ToSByte(((sbyte)(long.Parse(decNumber))).ToString(), (int)fromBase), (int)goalBase).ToUpper();
                switch (CurrentNumberBaseSystem)
                {
                case NumberBaseSystem.Binary:
                    if (CurrentEquationState.Length > 8)
                    {
                        CurrentEquationState = CurrentEquationState.Substring(CurrentEquationState.Length - 8);
                    }
                    break;

                case NumberBaseSystem.Decimal:
                    break;

                case NumberBaseSystem.Hexadecimal:
                    if (CurrentEquationState.Length > 2)
                    {
                        CurrentEquationState = CurrentEquationState.Substring(CurrentEquationState.Length - 2);
                    }
                    break;

                case NumberBaseSystem.Octal:
                    break;
                }
                break;
            }
            UpdateDisplay(this, eUpdateArgs);
        }
コード例 #7
0
        /* Ustawia nowy system liczbowy */
        public void ChangeBaseNumberSystem(string NumberSystem)
        {
            NumberBaseSystem previousBaseSystem = CurrentNumberBaseSystem;
            string           tempNumber         = ConvertNumberToDecimal(CurrentEquationState.ExtractLastNumberFromString(m_fSearchWithMinus));

            CurrentNumberBaseSystem = (NumberBaseSystem)Enum.Parse(typeof(NumberBaseSystem), NumberSystem);
            switch (CurrentNumberBaseSystem)
            {
            case NumberBaseSystem.Binary:
                LockButtons(this, new MyEventArgs("Octal"));
                LockButtons(this, new MyEventArgs("Decimal"));
                LockButtons(this, new MyEventArgs("Hexadecimal"));
                m_fSearchWithMinus = false;
                break;

            case NumberBaseSystem.Octal:
                UnlockButtons(this, new MyEventArgs("Octal"));
                LockButtons(this, new MyEventArgs("Decimal"));
                LockButtons(this, new MyEventArgs("Hexadecimal"));
                m_fSearchWithMinus = false;
                break;

            case NumberBaseSystem.Decimal:
                UnlockButtons(this, new MyEventArgs("Octal"));
                UnlockButtons(this, new MyEventArgs("Decimal"));
                LockButtons(this, new MyEventArgs("Hexadecimal"));
                m_fSearchWithMinus = true;
                break;

            case NumberBaseSystem.Hexadecimal:
                UnlockButtons(this, new MyEventArgs("Octal"));
                UnlockButtons(this, new MyEventArgs("Decimal"));
                UnlockButtons(this, new MyEventArgs("Hexadecimal"));
                m_fSearchWithMinus = false;
                break;
            }
            ChangeNumberBaseSystem(tempNumber, NumberBaseSystem.Decimal, CurrentNumberBaseSystem);
        }
コード例 #8
0
        /* Zmiana dlugosci uzywanego slowa */
        public TextInformation ChangeWordLength()
        {
            switch (CurrentWordLength)
            {
            case WordLengths.QWORD:
                CurrentWordLength = WordLengths.DWORD;
                break;

            case WordLengths.DWORD:
                CurrentWordLength = WordLengths.WORD;
                break;

            case WordLengths.WORD:
                CurrentWordLength = WordLengths.BYTE;
                break;

            case WordLengths.BYTE:
                CurrentWordLength = WordLengths.QWORD;
                break;
            }
            ChangeNumberBaseSystem(ConvertNumberToDecimal(CurrentEquationState.ExtractLastNumberFromString(m_fSearchWithMinus)), NumberBaseSystem.Decimal, CurrentNumberBaseSystem);
            return(new TextInformation(CurrentWordLength.ToString(), FontSizes.VerySmall, Brushes.Blue));
        }