Imports System.Data
Imports AppCommon
Imports AppVariable
Imports AppVariable_student

Partial Class mobile_questionnaire_AnswerSP
    Inherits System.Web.UI.Page

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

        Using q_table As DataTable = Q_CD質問_Get()
            If q_table Is Nothing OrElse q_table.Rows.Count = 0 Then
                Exit Sub
            End If
            lbl_QNO.Text = q_table.Rows(0).Item("QNO").ToString
            lbl_備考.Text = q_table.Rows(0).Item("備考").ToString.Replace(Environment.NewLine, "<br />")
            Session(S_Question_Selected_QNO) = q_table.Rows(0).Item("QNO").ToString
        End Using

        Call DataBind_grv講座()
        Call DataBind_frm要望()

    End Sub
#End Region

#Region "***************** コントロールイベント *****************"
    Protected Sub frm_要望_DataBound(sender As Object, e As EventArgs) Handles frm_要望.DataBound
        If frm_要望.CurrentMode = FormViewMode.ReadOnly Then
            If frm_要望.DataItemCount > 0 Then
                Dim lbl_回答日 As Label = CType(frm_要望.FindControl("lbl_回答日"), Label)

                If lbl_回答日.Text.Length > 0 Then
                    '回答済メッセージ表示
                    lbl_回答日.Text = "<br />" + lbl_回答日.Text + " 更新済み"
                End If
            End If
        End If
    End Sub
    Protected Sub frm_要望_ItemCommand(sender As Object, e As FormViewCommandEventArgs) Handles frm_要望.ItemCommand
        If e.CommandName = "回答" Then
            Dim txt要望1 As TextBox = CType(frm_要望.FindControl("txt要望1"), TextBox)
            Dim txt要望2 As TextBox = CType(frm_要望.FindControl("txt要望2"), TextBox)
            Dim txt要望3 As TextBox = CType(frm_要望.FindControl("txt要望3"), TextBox)

            Call Upd要望(txt要望1.Text, txt要望2.Text, txt要望3.Text)
            Call DataBind_frm要望()
        End If
    End Sub

    Protected Sub grv講座_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grv講座.RowCommand
        If e.CommandName = "回答記入" Then
            Dim lbl履修年度 As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl履修年度")
            Dim lbl成績年度 As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl成績年度")
            Dim lbl分野CD As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl分野CD")
            Dim lbl科目CD As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl科目CD")
            Dim lbl講座CD As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl講座CD")
            Dim lbl教員CD As Label = CType(e.CommandSource, Button).Parent.Parent.FindControl("lbl教員CD")

            'キーをセッションに保存
            Session(S_Question_Selected_Risyu_Nendo) = lbl履修年度.Text
            Session(S_Question_Selected_Seiseki_Nendo) = lbl成績年度.Text
            Session(S_Question_Selected_Bunya_CD) = lbl分野CD.Text
            Session(S_Question_Selected_Kamoku_CD) = lbl科目CD.Text
            Session(S_Question_Selected_Kouza_CD) = lbl講座CD.Text
            Session(S_Question_Selected_Kyouin_CD) = lbl教員CD.Text

            '詳細ページに遷移
            Response.Redirect(Com_Get_Content("menu_km_011_mb"))  'AnswerDetailSP.aspx
        End If
    End Sub
#End Region

#Region "******************* Sub及びFunction ********************"

    Private Function Q_CD質問_Get() As DataTable
        Using spm As New StoredProcedureManager("Q_回答_アンケート_SELECT")
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            spm.AddPrmIn("@対象日", Data.SqlDbType.DateTime, Now())
            spm.Fill()

            Return spm.ds.Tables(0)
        End Using
    End Function
    Private Sub DataBind_grv講座()
        grv講座.DataSource = Q_回答_Get()
        grv講座.DataBind()
    End Sub

    Private Function Q_回答_Get() As DataTable
        Using spm As New StoredProcedureManager("Q_回答_アンケート回答_SELECT")
            spm.AddPrmIn("@QNO", SqlDbType.Int, Session(S_Question_Selected_QNO))
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))

            spm.Fill()

            Return spm.ds.Tables(0)
        End Using
    End Function

    Private Sub DataBind_frm要望()
        frm_要望.DataSource = Q_要望_Get()
        frm_要望.DataBind()
    End Sub

    Private Function Q_要望_Get() As DataTable
        Using spm As New StoredProcedureManager("Q_回答_要望_SELECT")
            spm.AddPrmIn("@QNO", SqlDbType.Int, Session(S_Question_Selected_QNO))
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))

            spm.Fill()

            Return spm.ds.Tables(0)
        End Using
    End Function

    Private Sub Upd要望(ByVal str要望1 As String _
                       , ByVal str要望2 As String _
                       , ByVal str要望3 As String)

        Using spm As New StoredProcedureManager("Q_回答_要望_UPDATE")
            spm.AddPrmIn("@QNO", SqlDbType.Int, Session(S_Question_Selected_QNO))
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            spm.AddPrmIn("要望1", Data.SqlDbType.VarChar, 8000, str要望1)
            spm.AddPrmIn("要望2", Data.SqlDbType.VarChar, 8000, str要望2)
            spm.AddPrmIn("要望3", Data.SqlDbType.VarChar, 8000, str要望3)

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





End Class
