コード例 #1
0
        public int pik_processDigitPeriod(MyInternalKey ik)
        {
            switch (mycalcState)
            {
            case MyCalcState.CS_STATE_READY:
                firstNumber.setNumber("0.");
                ikm_textRefreshed(firstNumber.OriString());

                mycalcState = MyCalcState.CS_STATE_FIRSTOPERAND;
                break;

            case MyCalcState.CS_STATE_FIRSTOPERAND:
                firstNumber.appendDigit(".");
                ikm_textRefreshed(firstNumber.OriString());
                break;

            case MyCalcState.CS_STATE_OPERATOR:
                secondNumber.setNumber("0.");
                ikm_textRefreshed(secondNumber.OriString());

                mycalcState = MyCalcState.CS_STATE_SECONDOPERAND;
                break;

            case MyCalcState.CS_STATE_SECONDOPERAND:
                secondNumber.appendDigit(".");
                ikm_textRefreshed(secondNumber.OriString());
                break;
            }
            return(0);
        }
コード例 #2
0
 public void Form1_Load(object sender, EventArgs e)
 {
     initGlobal();
     memNum.setNumber("0");
     lastFirst.setNumber("0");
     lastSecond.setNumber("0");
     lastOperator = MyInternalKey.IK_OPERATOR_START;
 }
コード例 #3
0
ファイル: Form2.cs プロジェクト: lywme/CSharpCalculator
        private void Form2_Load(object sender, EventArgs e)
        {
            initGlobal();
            memNum.setNumber("0");
            lastFirst.setNumber("0");
            lastSecond.setNumber("0");
            lastOperator = MyInternalKey.IK_OPERATOR_START;

            openFileDialog1.ShowDialog();
            Fname = openFileDialog1.FileName;
            if (Fname != "")
            {
                this.label2.Text = Fname;
            }
            else
            {
                this.label2.Text = "您还没有选择批量测试文件,请选择";
            }
        }
コード例 #4
0
ファイル: Form2.cs プロジェクト: lywme/CSharpCalculator
        void initGlobal()
        {
            mycalcState         = MyCalcState.CS_STATE_READY;
            this.txtOutBox.Text = "0.";
            firstNumber         = new MyCalcNumber();
            secondNumber        = new MyCalcNumber();
            resultNumber        = new MyCalcNumber();
            MyInternalKey mycalcOperator;

            //firstNumber.setNumber('0');
            //secondNumber.setNumber('0');
            resultNumber.setNumber("0");
            firstNumber.setText("END");
            secondNumber.setText("END");
            mycalcOperator = MyInternalKey.IK_CANCEL_START;
        }
コード例 #5
0
        //--------------------ClassifyInternalKey_End--------------------


        //--------------------ProcessInternalKey_Start--------------------

        public int pik_processDigit(MyInternalKey ik)
        {
            int ik_digit;

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


            if (ik == MyInternalKey.IK_DIGIT_PERIOD)
            {
                pik_processDigitPeriod(ik);
                return(0);
            }
            ik_digit = ik - MyInternalKey.IK_DIGIT_0;

            switch (mycalcState)
            {
            case MyCalcState.CS_STATE_READY:
                this.firstNumber.setNumber(ik_digit);
                ikm_textRefreshed(firstNumber.OriString());

                mycalcState = MyCalcState.CS_STATE_FIRSTOPERAND;
                break;

            case MyCalcState.CS_STATE_FIRSTOPERAND:
                firstNumber.appendDigit(ik_digit.ToString());
                ikm_textRefreshed(firstNumber.OriString());
                break;

            case MyCalcState.CS_STATE_OPERATOR:
                secondNumber.setNumber(ik_digit);
                ikm_textRefreshed(secondNumber.OriString());

                mycalcState = MyCalcState.CS_STATE_SECONDOPERAND;
                break;

            case MyCalcState.CS_STATE_SECONDOPERAND:
                secondNumber.appendDigit(ik_digit.ToString());
                ikm_textRefreshed(secondNumber.OriString());
                break;
            }
            return(0);
        }
コード例 #6
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);
        }