コード例 #1
0
        private void Reset()
        {
            onConsoleOutput = "0";
            lastKey         = LastKey.Digit;
            operandSwitch   = OperandSwitch.OperandA;

            lastKeyValue = '0';
            lastOperator = '#';
        }
コード例 #2
0
        public string SendKeyPress(char key)
        {
            switch (key)
            {
            case var tempKey when(tempKey >= '0' && tempKey <= '9'):
                if (operandSwitch == OperandSwitch.OperandA)
                {
                    if (lastKey == LastKey.Digit)
                    {
                        if (onConsoleOutput == "0")
                        {
                            onConsoleOutput = key.ToString();
                        }
                        else
                        {
                            onConsoleOutput = onConsoleOutput + key.ToString();
                        }
                        operandA = onConsoleOutput;
                    }
                }

                else if (operandSwitch == OperandSwitch.OperandB)
                {
                    if (lastKey == LastKey.Operator)
                    {
                        onConsoleOutput = key.ToString();
                    }

                    else if (lastKey == LastKey.Digit)
                    {
                        if (onConsoleOutput == "0")
                        {
                            onConsoleOutput = key.ToString();
                        }
                        else
                        {
                            onConsoleOutput = onConsoleOutput + key.ToString();
                        }
                    }
                    operandB = onConsoleOutput;
                }
                lastKeyValue = key;
                lastKey      = LastKey.Digit;
                break;

            case var tempKey when(tempKey == '+' || tempKey == '-' || tempKey == '/' || tempKey.ToString().ToLower() == "x"):
                if (operandSwitch == OperandSwitch.OperandA)
                {
                    operandSwitch = OperandSwitch.OperandB;
                    lastKey       = LastKey.Operator;
                    lastOperator  = tempKey;
                    return(onConsoleOutput);
                }

                Result();

                lastOperator = tempKey;
                lastKey      = LastKey.Operator;
                operandA     = onConsoleOutput;

                if (operandSwitch == OperandSwitch.OperandA)
                {
                    operandSwitch = OperandSwitch.OperandB;
                }

                break;

            case var tempKey when(tempKey.ToString().ToLower() == "s"):
                Toggle();

                break;

            case var tempKey when(tempKey.ToString().ToLower() == "c"):
                Reset();

                break;

            case var tempKey when(tempKey == '='):
                Result();

                break;

            case var tempKey when(tempKey == '.'):
                HandleDecimals();

                break;
            }
            return(onConsoleOutput);
        }