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); }
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; }
//--------------------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); }
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; } }
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); }