Example #1
0
        public void pik_processMemory(MyInternalKey ik)
        {
            switch (ik)
            {
            case MyInternalKey.IK_MEMORY_MA:
            {
                memNum.setNumber(memNum.getNumber() + Convert.ToDouble(this.txtOutBox.Text));
                this.ioc_setMemoryFlagData();
            }
            break;

            case MyInternalKey.IK_MEMORY_MS:
            {
                memNum.setNumber(memNum.getNumber() - Convert.ToDouble(this.txtOutBox.Text));
                this.ioc_setMemoryFlagData();
            }
            break;

            case MyInternalKey.IK_MEMORY_MC:
            {
                memNum.setNumber(0);
                this.ioc_clearMemoryFlagData();
            }
            break;

            case MyInternalKey.IK_MEMORY_MR:
            {
                if (pressedMR == 0)
                {
                    pressedMR = 1;
                    switch (mycalcState)
                    {
                    case MyCalcState.CS_STATE_READY:
                    {
                        ikm_textRefreshed(memNum.toString());
                        firstNumber.setNumber(memNum.getNumber());
                        mycalcState = MyCalcState.CS_STATE_FIRSTOPERAND;
                    }
                    break;

                    case MyCalcState.CS_STATE_FIRSTOPERAND:
                    {
                        ikm_textRefreshed(memNum.toString());
                        firstNumber.setNumber(memNum.getNumber());
                        mycalcState = MyCalcState.CS_STATE_OPERATOR;
                    }
                    break;

                    case MyCalcState.CS_STATE_OPERATOR:
                    {
                        ikm_textRefreshed(memNum.toString());
                        secondNumber.setNumber(memNum.getNumber());
                        mycalcState = MyCalcState.CS_STATE_SECONDOPERAND;
                    }
                    break;

                    case MyCalcState.CS_STATE_SECONDOPERAND:
                    {
                        //ikm_textRefreshed(memNum.toString());
                        //secondNumber.setNumber(memNum.getNumber());
                        pik_doCalculate();
                    }
                    break;
                    }
                }
            }
            break;
            }
        }
Example #2
0
        public int pik_processOperator(MyInternalKey ik)
        {
            //double fn, sn, rn;

            if (g_getInternalKeyType(ik) != MyCalcInternalKeyType.IKT_OPERATOR)
            {
                return(1);
            }

            if (ik == MyInternalKey.IK_OPERATOR_SIGN)
            {
                if (mycalcState == MyCalcState.CS_STATE_FIRSTOPERAND)
                {
                    firstNumber.setNumber(0 - firstNumber.getNumber());
                    ikm_textRefreshed(firstNumber.toString());
                }
                if (mycalcState == MyCalcState.CS_STATE_SECONDOPERAND)
                {
                    secondNumber.setNumber(0 - secondNumber.getNumber());
                    ikm_textRefreshed(secondNumber.toString());
                }
                if (mycalcState == MyCalcState.CS_STATE_OPERATOR)
                {
                    secondNumber.setNumber(0 - secondNumber.getNumber());
                    ikm_textRefreshed(secondNumber.toString());
                }
                if (mycalcState == MyCalcState.CS_STATE_READY)
                {
                    resultNumber.setNumber(0 - resultNumber.getNumber());
                    ikm_textRefreshed(resultNumber.toString());
                }
            }
            else
            {
                if (ik == MyInternalKey.IK_OPERATOR_RESULT)
                {
                    mycalcState = MyCalcState.CS_STATE_SECONDOPERAND;
                }

                switch (mycalcState)
                {
                case MyCalcState.CS_STATE_READY:
                    if (firstNumber.getText() == "END" && secondNumber.getText() == "END")
                    {
                        firstNumber.setText(resultNumber.getText());
                        mycalcOperator = ik;
                        mycalcState    = MyCalcState.CS_STATE_OPERATOR;
                    }
                    break;

                case MyCalcState.CS_STATE_FIRSTOPERAND:
                    mycalcOperator = ik;
                    mycalcState    = MyCalcState.CS_STATE_OPERATOR;
                    break;

                case MyCalcState.CS_STATE_OPERATOR:
                {
                    if (ik == MyInternalKey.IK_OPERATOR_RESULT && firstNumber.getText() == resultNumber.getText() && secondNumber.getText() == "END")
                    {
                        secondNumber.setNumber(firstNumber.getNumber());
                        pik_doCalculate();
                        mycalcState = MyCalcState.CS_STATE_READY;
                    }
                    else
                    {
                        mycalcOperator = ik;
                    }
                }
                break;

                case MyCalcState.CS_STATE_SECONDOPERAND:
                    pik_doCalculate();
                    mycalcState = MyCalcState.CS_STATE_READY;
                    if (ik != MyInternalKey.IK_OPERATOR_RESULT)
                    {
                        firstNumber.setText(resultNumber.getText());
                        mycalcOperator = ik;
                        mycalcState    = MyCalcState.CS_STATE_OPERATOR;
                    }
                    break;
                }
            }

            return(0);
        }