Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class Student_TimeTable
    Inherits System.Web.UI.Page

#Region "************************* 定数 *************************"

    Private Const SESSION_TAB_SELECTED As String = "Comp_Selected_Syns_Kikan"   '選択中のタブ

#End Region

#Region "******************** ページイベント ********************"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '---------------------------------------------------------------
        'HTMLタグを追加
        '---------------------------------------------------------------
        Dim ctl As Control = Page.Master.FindControl("msp_header")
        'CSS
        SetTagCss(ctl, "timetable.css")

        '期間タブをバインド
        Set履修期間()

        '期間タブの初期値を設定
        If Session(SESSION_TAB_SELECTED) Is Nothing Then
            Session(SESSION_TAB_SELECTED) = 履修期間既定()
        End If

        '期間タブを選択状態にする
        If menu_履修期間.Items.Count > 0 Then
            For Each i As MenuItem In menu_履修期間.Items
                If i.Value = Session(SESSION_TAB_SELECTED) Then
                    i.Selected = True
                End If
            Next
        End If

        '時間割データをバインド
        uc_TimeTable.Kikan = Session(SESSION_TAB_SELECTED)
        uc_TimeTable.DataBind_時間割内()
        uc_TimeTable.DataBind_時間割外()

        '印刷ページへの遷移スクリプト
        Dim param As String
        param = "TimeTablePrint.aspx"
        lb_印刷.Attributes("onclick") = "window.open('" & param & "','_blank');return false;"
    End Sub

#End Region

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

    Protected Sub menu_登録期_MenuItemClick(sender As Object, e As MenuEventArgs) Handles menu_履修期間.MenuItemClick
        Session(SESSION_TAB_SELECTED) = e.Item.Value

        If e.Item.Depth = 0 Then
            Response.Redirect(Request.FilePath.ToString)
        End If
    End Sub

#End Region

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

    Private Function 履修期間既定() As String
        Dim ret As String = ""

        Using spm As New StoredProcedureManager("時間割_履修期間_既定_OUTPUT")
            spm.AddPrmOut("@既定履修期間", Data.SqlDbType.VarChar, 50)
            spm.Exec()

            ret = spm.GetValue("@既定履修期間")
        End Using

        Return ret
    End Function

    '-------------------------------------------------------------
    '取得したデータをメニューコントロールへセットする。
    '-------------------------------------------------------------
    Private Sub Set履修期間()
        Dim ds As DataSet = GetData_履修期間()

        If Not ds.Tables(0) Is Nothing Then
            For Each masterRow As DataRow In ds.Tables(0).Rows
                Dim masterItem As New MenuItem(masterRow("期間名").ToString(), masterRow("期間").ToString())
                menu_履修期間.Items.Add(masterItem)
            Next
        End If
    End Sub

    '-------------------------------------------------------------
    'データベースから登録期を取得し返す。
    '-------------------------------------------------------------
    Private Function GetData_履修期間() As DataSet
        Using spm As New StoredProcedureManager("時間割_履修期間_SELECT")
            spm.Fill()

            Return spm.ds
        End Using
    End Function

#End Region

End Class
