Imports System.Data
Imports AppCommon
Imports AppVariable

Partial Class uc_SearchSchool
    Inherits System.Web.UI.UserControl

    ''' <summary>
    ''' ページIndex保持
    ''' </summary>
    Private _pageIndex As Integer = 0

#Region "イベントメソッド"

    ''' <summary>
    ''' ページロードイベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            SetDropDown学校訪問(ddl分類CD)
        End If
    End Sub

    ''' <summary>
    ''' 検索ボタンクリックイベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub btn_検索_Click(sender As Object, e As EventArgs) Handles btn_検索.Click
        _pageIndex = 0
        searchSchool()
    End Sub

    ''' <summary>
    ''' 学校データソース初期化イベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub sds学校_Init(sender As Object, e As EventArgs) Handles sds学校.Init
        searchSchool()
    End Sub

    ''' <summary>
    ''' 学校グリッドページ変更イベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub gv学校_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles gv学校.PageIndexChanging
        gv学校.SelectedIndex = -1
        gv学校.PageIndex = e.NewPageIndex
        _pageIndex = e.NewPageIndex
    End Sub

    ''' <summary>
    ''' 学校グリッド行データバインドイベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    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)

            Dim rowItem As DataRowView = e.Row.DataItem

            e.Row.Attributes("onclick") = String.Format("selectSchool('{0}', '{1}', '{2}')", rowItem("分類CD"), rowItem("学校CD"), rowItem("名前"))
        End If
    End Sub

    ''' <summary>
    ''' 学校グリッドデータバインド後イベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub gv学校_DataBound(sender As Object, e As EventArgs) Handles gv学校.DataBound
        gv学校.PageIndex = _pageIndex
    End Sub


#End Region

#Region "ユーザメソッド"
    ''' <summary>
    ''' 学校検索
    ''' </summary>
    Private Sub searchSchool()
        WebControlsUtil.DeclareSP(sds学校, "学校_学校一覧_SELECT")
        With sds学校
            .SelectParameters.Add("分類CD", ddl分類CD.SelectedValue)
            .SelectParameters.Add("名前", txt学校名.Text)
            .SelectParameters.Add("ふり", txtふりがな.Text)
        End With
    End Sub
#End Region
End Class
