Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class uc_SearchClass
    Inherits System.Web.UI.UserControl

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

    '検索
    Private Const SESSION_SEARCH_RISYUNEN As String = "COM_Search_Jyugyo_Nendo" '履修年度
    Private Const SESSION_SEARCH_KAMOKUCD As String = "COM_Search_Jyugyo_CD"    '科目CD
    Private Const SESSION_SEARCH_KAMOKUMEI As String = "COM_Search_Jyugyo_Name" '科目名
    Private Const SESSION_SEARCH_KYOINCD As String = "COM_Search_Kyoin_CD"      '教員CD
    Private Const SESSION_SEARCH_KYOINMEI As String = "COM_Search_Kyoin_Name"   '教員名
    Private Const SESSION_SEARCH_KIKAN As String = "COM_Search_Jyugyo_Kikan"    '期間
    Private Const SESSIN_SEARCH_YOUBI As String = "COM_Search_Jyugyo_Youbi"     '曜日
    Private Const SESSION_SEARCH_JIGEN As String = "COM_Search_Jyugyo_Jigen"    '時限

    '一覧
    Private Const SESSION_LIST_PAGE_INDEX As String = "SearchClass_PageIndex"           'ページの位置
    Private Const SESSION_LIST_SELECTED_INDEX As String = "SearchClass_SelectedIndex"   '選択行の位置

#End Region

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '---------------------------------------------------------------
        '検索条件をセット
        '---------------------------------------------------------------
        If Not IsPostBack Then
            dd_検索_授業年度.Text = Session(SESSION_SEARCH_RISYUNEN)
            txt_検索_授業CD.Text = Session(SESSION_SEARCH_KAMOKUCD)
            txt_検索_授業名.Text = Session(SESSION_SEARCH_KAMOKUMEI)
            txt_検索_教員CD.Text = Session(SESSION_SEARCH_KYOINCD)
            txt_検索_教員名.Text = Session(SESSION_SEARCH_KYOINMEI)
            dd_検索_期間.Text = Session(SESSION_SEARCH_KIKAN)
            dd_検索_曜日.Text = Session(SESSIN_SEARCH_YOUBI)
            dd_検索_時限.Text = Session(SESSION_SEARCH_JIGEN)
        End If

        If Not Session(SESSION_LIST_SELECTED_INDEX) Is Nothing Then
            gv_授業.SelectedIndex = Session(SESSION_LIST_SELECTED_INDEX)
        Else
            gv_授業.SelectedIndex = -1
        End If
    End Sub

#End Region

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

    Protected Sub gv_授業_DataBound(sender As Object, e As EventArgs) Handles gv_授業.DataBound
        'ページの位置を復元
        gv_授業.PageIndex = Session(SESSION_LIST_PAGE_INDEX)
    End Sub

    Protected Sub gv_授業_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gv_授業.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            'リストクリック時選択状態にする
            Dim instance As ClientScriptManager = Page.ClientScript
            Dim button As LinkButton = CType(e.Row.FindControl("lbtn_選択"), LinkButton)
            e.Row.Attributes("onclick") = instance.GetPostBackClientHyperlink(button, "")
        End If
    End Sub

    Protected Sub gv_授業_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gv_授業.SelectedIndexChanged
        '検索リストから選択された授業情報を保持
        Session(S_COM_Selected_Risyu_Nendo) = CType(gv_授業.SelectedRow.FindControl("lb_履修年度"), Label).Text
        Session(S_COM_Selected_Seiseki_Nendo) = CType(gv_授業.SelectedRow.FindControl("lb_成績年度"), Label).Text
        Session(S_COM_Selected_Bunya_CD) = CType(gv_授業.SelectedRow.FindControl("lb_分野CD"), Label).Text
        Session(S_COM_Selected_Kamoku_CD) = CType(gv_授業.SelectedRow.FindControl("lb_科目CD"), Label).Text
        Session(S_COM_Selected_Kouza_CD) = CType(gv_授業.SelectedRow.FindControl("lb_講座CD"), Label).Text

        '選択行の位置を保持
        Session(SESSION_LIST_SELECTED_INDEX) = gv_授業.SelectedIndex

        Session.Remove(S_Attend_Selected_Syussekibo_PageIndex)

        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub gv_授業_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles gv_授業.PageIndexChanging
        '選択行を解除
        gv_授業.SelectedIndex = -1
        'ページを移動
        gv_授業.PageIndex = e.NewPageIndex

        'ページの位置を保持
        Session(SESSION_LIST_PAGE_INDEX) = gv_授業.PageIndex.ToString
    End Sub

    Protected Sub btn_検索_Click(sender As Object, e As EventArgs) Handles btn_検索.Click
        'ページと選択行の位置を初期化
        gv_授業.PageIndex = 0
        Session.Remove(SESSION_LIST_PAGE_INDEX)
        Session.Remove(SESSION_LIST_SELECTED_INDEX)

        '検索条件をクリア
        Session(SESSION_SEARCH_RISYUNEN) = dd_検索_授業年度.Items(0).Value
        Session(SESSION_SEARCH_KAMOKUCD) = ""
        Session(SESSION_SEARCH_KAMOKUMEI) = ""
        Session(SESSION_SEARCH_KYOINCD) = ""
        Session(SESSION_SEARCH_KYOINMEI) = ""
        Session(SESSION_SEARCH_KIKAN) = ""
        Session(SESSIN_SEARCH_YOUBI) = ""
        Session(SESSION_SEARCH_JIGEN) = ""

        '検索条件をセッションに保存
        Session(SESSION_SEARCH_RISYUNEN) = dd_検索_授業年度.Text
        Session(SESSION_SEARCH_KAMOKUCD) = txt_検索_授業CD.Text
        Session(SESSION_SEARCH_KAMOKUMEI) = txt_検索_授業名.Text
        Session(SESSION_SEARCH_KYOINCD) = txt_検索_教員CD.Text
        Session(SESSION_SEARCH_KYOINMEI) = txt_検索_教員名.Text
        Session(SESSION_SEARCH_KIKAN) = dd_検索_期間.Text
        Session(SESSIN_SEARCH_YOUBI) = dd_検索_曜日.Text
        Session(SESSION_SEARCH_JIGEN) = dd_検索_時限.Text

        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub btn_検索クリア_Click(sender As Object, e As EventArgs) Handles btn_検索クリア.Click
        '検索条件をクリア
        Session(SESSION_SEARCH_RISYUNEN) = dd_検索_授業年度.Items(0).Value
        Session(SESSION_SEARCH_KAMOKUCD) = ""
        Session(SESSION_SEARCH_KAMOKUMEI) = ""
        Session(SESSION_SEARCH_KYOINCD) = ""
        Session(SESSION_SEARCH_KYOINMEI) = ""
        Session(SESSION_SEARCH_KIKAN) = ""
        Session(SESSIN_SEARCH_YOUBI) = ""
        Session(SESSION_SEARCH_JIGEN) = ""

        Response.Redirect(Request.RawUrl.ToString)
    End Sub

    Protected Sub sql_dd_授業年度_Init(sender As Object, e As EventArgs) Handles sql_dd_授業年度.Init
        sql_dd_授業年度_select()
    End Sub

    Protected Sub sql_dd_期間_Init(sender As Object, e As EventArgs) Handles sql_dd_期間.Init
        sql_dd_授業期間_select()
    End Sub
    Protected Sub sql_授業_Init(sender As Object, e As EventArgs) Handles sql_授業.Init
        sql_授業_SET()
    End Sub
    Protected Sub sql_dd_曜日_Init(sender As Object, e As EventArgs) Handles sql_dd_曜日.Init
        sql_dd_曜日_select()
    End Sub
    Protected Sub sql_dd_時限_Init(sender As Object, e As EventArgs) Handles sql_dd_時限.Init
        sql_dd_時限_select()
    End Sub

#End Region

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

    Private Sub sql_授業_SET()
        '既定の授業年度をセッションにセット
        If Session(SESSION_SEARCH_RISYUNEN) Is Nothing Then
            Session(SESSION_SEARCH_RISYUNEN) = Com_Get_既定授業年度()
        End If

        Dim sds As SqlDataSource = sql_授業
        WebControlsUtil.DeclareSP(sds, "共通_授業評価検索_SELECT")
        With sds
            .SelectParameters.Add("履修年度", DbType.Int16, Session(SESSION_SEARCH_RISYUNEN))
            .SelectParameters.Add("科目CD", DbType.String, Session(SESSION_SEARCH_KAMOKUCD))
            .SelectParameters.Add("授業名", DbType.String, Session(SESSION_SEARCH_KAMOKUMEI))
            .SelectParameters.Add("教員CD", DbType.String, Session(SESSION_SEARCH_KYOINCD))
            .SelectParameters.Add("教員名", DbType.String, Session(SESSION_SEARCH_KYOINMEI))
            .SelectParameters.Add("期間", DbType.String, Session(SESSION_SEARCH_KIKAN))
            .SelectParameters.Add("曜日", DbType.String, Session(SESSIN_SEARCH_YOUBI))
            .SelectParameters.Add("時限", DbType.Int32, Session(SESSION_SEARCH_JIGEN))
            .SelectParameters.Add("検索種別", DbType.String, Session(S_MSP_Selected_Title))
            .SelectParameters.Add("PORTALID", DbType.String, Session(S_COM_PortalID))
        End With
    End Sub

    Private Sub sql_dd_授業年度_select()
        Dim sds As SqlDataSource = sql_dd_授業年度
        WebControlsUtil.DeclareSP(sds, "共通_教務_授業年度_DDL")
    End Sub

    Private Sub sql_dd_授業期間_select()
        Dim sds As SqlDataSource = sql_dd_期間
        WebControlsUtil.DeclareSP(sds, "共通_教務_授業期間_DDL")
    End Sub

    Private Sub sql_dd_曜日_select()
        Dim sds As SqlDataSource = sql_dd_曜日
        WebControlsUtil.DeclareSP(sds, "共通_曜日_DDL")
    End Sub

    Private Sub sql_dd_時限_select()
        Dim sds As SqlDataSource = sql_dd_時限
        WebControlsUtil.DeclareSP(sds, "共通_教務_時限_DDL")
    End Sub

#End Region

End Class
