Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class training_traininglist
    Inherits System.Web.UI.Page

#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)

        'JavaScript の alert で表示する処理完了メッセージ
        If Not String.IsNullOrEmpty(Session(S_Training_ClientMessage)) Then
            Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "myalert", "<script language=JavaScript>alert('" & Session(S_Training_ClientMessage) & "');</script>", False)
            Session(S_Training_ClientMessage) = String.Empty
        End If

        If Not IsPostBack() Then
            CreateControls()

            Dim seireki As String = Com_Get_変数("西暦今年")
            Dim seirekiValue As Short
            If Short.TryParse(seireki, seirekiValue) Then
                dd_検索_開講年度.SelectedValue = seireki
            End If
            '検索条件を復元
            If Not IsNothing(_search) Then
                dd_検索_開講年度.SelectedValue = _search.開講年度
                dd_検索_開講月.SelectedValue = _search.開講月
                dd_検索_課程.SelectedValue = _search.課程
                txt_検索_keyword.Text = _search.Keyword
                dd_検索_申込状況.SelectedValue = _search.申込状況
                txt_検索_受講者氏名.Text = _search.受講者氏名

                If _search.ForceSearch Then
                    Search研修()

                    'ユーザコントロールを開く
                    Com_UC1_Visible("slideopen")
                End If
            End If
        End If
    End Sub
#End Region

#Region "***************** コントロールイベント *****************"
    Protected Sub btn_検索_Click(ByVal sender As Object, ByVal e As EventArgs)
        Search研修()

        'ユーザコントロールを閉じる
        Com_UC1_Visible("close")
    End Sub

    Protected Sub lv_研修_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
        Select Case e.CommandName
            Case "link"
                _param = New TrainingParam
                _param.履修年度 = DirectCast(e.Item.FindControl("lb_履修年度"), Label).Text
                _param.成績年度 = DirectCast(e.Item.FindControl("lb_成績年度"), Label).Text
                _param.分野CD = DirectCast(e.Item.FindControl("lb_分野CD"), Label).Text
                _param.科目CD = DirectCast(e.Item.FindControl("lb_科目CD"), Label).Text
                _param.講座CD = DirectCast(e.Item.FindControl("lb_講座CD"), Label).Text
                Session(S_Training_Seleted_Param) = _param

                Create研修詳細()
                CreateList受講者()

                'ユーザコントロールを開く
                Com_UC1_Visible("slideopen")
        End Select
    End Sub
#End Region

#Region "******************* Sub及びFunction ********************"
    Private Sub CreateControls()
        Create検索_開講年度()
        Create検索_開講月()
        Create検索_課程()
        Create検索_申込状況()
    End Sub

    Private Sub Create検索_開講年度()
        Using spm As New StoredProcedureManager("共通_教務_授業年度_DDL")
            spm.Fill()

            dd_検索_開講年度.DataSource = spm.ds.Tables(0)
        End Using

        dd_検索_開講年度.DataBind()
    End Sub

    Private Sub Create検索_開講月()
        Using spm As New StoredProcedureManager("共通_教務_開講月_DDL")
            spm.Fill()

            dd_検索_開講月.DataSource = spm.ds.Tables(0)
        End Using

        dd_検索_開講月.DataBind()
    End Sub

    Private Sub Create検索_課程()
        Using spm As New StoredProcedureManager("共通_課程統計_DDL")
            spm.AddPrmIn("@区分", SqlDbType.VarChar, "課程")
            spm.Fill()

            dd_検索_課程.DataSource = spm.ds.Tables(0)
        End Using

        dd_検索_課程.DataBind()
    End Sub

    Private Sub Create検索_申込状況()
        Using spm As New StoredProcedureManager("共通_変数_DDL")
            spm.AddPrmIn("@変数", SqlDbType.VarChar, "研修申込_申込状況")
            spm.Fill()

            dd_検索_申込状況.DataSource = spm.ds.Tables(0)
        End Using

        dd_検索_申込状況.DataBind()
    End Sub

    Private Sub CreateList研修()
        Dim param As TrainingSearch = DirectCast(Session(S_Training_Search), TrainingSearch)

        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("@課程", SqlDbType.VarChar, param.課程)
            spm.AddPrmIn("@keyword", SqlDbType.VarChar, param.Keyword)
            spm.AddPrmIn("@申込状況", SqlDbType.VarChar, param.申込状況)
            spm.AddPrmIn("@受講者氏名", SqlDbType.VarChar, param.受講者氏名)

            'パラメータ追加 S.Iguchi 20240419
            spm.AddPrmIn("@学園CD", SqlDbType.VarChar, _user.学園CD)
            spm.AddPrmIn("@市区町村CD", SqlDbType.VarChar, _user.市区町村CD)

            'パラメータ追加 S.Iguchi 20241118
            spm.AddPrmIn("@email", SqlDbType.VarChar, email)

            spm.Fill()

            lv_研修.DataSource = spm.ds.Tables(0)
        End Using

        lv_研修.DataBind()
    End Sub

    Private Sub Create研修詳細()
        Dim ctl As FormView
        ctl = DirectCast(DirectCast(Master.FindControl("msp_asp_usercon1"), PlaceHolder).Controls.Item(0).FindControl("frm_研修詳細"), FormView)

        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()

            ctl.DataSource = spm.ds.Tables(0)
        End Using

        ctl.DataBind()
    End Sub

    Private Sub CreateList受講者()
        Dim ctl As ListView
        ctl = DirectCast(DirectCast(Master.FindControl("msp_asp_usercon1"), PlaceHolder).Controls.Item(0).FindControl("lv_受講者"), ListView)

        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()

            ctl.DataSource = spm.ds.Tables(0)
        End Using

        ctl.DataBind()
    End Sub

    Private Sub Search研修()
        If IsNothing(_search) Then
            _search = New TrainingSearch
        End If
        _search.開講年度 = dd_検索_開講年度.SelectedValue
        _search.開講月 = dd_検索_開講月.SelectedValue
        _search.課程 = dd_検索_課程.SelectedValue
        _search.Keyword = txt_検索_keyword.Text
        _search.申込状況 = dd_検索_申込状況.SelectedValue
        _search.受講者氏名 = txt_検索_受講者氏名.Text
        Session(S_Training_Search) = _search

        CreateList研修()
    End Sub
#End Region
End Class
