Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class AttendClassEdit
    Inherits System.Web.UI.Page

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        CType(frm_実施授業.FindControl("lb_回数"), Label).Text = Session(S_COM_Selected_Jyugyo_Kai)
    End Sub

#End Region

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

    Protected Sub gv_出欠_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gv_出欠.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If CType(e.Row.FindControl("色CD"), Label).Text <> "" Then
                e.Row.BackColor = Drawing.Color.FromName(CType(e.Row.FindControl("色CD"), Label).Text)
            ElseIf CType(e.Row.FindControl("出欠CD"), Label).Text = "" Then
                e.Row.BackColor = Drawing.Color.FromName("#F0F0F0")
            End If
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            Call Set出欠種()
        End If
    End Sub

    Protected Sub btn_戻る_Click(sender As Object, e As EventArgs) Handles btn_戻る.Click
        '出欠編集ページ呼び出し
        Response.Redirect(Com_Get_Content("menu_km_001", "close"))
    End Sub

    Protected Sub lbtn_出欠種別_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str種別 As String = CType(sender, LinkButton).CommandArgument.ToString
        Dim rb As RadioButtonList
        For Each row As GridViewRow In gv_出欠.Rows
            rb = DirectCast(row.FindControl("rbl_出欠種"), RadioButtonList)
            rb.SelectedValue = str種別
        Next
    End Sub

    Protected Sub sql_実施授業_Init(sender As Object, e As EventArgs) Handles sql_実施授業.Init
        sql_実施授業_SET()
    End Sub

    Protected Sub sql_出欠_Init(sender As Object, e As EventArgs) Handles sql_出欠.Init
        sql_出欠_SET()
    End Sub

#End Region

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

    Private Sub sql_実施授業_SET()
        Dim sds As SqlDataSource = sql_実施授業
        WebControlsUtil.DeclareSP(sds, "出欠_実施授業_個別_SELECT")
        With sds
            .SelectParameters.Add("履修年度", Session(S_COM_Selected_Risyu_Nendo))
            .SelectParameters.Add("成績年度", Session(S_COM_Selected_Seiseki_Nendo))
            .SelectParameters.Add("分野CD", Session(S_COM_Selected_Bunya_CD))
            .SelectParameters.Add("科目CD", Session(S_COM_Selected_Kamoku_CD))
            .SelectParameters.Add("講座CD", Session(S_COM_Selected_Kouza_CD))
            .SelectParameters.Add("回数", DbType.Int32, Session(S_COM_Selected_Jyugyo_Kai))
        End With
    End Sub

    Private Sub sql_出欠_SET()
        Dim sds As SqlDataSource = sql_出欠
        WebControlsUtil.DeclareSP(sds, "出欠_授業出欠_SELECT")
        With sds
            .SelectParameters.Add("履修年度", Session(S_COM_Selected_Risyu_Nendo))
            .SelectParameters.Add("成績年度", Session(S_COM_Selected_Seiseki_Nendo))
            .SelectParameters.Add("分野CD", Session(S_COM_Selected_Bunya_CD))
            .SelectParameters.Add("科目CD", Session(S_COM_Selected_Kamoku_CD))
            .SelectParameters.Add("講座CD", Session(S_COM_Selected_Kouza_CD))
            .SelectParameters.Add("回数", DbType.Int32, Session(S_COM_Selected_Jyugyo_Kai))
            .SelectParameters.Add("教員CD", DbType.String, Session(S_COM_UserCD))
        End With
    End Sub

    '出欠種の選択肢などを動的に設定
    Private Sub Set出欠種()
        Const INT_選択肢 As Integer = 4

        Dim ary出欠CD(INT_選択肢 - 1) As String
        Dim ary出欠名(INT_選択肢 - 1) As String

        Using spm As New StoredProcedureManager("SP出欠種名GET")
            spm.Fill()

            If Not spm.ds.Tables(0) Is Nothing Then
                For Each row As DataRow In spm.ds.Tables(0).Rows
                    Dim i As Integer
                    For i = 1 To INT_選択肢
                        ary出欠名(i - 1) = row("名前" & CStr(i)).ToString()
                        ary出欠CD(i - 1) = row("CD" & CStr(i)).ToString()
                    Next
                Next
            End If
        End Using

        'ヘッダ
        For i = 1 To INT_選択肢
            CType(gv_出欠.HeaderRow.FindControl("lbtn_出欠種" & CStr(i)), LinkButton).Text = ary出欠名(i - 1)
            CType(gv_出欠.HeaderRow.FindControl("lbtn_出欠種" & CStr(i)), LinkButton).CommandArgument = ary出欠CD(i - 1)
        Next

        '詳細
        For Each row As GridViewRow In gv_出欠.Rows
            CType(row.FindControl("rbl_出欠種"), RadioButtonList).Items.Clear()
            For i = 1 To INT_選択肢
                CType(row.FindControl("rbl_出欠種"), RadioButtonList).Items.Add(New ListItem(ary出欠名(i - 1), ary出欠CD(i - 1)))
                If CType(row.FindControl("出欠CD"), Label).Text <> "" Then
                    CType(row.FindControl("rbl_出欠種"), RadioButtonList).SelectedValue = CType(row.FindControl("出欠CD"), Label).Text
                End If
            Next
        Next
    End Sub

#End Region

End Class
