Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class training_uc_applylist
    Inherits System.Web.UI.UserControl

#Region "******************** メンバ変数 ********************"
    Private _search As TrainingSearch
    Private _param As TrainingParam
    Private _user As LoginUser
#End Region

#Region "******************** ページイベント ********************"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _search = DirectCast(Session(S_Training_Search), TrainingSearch)
        _param = DirectCast(Session(S_Training_Seleted_Param), TrainingParam)
        _user = DirectCast(Session(S_COM_LoginUser), LoginUser)

        If Not IsPostBack() Then
            If Not IsNothing(_search) AndAlso _search.ForceSearch Then
                Create研修詳細()
                CreateList受講者()

                _search.ForceSearch = False
                Session(S_Training_Search) = _search
            End If
        End If
    End Sub
#End Region

#Region "***************** コントロールイベント *****************"
    Protected Sub frm_研修詳細_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim msg As String = DirectCast(frm_研修詳細.FindControl("lb_新規申込NG"), Label).Text
        lb_新規申込NG.Text = msg
        If String.Empty.Equals(msg) Then
            btn_新規申込.Visible = True
            lb_新規申込NG.Visible = False
        Else
            btn_新規申込.Visible = False
            lb_新規申込NG.Visible = True
        End If

        Dim lb As Label
        lb = DirectCast(frm_研修詳細.FindControl("lb_申込期限"), Label)
        If String.IsNullOrEmpty(lb.Text) Then
            lb.Text = "なし"
        End If
        lb = DirectCast(frm_研修詳細.FindControl("lb_定員"), Label)
        If String.IsNullOrEmpty(lb.Text) Then
            lb.Text = "なし"
        End If

    End Sub

    Protected Sub lv_受講者_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
        Select Case e.CommandName
            Case "link"
                _param.連番 = DirectCast(e.Item.FindControl("lb_連番"), Label).Text

                Dim fncCd As String
                Select Case DirectCast(e.Item.FindControl("lb_申込状況"), Label).Text
                    Case "一時保存"
                        fncCd = FunctionCd.TrainingApplyRegister
                        _param.Mode = ScreenMode.Temporary
                        _param.Referer = FunctionCd.TrainingList
                    Case Else
                        fncCd = FunctionCd.TrainingApplyConfirm
                End Select

                Session(S_Training_Seleted_Param) = _param

                'ページ遷移
                Response.Redirect(Com_Get_Content(fncCd))
        End Select
    End Sub

    Protected Sub btn_新規申込_Click(ByVal sender As Object, ByVal e As EventArgs)
        _param.連番 = 0
        _param.Mode = ScreenMode.Additions
        _param.Referer = FunctionCd.TrainingList
        Session(S_Training_Seleted_Param) = _param

        'ページ遷移
        Response.Redirect(Com_Get_Content(FunctionCd.TrainingApplyRegister))
    End Sub
#End Region

#Region "******************* Sub及びFunction ********************"
    Private Sub Create研修詳細()
        Using spm As New StoredProcedureManager("申込_研修詳細_SELECT")
            spm.AddPrmIn("@履修年度", SqlDbType.SmallInt, _param.履修年度)
            spm.AddPrmIn("@成績年度", SqlDbType.SmallInt, _param.成績年度)
            spm.AddPrmIn("@分野CD", SqlDbType.VarChar, _param.分野CD)
            spm.AddPrmIn("@科目CD", SqlDbType.VarChar, _param.科目CD)
            spm.AddPrmIn("@講座CD", SqlDbType.VarChar, _param.講座CD)
            spm.Fill()

            frm_研修詳細.DataSource = spm.ds.Tables(0)
        End Using

        frm_研修詳細.DataBind()
    End Sub

    Private Sub CreateList受講者()

        Dim dt = GetUserData(_user.USERCD, True)
        Dim email = dt.Rows(0)("EMAIL")

        Using spm As New StoredProcedureManager("申込_受講者一覧_SELECT")
            spm.AddPrmIn("@履修年度", SqlDbType.SmallInt, _param.履修年度)
            spm.AddPrmIn("@成績年度", SqlDbType.SmallInt, _param.成績年度)
            spm.AddPrmIn("@分野CD", SqlDbType.VarChar, _param.分野CD)
            spm.AddPrmIn("@科目CD", SqlDbType.VarChar, _param.科目CD)
            spm.AddPrmIn("@講座CD", SqlDbType.VarChar, _param.講座CD)
            spm.AddPrmIn("@学園CD", SqlDbType.VarChar, _user.学園CD)
            spm.AddPrmIn("@市区町村CD", SqlDbType.VarChar, _user.市区町村CD)
            spm.AddPrmIn("@EMAIL", SqlDbType.VarChar, email)
            spm.Fill()

            lv_受講者.DataSource = spm.ds.Tables(0)
        End Using

        lv_受講者.DataBind()
    End Sub
#End Region

End Class
