Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class training_documentconfirm
    Inherits System.Web.UI.Page

#Region "******************** メンバ変数 ********************"
    Private _param As TrainingParam
#End Region

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

        '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
            uc_TrainingInfo.Create研修詳細()
            Bind書類()
            CreateList書類添付(lv_書類添付_課題演習資料, "課題演習資料")
            CreateList書類添付(lv_書類添付_その他, "その他")
        End If
    End Sub
#End Region

#Region "***************** コントロールイベント *****************"
    Protected Sub btn_戻る_Click(ByVal sender As Object, ByVal e As EventArgs)
        'ページ遷移
        Response.Redirect(Com_Get_Content(FunctionCd.TrainingApplyConfirm))
    End Sub

    Protected Sub btn_編集_Click(ByVal sender As Object, ByVal e As EventArgs)
        _param.Mode = ScreenMode.Edits
        _param.Referer = FunctionCd.TrainingDocumentConfirm
        Session(S_Training_Seleted_Param) = _param

        'ページ遷移
        Response.Redirect(Com_Get_Content(FunctionCd.TrainingDocumentRegister))
    End Sub

    Protected Sub lv_書類添付_課題演習資料_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
        Select Case e.CommandName
            Case "download"
                Dim dt As DataTable
                Using spm As New StoredProcedureManager("申込_書類添付_SELECT")
                    spm.AddPrmIn("@id", SqlDbType.Int, DirectCast(e.Item.FindControl("lb_id"), Label).Text)
                    spm.Fill()

                    dt = spm.ds.Tables(0)
                End Using

                Response.ContentType = "application/octet-stream"
                Response.HeaderEncoding = System.Text.Encoding.GetEncoding("SHIFT-JIS")
                Response.AddHeader("Content-Disposition", "attachment; filename=" & DirectCast(e.Item.FindControl("lnkb_file_name"), LinkButton).Text)
                Response.BinaryWrite(CType(dt.Rows(0)("file_binary"), Byte()))
                Response.Flush()
                Response.End()
        End Select
    End Sub

    Protected Sub lv_書類添付_その他_ItemCommand(ByVal sender As Object, ByVal e As ListViewCommandEventArgs)
        Select Case e.CommandName
            Case "download"
                Dim dt As DataTable
                Using spm As New StoredProcedureManager("申込_書類添付_SELECT")
                    spm.AddPrmIn("@id", SqlDbType.Int, DirectCast(e.Item.FindControl("lb_id"), Label).Text)
                    spm.Fill()

                    dt = spm.ds.Tables(0)
                End Using

                Response.ContentType = "application/octet-stream"
                Response.HeaderEncoding = System.Text.Encoding.GetEncoding("SHIFT-JIS")
                Response.AddHeader("Content-Disposition", "attachment; filename=" & DirectCast(e.Item.FindControl("lnkb_file_name"), LinkButton).Text)
                Response.BinaryWrite(CType(dt.Rows(0)("file_binary"), Byte()))
                Response.Flush()
                Response.End()
        End Select
    End Sub
#End Region

#Region "******************* Sub及びFunction ********************"
    Private Sub Bind書類()
        Dim dt As DataTable
        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("@連番", SqlDbType.Int, _param.連番)
            spm.Fill()

            dt = spm.ds.Tables(0)
        End Using

        lb_EMAIL.Text = dt.Rows(0)("EMAIL").ToString()

        lb_団体名.Text = dt.Rows(0)("所属団体名").ToString()
        lb_氏名.Text = dt.Rows(0)("氏名").ToString()
        lb_ふりがな.Text = dt.Rows(0)("ふりがな").ToString()
        Dim str年齢 As String = dt.Rows(0)("年齢").ToString()
        If Not String.IsNullOrEmpty(str年齢) Then
            lb_年齢.Text = str年齢 & "歳"
        End If
        lb_性別.Text = dt.Rows(0)("性別").ToString()

        lb_郵便番号.Text = dt.Rows(0)("郵便番号").ToString() '初期表示はCD市区町村の値
        lb_住所.Text = dt.Rows(0)("住所").ToString() '初期表示はCD市区町村の値
        lb_電話番号.Text = dt.Rows(0)("電話番号").ToString() '初期表示はCD市区町村の値
        'lb_メールアドレス.Text = dt.Rows(0)("研修担当EMAIL").ToString()

        lb_職歴1.Text = dt.Rows(0)("職歴1").ToString()
        Dim str職歴1開始年 As String = dt.Rows(0)("職歴1開始年").ToString()
        If Not String.IsNullOrEmpty(str職歴1開始年) Then
            lb_職歴1開始年.Text = str職歴1開始年 & "年"
        End If
        Dim str職歴1開始月 As String = dt.Rows(0)("職歴1開始月").ToString()
        If Not String.IsNullOrEmpty(str職歴1開始月) Then
            lb_職歴1開始月.Text = str職歴1開始月 & "月　～"
        End If
        Dim str職歴1終了年 As String = dt.Rows(0)("職歴1終了年").ToString()
        If Not String.IsNullOrEmpty(str職歴1終了年) Then
            lb_職歴1終了年.Text = str職歴1終了年 & "年"
        End If
        Dim str職歴1終了月 As String = dt.Rows(0)("職歴1終了月").ToString()
        If Not String.IsNullOrEmpty(str職歴1終了月) Then
            lb_職歴1終了月.Text = str職歴1終了月 & "月"
        End If
        lb_所属部課.Text = dt.Rows(0)("所属部課").ToString()
        lb_職名.Text = dt.Rows(0)("職名").ToString()

        lb_現職開始年.Text = dt.Rows(0)("現職開始年").ToString()
        lb_現職開始月.Text = dt.Rows(0)("現職開始月").ToString()
        Dim str現職開始年 As String = dt.Rows(0)("現職開始年").ToString()
        If Not String.IsNullOrEmpty(str現職開始年) Then
            lb_現職開始年.Text = str現職開始年 & "年"
        End If
        Dim str現職開始月 As String = dt.Rows(0)("現職開始月").ToString()
        If Not String.IsNullOrEmpty(str現職開始月) Then
            lb_現職開始月.Text = str現職開始月 & "月　～　現在"
        End If

        lb_職層.Text = dt.Rows(0)("職層").ToString()
        Dim str実務経験年 As String = dt.Rows(0)("通算経験年数").ToString()
        If Not String.IsNullOrEmpty(str実務経験年) Then
            lb_実務経験年.Text = str実務経験年 & "年"
        End If
        Dim str実務経験月 As String = dt.Rows(0)("通算経験月数").ToString()
        If Not String.IsNullOrEmpty(str実務経験月) Then
            lb_実務経験月.Text = str実務経験月 & "カ月"
        End If
        lb_連絡事項.Text = dt.Rows(0)("連絡事項").ToString()

        lb_意向確認.Text = GetDdlText("研修申込_意向確認", dt.Rows(0)("意向確認").ToString())

        lb_代表幹事承諾.Text = GetDdlText("研修申込_承諾", dt.Rows(0)("代表幹事承諾").ToString())
        lb_副幹事承諾.Text = GetDdlText("研修申込_承諾", dt.Rows(0)("副幹事承諾").ToString())
        lb_座長承諾.Text = GetDdlText("研修申込_承諾", dt.Rows(0)("座長承諾").ToString())
        lb_教室委員承諾.Text = GetDdlText("研修申込_承諾", dt.Rows(0)("教室委員承諾").ToString())

        lb_THEME.Text = dt.Rows(0)("THEME").ToString()
        lb_現状.Text = dt.Rows(0)("現状").ToString()
        lb_問題点.Text = dt.Rows(0)("問題点").ToString()
        lb_対応案.Text = dt.Rows(0)("対応案").ToString()

        lb_受講動機.Text = dt.Rows(0)("受講動機").ToString()
        lb_研修目標.Text = dt.Rows(0)("研修目標").ToString()
        lb_振返.Text = dt.Rows(0)("振返").ToString()

    End Sub

    Private Function GetDdlText(key As String, cd As String) As String
        Using spm As New StoredProcedureManager("共通_変数_DDL")
            spm.AddPrmIn("@変数", SqlDbType.VarChar, key)
            spm.Fill()

            Dim filter As String = "CD = '" & cd.Replace("'", "''") & "'"
            Dim rows As DataRow() = spm.ds.Tables(0).Select(filter)

            If rows.Length > 0 Then
                Return rows(0)("内容").ToString
            Else
                Return ""
            End If
        End Using
    End Function

    Private Sub CreateList書類添付(ByRef lv As ListView, ByVal columnName As String)
        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("@連番", SqlDbType.Int, _param.連番)
            spm.AddPrmIn("@column_name", SqlDbType.NVarChar, columnName)
            spm.Fill()

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

        lv.DataBind()
    End Sub
#End Region

End Class
