コード例 #1
0
        /// <summary>
        /// 毫米轉換為米分米釐米毫米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(毫米或者米分米釐米毫米)</param>
        protected virtual void MillimeterConvertToMeterDecimetreCentimeterExt(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得米數量級
            int meter = CommonUtil.GetRandomNumber(1, 9);
            // 隨機取得分米數量級
            int decimetre = CommonUtil.GetRandomNumber(1, 9);
            // 隨機取得釐米數量級
            int centimeter = CommonUtil.GetRandomNumber(1, 9);
            // 隨機取得釐米數量級
            int remainderMillimeter = CommonUtil.GetRandomNumber(1, 9);
            // 隨機編排填空項目(是毫米還是米分米釐米毫米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 毫米單位
                Millimeter = meter * 1000 + decimetre * 100 + centimeter * 10 + remainderMillimeter,
                // 米單位
                Meter = meter,
                // 分米單位
                Decimetre = decimetre,
                // 釐米單位
                Centimeter = centimeter
            };
            // 剩餘的毫米
            formula.RemainderMillimeter = remainderMillimeter;
            // 填空項目(毫米或者米分米釐米毫米)
            formula.Gap = gap;
        }
コード例 #2
0
        /// <summary>
        /// 返回毫米單位的HTML信息
        /// </summary>
        /// <param name="item">題型輸出結果</param>
        /// <param name="controlIndex">輸入框控件ID(主)</param>
        /// <param name="isInput">是否為可輸入項目</param>
        /// <param name="childIndex">輸入框控件ID(子)</param>
        /// <returns>HTML信息</returns>
        private string GetMillimeterHtml(LearnLengthUnitFormula item, int controlIndex, bool isInput, string childIndex = "S0")
        {
            StringBuilder html = new StringBuilder();

            if (isInput)
            {
                _answers.AppendFormat("{0};", Base64.EncodeBase64(item.LengthUnitItme.Millimeter.Value.ToString()));
                html.AppendFormat(INPUT_HTML_FORMAT, controlIndex, childIndex).AppendLine(string.Format(UNIT_HTML_FORMAT, Consts.MILLIMETER_UNIT));
            }
            else
            {
                html.AppendFormat(SPAN_HTML_FORMAT, item.LengthUnitItme.Millimeter).AppendLine(string.Format(UNIT_HTML_FORMAT, Consts.MILLIMETER_UNIT));
            }

            return(html.ToString());
        }
コード例 #3
0
        /// <summary>
        /// 返回分米單位的HTML信息
        /// </summary>
        /// <param name="item">題型輸出結果</param>
        /// <param name="controlIndex">輸入框控件ID(主)</param>
        /// <param name="isInput">是否為可輸入項目</param>
        /// <param name="childIndex">輸入框控件ID(子)</param>
        /// <returns>HTML信息</returns>
        private string GetRemainderDecimetreHtml(LearnLengthUnitFormula item, int controlIndex, bool isInput, string childIndex = "S0")
        {
            StringBuilder html = new StringBuilder();

            if (isInput)
            {
                _answers.AppendFormat("{0};", Base64.EncodeBase64(item.RemainderDecimetre.Value.ToString()));
                html.AppendFormat(INPUT_HTML_FORMAT, controlIndex, childIndex).AppendLine(string.Format(UNIT_HTML_FORMAT, Consts.DECIMETRE_UNIT));
            }
            else
            {
                // 考慮剩餘分米的輸出
                html.AppendFormat(SPAN_HTML_FORMAT, item.RemainderDecimetre.Value).AppendLine(string.Format(UNIT_HTML_FORMAT, Consts.DECIMETRE_UNIT));
            }

            return(html.ToString());
        }
コード例 #4
0
        /// <summary>
        /// 毫米轉換為釐米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(毫米或者釐米)</param>
        protected virtual void MillimeterConvertToCentimeter(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得釐米數量級
            int centimeter = CommonUtil.GetRandomNumber(1, 10);
            // 隨機編排填空項目(是毫米還是釐米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 毫米單位
                Millimeter = centimeter * 10,
                // 釐米單位
                Centimeter = centimeter
            };
            // 填空項目(毫米或者釐米)
            formula.Gap = gap;
        }
コード例 #5
0
        /// <summary>
        /// 毫米轉換為分米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(毫米或者分米)</param>
        protected virtual void MillimeterConvertToDecimetre(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得分米數量級
            int decimetre = CommonUtil.GetRandomNumber(1, 10);
            // 隨機編排填空項目(是毫米還是分米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 毫米單位
                Millimeter = decimetre * 100,
                // 分米單位
                Decimetre = decimetre
            };
            // 填空項目(毫米或者分米)
            formula.Gap = gap;
        }
コード例 #6
0
        /// <summary>
        /// 釐米轉換為分米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(釐米或者分米)</param>
        protected virtual void CentimeterConvertToDecimetre(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得釐米數量級
            int centimeter = CommonUtil.GetRandomNumber(1, 10) * 10;
            // 轉換為分米的換算
            int decimetre = centimeter / 10;
            // 隨機編排填空項目(是釐米還是分米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 釐米單位
                Centimeter = centimeter,
                // 分米單位
                Decimetre = decimetre
            };
            // 填空項目(釐米或者分米)
            formula.Gap = gap;
        }
コード例 #7
0
        /// <summary>
        /// 分米轉換為毫米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(分米或者毫米)</param>
        protected virtual void DecimetreConvertToMillimeter(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得分米數量級
            int decimetre = CommonUtil.GetRandomNumber(1, 10);
            // 轉換為毫米的換算
            int millimeter = decimetre * 100;
            // 隨機編排填空項目(是分米還是毫米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 分米單位
                Decimetre = decimetre,
                // 毫米單位
                Millimeter = millimeter
            };
            // 填空項目(分米或者毫米)
            formula.Gap = gap;
        }
コード例 #8
0
        /// <summary>
        /// 分米到釐米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(米或者釐米)</param>
        protected virtual void DecimetreConvertToCentimeter(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得分米數量級
            int decimetre = CommonUtil.GetRandomNumber(1, 10);
            // 轉換為釐米的換算
            int entimeter = decimetre * 10;
            // 隨機編排填空項目(是釐米還是分米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 分米單位
                Decimetre = decimetre,
                // 釐米單位
                Centimeter = entimeter
            };
            // 填空項目(米或者釐米)
            formula.Gap = gap;
        }
コード例 #9
0
        /// <summary>
        /// 算式作成
        /// </summary>
        /// <param name="p">題型參數</param>
        /// <param name="lengthUnitFunc">運算符取得用的表達式</param>
        private void MarkFormulaList(LearnLengthUnitParameter p, Func <LengthUnitTransformType> lengthUnitFunc)
        {
            // 當前反推判定次數(一次推算內次數累加)
            int defeated = 0;

            // 按照指定數量作成相應的數學計算式
            for (var i = 0; i < p.NumberOfQuestions; i++)
            {
                // 單一的長度轉換類型
                LengthUnitTransformType type = lengthUnitFunc();

                LearnLengthUnitFormula formula = new LearnLengthUnitFormula()
                {
                    LengthUnitTransType = type
                };
                if (_currencys.TryGetValue(type, out Action <LearnLengthUnitFormula, QuestionType> currency))
                {
                    currency(formula, p.QuestionType);
                }
                else
                {
                    throw new ArgumentException(MessageUtil.GetMessage(() => MsgResources.E0001L, type.ToString()));
                }

                if (CheckIsNeedInverseMethod(p.Formulas, formula))
                {
                    defeated++;
                    // 如果大於兩次則認為此題無法作成繼續下一題
                    if (defeated == INVERSE_NUMBER)
                    {
                        // 當前反推判定次數復原
                        defeated = 0;
                        continue;
                    }
                    i--;
                    continue;
                }
                p.Formulas.Add(formula);
            }
        }
コード例 #10
0
        /// <summary>
        /// 分米到米分米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(分米或者米分米)</param>
        protected virtual void DecimetreConvertToMeterExt(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得米數量級
            int meter = CommonUtil.GetRandomNumber(1, 9);
            // 隨機取得分米數量級
            int remainderDecimetre = CommonUtil.GetRandomNumber(1, 9);
            // 隨機編排填空項目(是分米還是米分米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 分米單位
                Decimetre = meter * 10 + remainderDecimetre,
                // 米單位
                Meter = meter
            };
            // 剩餘的分米
            formula.RemainderDecimetre = remainderDecimetre;
            // 填空項目(分米或者米、分米)
            formula.Gap = gap;
        }
コード例 #11
0
        /// <summary>
        /// 分米到米釐米
        /// </summary>
        /// <param name="formula">計算式作成</param>
        /// <param name="type">填空項目選擇(分米或者米釐米)</param>
        protected virtual void DecimetreConvertToMeterCentimeter(LearnLengthUnitFormula formula, QuestionType type)
        {
            // 隨機取得分米數量級
            int decimetre = CommonUtil.GetRandomNumber(11, 99);
            // 轉換為米的換算
            int meter = decimetre / 10;
            // 轉換為釐米的換算
            int centimeter = decimetre % 10 * 10;
            // 隨機編排填空項目(是分米還是米分米)
            GapFilling gap = GetRandomGapFilling(type);

            // 結果對象設置并返回
            formula.LengthUnitItme = new LengthUnit()
            {
                // 分米單位
                Decimetre = decimetre,
                // 米單位
                Meter = meter,
                // 釐米單位
                Centimeter = centimeter
            };
            // 填空項目(分米或者米、釐米)
            formula.Gap = gap;
        }
コード例 #12
0
 /// <summary>
 /// 判定是否需要反推并重新作成計算式
 /// </summary>
 /// <remarks>
 /// 情況1:完全一致
 /// </remarks>
 /// <param name="preFormulas">已得到的算式</param>
 /// <param name="currentFormula">當前算式</param>
 /// <returns>需要反推:true  正常情況: false</returns>
 private bool CheckIsNeedInverseMethod(IList <LearnLengthUnitFormula> preFormulas, LearnLengthUnitFormula currentFormula)
 {
     // 判斷當前算式是否已經出現過
     if (preFormulas.ToList().Any(d => d.LengthUnitItme.Meter == currentFormula.LengthUnitItme.Meter &&
                                  d.LengthUnitItme.Decimetre == currentFormula.LengthUnitItme.Decimetre &&
                                  d.LengthUnitItme.Centimeter == currentFormula.LengthUnitItme.Centimeter &&
                                  d.LengthUnitItme.Millimeter == currentFormula.LengthUnitItme.Millimeter &&
                                  d.LengthUnitTransType == currentFormula.LengthUnitTransType))
     {
         return(true);
     }
     return(false);
 }
コード例 #13
0
        /// <summary>
        /// 根據題型輸出結果作成HTML模板信息
        /// </summary>
        /// <param name="item">題型輸出結果</param>
        /// <param name="controlIndex">輸入框控件ID</param>
        /// <returns>HTML模板信息</returns>
        private string GetHtml(LearnLengthUnitFormula item, int controlIndex)
        {
            _answers.Length = 0;
            StringBuilder html = new StringBuilder();

            switch (item.LengthUnitTransType)
            {
            // 米到分米
            case LengthUnitTransformType.M2D:
                html.Append(GetMeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 米到釐米
            case LengthUnitTransformType.M2C:
                html.Append(GetMeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 米到毫米
            case LengthUnitTransformType.M2MM:
                html.Append(GetMeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMillimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 分米到米
            case LengthUnitTransformType.D2M:
                html.Append(GetDecimetreHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 分米到釐米
            case LengthUnitTransformType.D2C:
                html.Append(GetDecimetreHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 分米到毫米
            case LengthUnitTransformType.D2MM:
                html.Append(GetDecimetreHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMillimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 分米到米分米(有剩餘)
            case LengthUnitTransformType.D2MExt:
                html.Append(GetDecimetreHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetRemainderDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 分米到米釐米
            case LengthUnitTransformType.D2MC:
                html.Append(GetDecimetreHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 釐米到米
            case LengthUnitTransformType.C2M:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 釐米到分米
            case LengthUnitTransformType.C2D:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 釐米到毫米
            case LengthUnitTransformType.C2MM:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMillimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 釐米到米分米
            case LengthUnitTransformType.C2MD:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 釐米到分米毫米
            case LengthUnitTransformType.C2DMM:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetMillimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 釐米到米分米釐米(有剩餘)
            case LengthUnitTransformType.C2MDExt:
                html.Append(GetCentimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                html.Append(GetRemainderCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S2"));
                break;

            // 毫米到分米
            case LengthUnitTransformType.MM2D:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 毫米到釐米
            case LengthUnitTransformType.MM2C:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 毫米到米
            case LengthUnitTransformType.MM2M:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                break;

            // 毫米到米分米
            case LengthUnitTransformType.MM2MD:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 毫米到米分米釐米
            case LengthUnitTransformType.MM2MDC:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S2"));
                break;

            // 毫米到分米釐米
            case LengthUnitTransformType.MM2DC:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 毫米到米釐米
            case LengthUnitTransformType.MM2MC:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                break;

            // 毫米到米分米釐米毫米(有剩餘)
            case LengthUnitTransformType.MM2MDCExt:
                html.Append(GetMillimeterHtml(item, controlIndex, (item.Gap == GapFilling.Left)));
                html.AppendLine(EQUALTO_HTML);
                html.Append(GetMeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left)));
                html.Append(GetDecimetreHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1"));
                html.Append(GetCentimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S2"));
                html.Append(GetRemainderMillimeterHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S3"));
                break;
            }

            // 答案列表
            _answers.Length -= 1;
            html.AppendLine(string.Format("<input id=\"hidLluAnswer{0}\" type=\"hidden\" value=\"{1}\" />", controlIndex, _answers.ToString()));

            return(html.ToString());
        }