/// <summary> /// 角轉換為元(有剩餘) /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(元或者角)</param> protected virtual void JiaoConvertToYuanExt(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得角數量級 int jiao = CommonUtil.GetRandomNumber(10, 100); // 如果沒有產生角的餘量,那麼變換題型為角轉元 if (jiao % 10 == 0) { // 題型變換 formula.CurrencyTransType = CurrencyTransformType.J2Y; // 角轉換為元 JiaoConvertToYuan(formula, type); return; } // 轉換為元的換算 int yuan = jiao / 10; // 隨機編排填空項目(是角還是元) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 角單位 Jiao = jiao }; // 剩餘的角 formula.RemainderJiao = jiao % 10; // 填空項目(角或者元、角) formula.Gap = gap; }
/// <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 GetFenHtml(LearnCurrencyFormula item, int controlIndex, bool isInput, string childIndex = "S0") { StringBuilder html = new StringBuilder(); if (isInput) { _answers.AppendFormat("{0};", Base64.EncodeBase64(item.CurrencyUnit.Fen.Value.ToString())); html.AppendFormat(INPUT_HTML_FORMAT, controlIndex, childIndex).AppendLine(string.Format(CURRENCY_UNIT_HTML_FORMAT, Consts.FEN_UNIT)); } else { html.AppendFormat(SPAN_HTML_FORMAT, item.CurrencyUnit.Fen).AppendLine(string.Format(CURRENCY_UNIT_HTML_FORMAT, Consts.FEN_UNIT)); } return(html.ToString()); }
/// <summary> /// 分轉換為元角(有剩餘) /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(分或者元角)</param> protected virtual void FenConvertToYuanJiaoExt(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得分數量級 int fen = CommonUtil.GetRandomNumber(1, 1000); // 如果沒有產生分的餘量,那麼變換題型為分轉元角 if (fen % 10 == 0) { // 題型變換 formula.CurrencyTransType = CurrencyTransformType.F2YJ; // 分轉換為元角 FenConvertToYuanJiao(formula, type); return; } else if (fen % 100 == 0) { // 題型變換 formula.CurrencyTransType = CurrencyTransformType.F2Y; // 分轉換為元 FenConvertToYuan(formula, type); return; } // 轉換為元的換算 int yuan = fen / 100; // 轉換為角的換算 int jiao = fen % 100 / 10; // 隨機編排填空項目(是角還是分) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 角單位 Jiao = jiao, // 分單位 Fen = fen }; // 剩餘的分 formula.RemainderFen = fen % 10; // 填空項目(分或者角) formula.Gap = gap; }
/// <summary> /// 元轉換為分 /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(元或者分)</param> protected virtual void YuanConvertToFen(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得元數量級 int yuan = CommonUtil.GetRandomNumber(1, 10); // 轉換為分的換算 int fen = yuan * 100; // 隨機編排填空項目(是分還是元) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 分單位 Fen = fen }; // 填空項目(元或者分) formula.Gap = gap; }
/// <summary> /// 元轉換為角 /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(元或者角)</param> protected virtual void YuanConvertToJiao(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得元數量級 int yuan = CommonUtil.GetRandomNumber(1, 10); // 轉換為角的換算 int jiao = yuan * 10; // 隨機編排填空項目(是角還是元) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 角單位 Jiao = jiao }; // 填空項目(元或者角) formula.Gap = gap; }
/// <summary> /// 角轉換為分 /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(分或者角)</param> protected virtual void JiaoConvertToFen(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得角數量級 int jiao = CommonUtil.GetRandomNumber(1, 10); // 轉換為分的換算 int fen = jiao * 10; // 隨機編排填空項目(是角還是分) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 角單位 Jiao = jiao, // 分單位 Fen = fen }; // 填空項目(分或者角) formula.Gap = gap; }
/// <summary> /// 分轉換為元 /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(分或者元)</param> protected virtual void FenConvertToYuan(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得分數量級 int fen = CommonUtil.GetRandomNumber(1, 10) * 100; // 轉換為元的換算 int yuan = fen / 100; // 隨機編排填空項目(是角還是分) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 分單位 Fen = fen }; // 填空項目(分或者元) formula.Gap = gap; }
/// <summary> /// 算式作成 /// </summary> /// <param name="p">題型參數</param> /// <param name="currencyTransFunc">運算符取得用的表達式</param> private void MarkFormulaList(LearnCurrencyParameter p, Func <CurrencyTransformType> currencyTransFunc) { // 當前反推判定次數(一次推算內次數累加) int defeated = 0; // 按照指定數量作成相應的數學計算式 for (var i = 0; i < p.NumberOfQuestions; i++) { // 貨幣轉換類型 CurrencyTransformType type = currencyTransFunc(); LearnCurrencyFormula formula = new LearnCurrencyFormula() { CurrencyTransType = type }; if (_currencys.TryGetValue(type, out Action <LearnCurrencyFormula, 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); } }
/// <summary> /// 角轉換為元分 /// </summary> /// <param name="formula">計算式作成</param> /// <param name="type">填空項目選擇(元分或者角)</param> protected virtual void JiaoConvertToYuanFen(LearnCurrencyFormula formula, QuestionType type) { // 隨機取得角數量級 int jiao = CommonUtil.GetRandomNumber(1, 100); // 轉換為元的換算 int yuan = Convert.ToInt32(Math.Floor(Convert.ToDecimal(jiao) / 10.0m)); // 轉換為分的換算 int fen = (jiao % 10) * 10; // 隨機編排填空項目(是角還是分) GapFilling gap = GetRandomGapFilling(type); // 結果對象設置并返回 formula.CurrencyUnit = new Currency() { // 元單位 Yuan = yuan, // 角單位 Jiao = jiao, // 分單位 Fen = fen }; // 填空項目(分或者角) formula.Gap = gap; }
/// <summary> /// 判定是否需要反推并重新作成計算式 /// </summary> /// <remarks> /// 情況1:完全一致 /// </remarks> /// <param name="preFormulas">已得到的算式</param> /// <param name="currentFormula">當前算式</param> /// <returns>需要反推:true 正常情況: false</returns> private bool CheckIsNeedInverseMethod(IList <LearnCurrencyFormula> preFormulas, LearnCurrencyFormula currentFormula) { // 判斷當前算式是否已經出現過 if (preFormulas.ToList().Any(d => d.CurrencyUnit.Yuan == currentFormula.CurrencyUnit.Yuan && d.CurrencyUnit.Jiao == currentFormula.CurrencyUnit.Jiao && d.CurrencyUnit.Fen == currentFormula.CurrencyUnit.Fen && d.CurrencyTransType == currentFormula.CurrencyTransType)) { return(true); } return(false); }
/// <summary> /// 根據題型輸出結果作成HTML模板信息 /// </summary> /// <param name="item">題型輸出結果</param> /// <param name="controlIndex">輸入框控件ID</param> /// <returns>HTML模板信息</returns> private string GetHtml(LearnCurrencyFormula item, int controlIndex) { _answers.Length = 0; StringBuilder html = new StringBuilder(); switch (item.CurrencyTransType) { // 元轉角 case CurrencyTransformType.Y2J: html.Append(GetYuanHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetJiaoHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 元轉分 case CurrencyTransformType.Y2F: html.Append(GetYuanHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetFenHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 角轉元 case CurrencyTransformType.J2Y: html.Append(GetJiaoHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 角轉分 case CurrencyTransformType.J2F: html.Append(GetJiaoHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetFenHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 角轉元分 case CurrencyTransformType.J2YF: html.Append(GetJiaoHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); html.Append(GetFenHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1")); break; // 分轉元 case CurrencyTransformType.F2Y: html.Append(GetFenHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 分轉角 case CurrencyTransformType.F2J: html.Append(GetFenHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetJiaoHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 分轉元角 case CurrencyTransformType.F2YJ: html.Append(GetFenHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); html.Append(GetJiaoHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1")); break; // 角轉元(有剩餘) case CurrencyTransformType.J2YExt: html.Append(GetJiaoHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); html.Append(GetRemainderJiaoHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); break; // 分轉元角(有剩餘) case CurrencyTransformType.F2YJExt: html.Append(GetFenHtml(item, controlIndex, (item.Gap == GapFilling.Left))); html.AppendLine(EQUALTO_HTML); html.Append(GetYuanHtml(item, controlIndex, !(item.Gap == GapFilling.Left))); html.Append(GetJiaoHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S1")); html.Append(GetRemainderFenHtml(item, controlIndex, !(item.Gap == GapFilling.Left), "S2")); break; } // 答案列表 _answers.Length -= 1; html.AppendLine(string.Format("<input id=\"hidLcAnswer{0}\" type=\"hidden\" value=\"{1}\" />", controlIndex, _answers.ToString())); return(html.ToString()); }