Imports AppCommon
Imports AppVariable

Partial Class AttendClass
    Inherits System.Web.UI.Page

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

    Private Const COLUMN_MAX As Integer = 15

#End Region

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

    Private _RowCnt As Integer = 1

#End Region

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        gv_Page.PageIndex = Session(S_Attend_Selected_Syussekibo_PageIndex)
    End Sub

#End Region

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

    Protected Sub gv_Page_PageIndexChanged(sender As Object, e As EventArgs) Handles gv_Page.PageIndexChanged
        Session(S_Attend_Selected_Syussekibo_PageIndex) = gv_Page.PageIndex
        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub gv_出欠一覧_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_出欠一覧.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If _RowCnt = 1 Then
                e.Row.BackColor = Drawing.Color.FromName("#6B696B")
                CType(e.Row.FindControl("lb_学年"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_所属"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_学籍NO"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_氏名"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_ふり"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_区分"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_出席率"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
                CType(e.Row.FindControl("lb_欠席数"), Label).ForeColor = Drawing.Color.FromName("#FFFFFF")
            End If

            Dim ColmunCnt As Integer = 1
            While (ColmunCnt <= COLUMN_MAX)
                If CType(e.Row.FindControl("授" & ColmunCnt), Label).Text = "" Then
                    CType(e.Row.FindControl("授" & ColmunCnt), Label).Visible = False
                Else
                    CType(e.Row.FindControl("授" & ColmunCnt), Label).Visible = True
                End If

                If CType(e.Row.FindControl("色" & ColmunCnt), Label).Text <> "" Then
                    e.Row.Cells(7 + ColmunCnt).BackColor = Drawing.Color.FromName(CType(e.Row.FindControl("色" & ColmunCnt), Label).Text)
                ElseIf CType(e.Row.FindControl("出" & ColmunCnt), Label).Text = "" Then
                    e.Row.Cells(7 + ColmunCnt).BackColor = Drawing.Color.FromName("#F0F0F0")
                End If

                ColmunCnt = ColmunCnt + 1
            End While

            _RowCnt = _RowCnt + 1
        ElseIf e.Row.RowType = DataControlRowType.Footer Then
            If gv_出欠一覧.Rows.Count <= 1 Then
                gv_Page.Visible = False
                gv_出欠一覧.Visible = False
                If Not IsNothing(Session(S_COM_Selected_Kouza_CD)) Then
                    pnl_empty_出席簿.Visible = True
                End If
            Else
                gv_Page.Visible = True
                gv_出欠一覧.Visible = True
                pnl_empty_出席簿.Visible = False
            End If

            If IsNothing(Session(S_COM_Selected_Kouza_CD)) Then
                pnl_empty_出席簿.Visible = False
            End If
        End If
    End Sub

    Protected Sub gv_出欠一覧_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gv_出欠一覧.RowCommand
        If e.CommandName = "edit_cst" Then
            出欠編集(CInt(e.CommandArgument))
        End If
    End Sub

    Protected Sub sql_page_Init(sender As Object, e As EventArgs) Handles sql_page.Init
        sql_page_select()
    End Sub

    Protected Sub sql_出席簿_Init(sender As Object, e As EventArgs) Handles sql_出席簿.Init
        If Session(S_Attend_Selected_Syussekibo_PageIndex) Is Nothing Then
            'ページインデックスに既定ぺージセット
            Session(S_Attend_Selected_Syussekibo_PageIndex) = Page取得()
        End If

        sql_出席簿_SET()
    End Sub

#End Region

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

    Private Sub sql_page_select()
        Dim sds As SqlDataSource = sql_page
        WebControlsUtil.DeclareSP(sds, "出欠_出席簿PAGE_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))
        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("Page", Session(S_Attend_Selected_Syussekibo_PageIndex))
            .SelectParameters.Add("教員CD", Session(S_COM_UserCD))
        End With
    End Sub

    Private Function Page取得() As Integer
        Dim ret As Integer

        Using spm As New StoredProcedureManager("出欠_MAXPAGE_OUTPUT")
            spm.AddPrmIn("@履修年度", Data.SqlDbType.SmallInt, Session(S_COM_Selected_Risyu_Nendo))
            spm.AddPrmIn("@成績年度", Data.SqlDbType.SmallInt, Session(S_COM_Selected_Seiseki_Nendo))
            spm.AddPrmIn("@分野CD", Data.SqlDbType.VarChar, Session(S_COM_Selected_Bunya_CD))
            spm.AddPrmIn("@科目CD", Data.SqlDbType.VarChar, Session(S_COM_Selected_Kamoku_CD))
            spm.AddPrmIn("@講座CD", Data.SqlDbType.VarChar, Session(S_COM_Selected_Kouza_CD))
            spm.AddPrmOut("@MAXPAGE", Data.SqlDbType.Int)
            spm.Exec()

            ret = spm.GetValue("@MAXPAGE")
        End Using

        Return ret
    End Function

    Private Sub 出欠編集(no As Integer)
        '授業が選択されていない場合
        If Session(S_COM_Selected_Risyu_Nendo) Is Nothing Then
            Exit Sub
        End If

        '選択された授業回数の保持
        Session(S_COM_Selected_Jyugyo_Kai) = no + (Session(S_Attend_Selected_Syussekibo_PageIndex)) * 15

        '出欠編集ページ呼び出し
        Response.Redirect(Com_Get_Content("menu_km_002"))
    End Sub

#End Region

End Class
