/// <summary> /// 動態作成html并按照一定的格式注入html模板中 /// </summary> /// <param name="p">通用參數類</param> /// <returns>HTML上下文內容</returns> public override string MakeHtmlContent(HowMuchMoreParameter p) { if (p.Formulas.Count == 0) { return(string.Empty); } int numberOfColumns = 0; bool isRowHtmlClosed = false; _brainpowerHint = p.BrainpowerHint; _brainpowerIndex = 0; int controlIndex = 0; StringBuilder html = new StringBuilder(); StringBuilder rowHtml = new StringBuilder(); StringBuilder listGroupHtml = new StringBuilder(); _gapFillingItems = new StringBuilder(); foreach (HowMuchMoreFormula item in p.Formulas) { // 隨機排序(個體顯示圖片是隨機的) _moreTypeArray = _moreTypeArray.OrderBy(x => Guid.NewGuid()).ToList(); isRowHtmlClosed = false; listGroupHtml.AppendLine("<div class=\"col-md-6 form-inline\">"); if (_brainpowerHint.FormulaIndex.Count > _brainpowerIndex && _brainpowerHint.FormulaIndex[_brainpowerIndex] == controlIndex) { listGroupHtml.AppendLine(string.Format("<ul {0} class=\"list-group list-group-ext\">", string.Format(DIALOGUE_JS_HTML_FORMAT, _brainpowerIndex++))); } else { listGroupHtml.AppendLine("<ul class=\"list-group list-group-ext\">"); } listGroupHtml.AppendLine("<li class=\"list-group-item list-group-item-ext-1\">"); listGroupHtml.AppendLine("<h4>"); listGroupHtml.AppendLine(GetProblemHtml(item)); listGroupHtml.AppendLine("</h4>"); listGroupHtml.AppendLine("</li>"); // 表示項目顯示 listGroupHtml.AppendLine("<li class=\"list-group-item list-group-item-ext-2\">"); listGroupHtml.AppendLine("<h4>"); listGroupHtml.AppendLine(SetDisplayItem(item)); listGroupHtml.AppendLine("</h4>"); listGroupHtml.AppendLine("</li>"); // 填空項目顯示 listGroupHtml.AppendLine("<li class=\"list-group-item list-group-item-ext-3\">"); listGroupHtml.AppendLine("<h4>"); listGroupHtml.AppendLine(SetDisplayGapFillingItem(item, controlIndex)); listGroupHtml.AppendLine("</h4>"); listGroupHtml.AppendLine("</li>"); // 結束符 listGroupHtml.AppendLine("</ul>"); listGroupHtml.AppendLine("<div class=\"divCorrectOrFault-4\">"); listGroupHtml.AppendLine(string.Format("<img id=\"imgOKHmm{0}\" src=\"../Content/image/correct.png\" class=\"imgCorrect-4\" />", controlIndex)); listGroupHtml.AppendLine(string.Format("<img id=\"imgNoHmm{0}\" src=\"../Content/image/fault.png\" class=\"imgFault-4\" />", controlIndex)); listGroupHtml.AppendLine("</div>"); listGroupHtml.AppendLine("</div>"); // 答案項目 listGroupHtml.AppendLine(string.Format("<input type=\"hidden\" id=\"hidHmmAnswer{0}\" value=\"{1}\" />", controlIndex, item.Answer)); controlIndex++; numberOfColumns++; if (numberOfColumns == 2) { rowHtml.AppendLine("<div class=\"row text-center row-margin-top\">"); rowHtml.Append(listGroupHtml.ToString()); rowHtml.AppendLine("</div>"); html.Append(rowHtml); isRowHtmlClosed = true; numberOfColumns = 0; rowHtml.Length = 0; listGroupHtml.Length = 0; } } if (!isRowHtmlClosed) { rowHtml.AppendLine("<div class=\"row text-center row-margin-top\">"); rowHtml.Append(listGroupHtml.ToString()); rowHtml.AppendLine("</div>"); html.Append(rowHtml); } if (html.Length != 0) { StringBuilder head = new StringBuilder(); // 題目標題顯示 head.AppendLine(string.Format(PAGE_HEADER_HTML_FORMAT, "HowMuchMore", "比多少")); // 答案項目 _gapFillingItems.Length -= 1; head.AppendLine(string.Format("<input type=\"hidden\" id=\"hidImgHmmHelpArray\" value=\"{0}\" />", _gapFillingItems.ToString())); html.Insert(0, "<div class=\"div-page-content\">").AppendLine(); // 會話提示內容保存至畫面 html.AppendLine(string.Format(DIALOGUE_CONTENT_HTML_FORMAT, GetDialogue())); html.AppendLine().Append("</div>"); html.Insert(0, head); } return(html.ToString()); }
/// <summary> /// 題型HTML模板作成 /// </summary> /// <param name="p">題型參數</param> /// <returns>題型HTML模板信息</returns> public override string MakeHtmlContent(ArithmeticOperationsParameter p) { if (p.Formulas.Count == 0) { return string.Empty; } int numberOfColumns = 0; bool isRowHtmlClosed = false; BrainpowerHint = p.BrainpowerHint; _brainpowerIndex = 0; int controlIndex = 0; StringBuilder html = new StringBuilder(); StringBuilder rowHtml = new StringBuilder(); StringBuilder colHtml = new StringBuilder(); foreach (ArithmeticOperationsFormula item in p.Formulas) { isRowHtmlClosed = false; colHtml.AppendLine("<div class=\"col-md-4 form-inline\">"); colHtml.AppendLine("<h5>"); if (item.AnswerIsRight) { // 第一級計算式左側的值 colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.LeftParameter, GapFilling.Left, controlIndex)); // 第一級計算式運算符 colHtml.AppendLine(string.Format(LABEL_HTML_FORMAT, item.Arithmetic.Sign.ToOperationUnicode())); colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.RightParameter, GapFilling.Right, controlIndex)); // 等號 colHtml.AppendLine(string.Format(EQUALTO_HTML_FORMAT, SignOfCompare.Equal.ToSignOfCompareString())); // 結果值 colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.Answer, GapFilling.Answer, controlIndex)); } else { // 結果值 colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.Answer, GapFilling.Answer, controlIndex)); // 等號 colHtml.AppendLine(string.Format(EQUALTO_HTML_FORMAT, SignOfCompare.Equal.ToSignOfCompareString())); // 第一級計算式左側的值 colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.LeftParameter, GapFilling.Left, controlIndex)); // 第一級計算式運算符 colHtml.AppendLine(string.Format(LABEL_HTML_FORMAT, item.Arithmetic.Sign.ToOperationUnicode())); colHtml.AppendLine(GetHtml(item.Arithmetic.Gap, item.Arithmetic.RightParameter, GapFilling.Right, controlIndex)); } colHtml.AppendLine("</h5>"); colHtml.AppendLine("<div class=\"divCorrectOrFault-1\">"); colHtml.AppendLine(string.Format("<img id=\"imgOKArithmetic{0}\" src=\"../Content/image/correct.png\" class=\"imgCorrect-1\" />", controlIndex.ToString().PadLeft(2, '0'))); colHtml.AppendLine(string.Format("<img id=\"imgNoArithmetic{0}\" src=\"../Content/image/fault.png\" class=\"imgFault-1\" />", controlIndex.ToString().PadLeft(2, '0'))); colHtml.AppendLine("</div>"); colHtml.AppendLine("</div>"); controlIndex++; numberOfColumns++; // 單位行上顯示3道題目 if (numberOfColumns == 3) { rowHtml.AppendLine("<div class=\"row text-center row-margin-top\">"); rowHtml.Append(colHtml.ToString()); rowHtml.AppendLine("</div>"); html.Append(rowHtml); isRowHtmlClosed = true; numberOfColumns = 0; rowHtml.Length = 0; colHtml.Length = 0; } } if (!isRowHtmlClosed) { rowHtml.AppendLine("<div class=\"row text-center row-margin-top\">"); rowHtml.Append(colHtml.ToString()); rowHtml.AppendLine("</div>"); html.Append(rowHtml); } if (html.Length != 0) { html.Insert(0, "<div class=\"div-page-content\">").AppendLine(); // 會話提示內容保存至畫面 html.AppendLine(string.Format(DIALOGUE_CONTENT_HTML_FORMAT, GetArithmeticDialogue())); html.AppendLine().Append("</div>"); html.Insert(0, string.Format(PAGE_HEADER_HTML_FORMAT, "Arithmetic", "四則運算")); } return html.ToString(); }