示例#1
0
        /// <summary>
        /// 新增一個位數
        /// </summary>
        /// <param name="number">一個位數</param>
        /// <returns>數字更新</returns>
        public FrameUpdate AddNumber(char number)
        {
            //小數點case
            if (number.Equals('.'))
            {
                //若這時沒有值→視為已經輸入零
                if (NumberField == null)
                {
                    NumberField = new NumberField();
                    NumberField.AddDigit(number);
                    return(new FrameUpdate("0.", new ExpUpdate(removeLength: 0, updateString: "0.")));
                }
                //若有值→判斷是否已為小數
                if (NumberField.IsNumeric)
                {
                    //已經是小數→不回傳值
                    return(new FrameUpdate(NumberField.Number.ToString() + ".", new ExpUpdate(removeLength: 0, updateString: string.Empty)));
                }
                else
                {
                    //不是小數→更新小數點
                    NumberField.AddDigit(number);
                    return(new FrameUpdate(NumberField.Number.ToString() + ".", new ExpUpdate(removeLength: 0, updateString: ".")));
                }
            }

            //防呆
            if (!char.IsNumber(number))
            {
                throw new Exception("NewControll.Add該輸入數字");
            }

            //正常的數字case
            if (NumberField == null)
            {
                NumberField = new NumberField(number);
            }
            else
            {
                NumberField.AddDigit(number);
            }
            return(new FrameUpdate(NumberField.Number.ToString(), new ExpUpdate(removeLength: 0, updateString: number.ToString())));
        }