Imports System.Data
Imports AppCommon
Imports AppVariable
Imports AppVariable_student

Partial Class mobile_questionnaire_AnswerDeatilSP
    Inherits System.Web.UI.Page

    Private Const Cnt As Integer = 15 '質問数

#Region "******************** ページイベント ********************"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
#End Region

#Region "***************** コントロールイベント *****************"
    Protected Sub btn_戻る_Click(sender As Object, e As EventArgs) Handles btn_戻る1.Click, btn_戻る2.Click
        '授業アンケートの講座一覧ページに戻る
        Response.Redirect(Com_Get_Content("menu_km_009_mb"))  'AnswerSP.aspx
    End Sub

    Protected Sub btn_回答_Click(sender As Object, e As EventArgs) Handles btn_回答1.Click, btn_回答2.Click
        For Each lv As ListViewItem In lsv_質問回答.Items
            Dim arrayAnswers As ArrayList = New ArrayList()
            Dim arrayAnswers2 As ArrayList = New ArrayList()
            Dim txt備考 As TextBox = CType(lv.FindControl("txt_備考"), TextBox)

            For i As Integer = 1 To Cnt
                Dim rbtn As RadioButtonList = CType(lv.FindControl("rbtn_A" & i.ToString), RadioButtonList)
                Dim rbtn_二択 As RadioButtonList = CType(lv.FindControl("rbtn_A" & i.ToString & "_二択"), RadioButtonList)

                arrayAnswers.Add(rbtn.SelectedValue)
                arrayAnswers2.Add(rbtn_二択.SelectedValue)
            Next

            Call Upd回答(arrayAnswers, arrayAnswers2, txt備考)

            lsv_質問回答.DataBind()
        Next
    End Sub

    Protected Sub sql_質問回答_Init(sender As Object, e As EventArgs) Handles sql_質問回答.Init
        sql_質問回答_select()
    End Sub

    Protected Sub sql_選択肢_Init(sender As Object, e As EventArgs) Handles sql_選択肢.Init
        Dim sds As SqlDataSource = sql_選択肢
        WebControlsUtil.DeclareSP(sds, "Q_回答_選択肢_SELECT")
        With sds
            .SelectParameters.Add("QNO", Session(S_Question_Selected_QNO))
        End With
    End Sub

    Protected Sub sql_二択回答_Init(sender As Object, e As EventArgs) Handles sql_二択回答.Init
        Dim sds As SqlDataSource = sql_二択回答
        WebControlsUtil.DeclareSP(sds, "Q_回答_二択回答_SELECT")
        With sds
            .SelectParameters.Add("QNO", Session(S_Question_Selected_QNO))
        End With
    End Sub

    Protected Sub lsv_質問回答_DataBound(sender As Object, e As EventArgs) Handles lsv_質問回答.DataBound
        If lsv_質問回答.Items.Count = 0 Then
            btn_回答1.Visible = False
            btn_回答2.Visible = False
        End If
    End Sub

    Protected Sub lsv_質問回答_ItemDataBound(sender As Object, e As ListViewItemEventArgs) Handles lsv_質問回答.ItemDataBound
        If e.Item.ItemType = ListViewItemType.DataItem Then
            For i As Integer = 1 To Cnt
                Dim strAnswer As String = CType(e.Item.FindControl("lbl_A" & i.ToString), Label).Text
                Dim strAnswer2 As String = CType(e.Item.FindControl("lbl_A" & i.ToString & "_二択"), Label).Text

                Dim rbtn As RadioButtonList = CType(e.Item.FindControl("rbtn_A" & i.ToString), RadioButtonList)
                Dim rbtn_二択 As RadioButtonList = CType(e.Item.FindControl("rbtn_A" & i.ToString & "_二択"), RadioButtonList)

                rbtn.SelectedValue = strAnswer
                rbtn_二択.SelectedValue = strAnswer2

                '質問の本文がなければ、行を非表示
                Dim str表示FLG As String = CType(e.Item.FindControl("lbl_表示FLG_" & i.ToString), Label).Text
                Dim row As HtmlTableRow = CType(e.Item.FindControl("row_" & i.ToString), HtmlTableRow)
                row.Visible = IIf(str表示FLG = "1", True, False)
            Next
        End If
    End Sub
#End Region

#Region "******************* Sub及びFunction ********************"
    Private Sub sql_質問回答_select()
        Dim sds As SqlDataSource = sql_質問回答
        WebControlsUtil.DeclareSP(sds, "Q_モバイル_講座別回答_SELECT")
        With sds
            .SelectParameters.Add("QNO", Session(S_Question_Selected_QNO))
            .SelectParameters.Add("履修年度", Session(S_Question_Selected_Risyu_Nendo))
            .SelectParameters.Add("成績年度", Session(S_Question_Selected_Seiseki_Nendo))
            .SelectParameters.Add("分野CD", Session(S_Question_Selected_Bunya_CD))
            .SelectParameters.Add("科目CD", Session(S_Question_Selected_Kamoku_CD))
            .SelectParameters.Add("講座CD", Session(S_Question_Selected_Kouza_CD))
            .SelectParameters.Add("教員CD", Session(S_Question_Selected_Kyouin_CD))
            .SelectParameters.Add("学籍NO", Session(S_COM_UserCD))
        End With
    End Sub

    Private Sub Upd回答(ByRef arrayAnswers As ArrayList _
                      , ByRef arrayAnswers2 As ArrayList _
                      , ByRef txt備考 As TextBox)

        Using spm As New StoredProcedureManager("Q_回答_アンケート回答_UPDATE")
            spm.AddPrmIn("@QNO", SqlDbType.Int, Session(S_Question_Selected_QNO))
            spm.AddPrmIn("@履修年度", SqlDbType.SmallInt, Session(S_Question_Selected_Risyu_Nendo))
            spm.AddPrmIn("@成績年度", SqlDbType.SmallInt, Session(S_Question_Selected_Seiseki_Nendo))
            spm.AddPrmIn("@分野CD", SqlDbType.VarChar, 20, Session(S_Question_Selected_Bunya_CD))
            spm.AddPrmIn("@科目CD", SqlDbType.VarChar, 20, Session(S_Question_Selected_Kamoku_CD))
            spm.AddPrmIn("@講座CD", SqlDbType.VarChar, 20, Session(S_Question_Selected_Kouza_CD))
            spm.AddPrmIn("@教員CD", SqlDbType.VarChar, 20, Session(S_Question_Selected_Kyouin_CD))
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            'A1～A15
            For i As Integer = 1 To Cnt
                spm.AddPrmIn("@A" & i.ToString, SqlDbType.VarChar, 2, arrayAnswers.Item(i - 1).ToString())
            Next
            'A1_二択～A15_二択
            For i As Integer = 1 To Cnt
                spm.AddPrmIn("@A" & i.ToString & "_二択", SqlDbType.VarChar, 2, arrayAnswers2.Item(i - 1).ToString())
            Next

            spm.AddPrmIn("@備考", Data.SqlDbType.NVarChar, 500, txt備考.Text)

            spm.Exec()
        End Using
    End Sub
#End Region


End Class
