示例#1
0
        /// <summary>
        /// 初期表示
        /// </summary>
        private void PageInit()
        {
            logger.StartMethod(MethodBase.GetCurrentMethod().Name);

            // 表題の設定
            LabelQuestion.Text = "よんたくもんだい";

            // ボタンの設定
            Button1.Text    = "1ねんせいのかんじ";
            Button2.Text    = "1~2ねんせいのかんじ";
            Button3.Text    = "2ねんせいのかんじ";
            Button4.Visible = false;

            HiddenFieldOk.Value       = "0";
            HiddenFieldNg.Value       = "0";
            RepeaterRireki.DataSource = null;
            RepeaterRireki.DataBind();

            // セッションクリア
            SessionRemove();

            PanelKekka.Visible = false;

            logger.EndMethod(MethodBase.GetCurrentMethod().Name);
        }
示例#2
0
        /// <summary>
        /// 解答クリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonAnswer_Click(object sender, EventArgs e)
        {
            try
            {
                logger.StartMethod(MethodBase.GetCurrentMethod().Name);

                // 押下されたボタンのテキストを取得
                string answer = ((Button)sender).Text;

                if (answer.Equals("おわる"))
                {
                    // セッションクリア
                    SessionRemove();

                    // メニューに遷移
                    Response.Redirect("~/Menu.aspx", false);
                    return;
                }

                // トークンチェック
                CheckBasePageToken();

                switch (answer)
                {
                case "1ねんせいのかんじ":
                {
                    string level = "1";
                    string type  = "かき";
                    string mode  = "一致";
                    HiddenFieldType.Value  = type;
                    HiddenFieldLevel.Value = level;
                    SetMondai(level, type, mode);
                }
                    Button4.Visible    = true;
                    PanelKekka.Visible = false;
                    break;

                case "1~2ねんせいのかんじ":
                {
                    string level = "2";
                    string type  = "かき";
                    HiddenFieldType.Value  = type;
                    HiddenFieldLevel.Value = level;
                    SetMondai(level, type);
                }
                    Button4.Visible    = true;
                    PanelKekka.Visible = false;
                    break;

                case "2ねんせいのかんじ":
                {
                    string level = "2";
                    string type  = "かき";
                    string mode  = "一致";
                    HiddenFieldType.Value  = type;
                    HiddenFieldLevel.Value = level;
                    SetMondai(level, type, mode);
                }
                    Button4.Visible    = true;
                    PanelKekka.Visible = false;
                    break;

                case "つぎへ":
                {
                    string level = HiddenFieldLevel.Value;
                    string type  = HiddenFieldType.Value;
                    SetMondai(level, type);
                    PanelKekka.Visible = false;
                }
                break;

                default:
                    // セッションから問題を取得
                    DataRow mondaiRow = Session["mondai"] as DataRow;

                    // 結果の設定
                    YontakuLogic logic = new YontakuLogic();
                    (bool result, string text) = logic.GetResult(answer, mondaiRow);
                    LabelQuestion.Text         = text;

                    // 正解率の表示
                    decimal.TryParse(HiddenFieldOk.Value, out decimal ok);
                    decimal.TryParse(HiddenFieldNg.Value, out decimal ng);
                    string resultText = logic.GetResultText(result, ref ok, ref ng);
                    LabelResult.Text    = resultText;
                    HiddenFieldOk.Value = ok.ToString();
                    HiddenFieldNg.Value = ng.ToString();

                    // 履歴の設定
                    List <string> rireki = Session["rireki"] as List <string>;
                    string        header = LabelQuestionTitle.Text;
                    rireki = logic.AddRireki(rireki, header, answer, mondaiRow);
                    RepeaterRireki.DataSource = rireki;
                    RepeaterRireki.DataBind();
                    Session["rireki"] = rireki;

                    // 出題した問題を元のテーブルから削除
                    if (Session["table"] is DataTable mondaiTable)
                    {
                        mondaiTable.Rows.Remove(mondaiRow);
                    }

                    // ボタンの設定
                    Button1.Text    = "おわる";
                    Button2.Text    = "つぎへ";
                    Button3.Visible = false;
                    Button4.Visible = false;

                    PanelKekka.Visible = true;
                    break;
                }
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.ToString();

                logger.WriteException(MethodBase.GetCurrentMethod().Name, ex);
            }
            finally
            {
                logger.EndMethod(MethodBase.GetCurrentMethod().Name);
            }
        }