Imports System.Data
Imports AppVariable

Partial Class uc_TimeTable
    Inherits System.Web.UI.UserControl

#Region "********************** メンバ変数 **********************"

    Private _tmp時限 As String

#End Region

#Region "********************** プロパティ **********************"

    Private _kikan As String
    Public Property Kikan As String
        Get
            Return _kikan
        End Get
        Set(ByVal value As String)
            _kikan = value
        End Set
    End Property

#End Region

#Region "***************** コントロールイベント *****************"

    Protected Sub gv_時間割内_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gv_時間割内.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If _tmp時限 = CType(e.Row.FindControl("lb_時限表示"), Label).Text Then
                CType(e.Row.FindControl("lb_時限表示"), Label).Visible = False
            Else
                CType(e.Row.FindControl("lb_時限表示"), Label).Visible = True
            End If
            _tmp時限 = CType(e.Row.FindControl("lb_時限表示"), Label).Text

            Dim str時限 As String = CType(e.Row.FindControl("lb_時限"), Label).Text
            Dim ary曜日() As String = {"月", "火", "水", "木", "金", "土"}
            For Each str曜日 In ary曜日
                CType(e.Row.FindControl("gv_" & str曜日), GridView).DataSource = GetData_時間割コマ( _
                      _kikan _
                    , CType(e.Row.FindControl("lb_曜日" & str曜日), Label).Text _
                    , str時限 _
                )
                CType(e.Row.FindControl("gv_" & str曜日), GridView).DataBind()
            Next
        End If
    End Sub

#End Region

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

    Public Sub DataBind_時間割内()
        gv_時間割内.DataSource = GetData_時間割内()
        gv_時間割内.DataBind()
    End Sub

    Public Sub DataBind_時間割外()
        gv_時間割外.DataSource = GetData_時間割外()
        gv_時間割外.DataBind()
    End Sub

    Private Function GetData_時間割内() As DataSet
        Using spm As New StoredProcedureManager("時間割_履修_SELECT")
            spm.AddPrmIn("@期間", Data.SqlDbType.VarChar, 50, _kikan)
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            spm.Fill()

            Return spm.ds
        End Using
    End Function

    Private Function GetData_時間割コマ(ByVal 期間 As String, ByVal 曜日 As String, 時限 As Integer) As DataSet
        Using spm As New StoredProcedureManager("時間割_履修_コマ_SELECT")
            spm.AddPrmIn("@学籍NO", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            spm.AddPrmIn("@期間", Data.SqlDbType.VarChar, 50, 期間)
            spm.AddPrmIn("@曜日", Data.SqlDbType.VarChar, 10, 曜日)
            spm.AddPrmIn("@時限", Data.SqlDbType.Int, 時限)
            spm.Fill()

            Return spm.ds
        End Using
    End Function

    Private Function GetData_時間割外() As DataSet
        Using spm As New StoredProcedureManager("時間割_履修_時間割外_SELECT")
            spm.AddPrmIn("@期間", Data.SqlDbType.VarChar, 50, _kikan)
            spm.AddPrmIn("@USERCD", Data.SqlDbType.VarChar, 20, Session(S_COM_UserCD))
            spm.Fill()

            Return spm.ds
        End Using
    End Function

#End Region

End Class
