Public Class RoadsideInspections
    Inherits System.Web.UI.Page

    Property contractId As Integer

    Protected Sub Page_Load() Handles Me.Load
        Try
            contractId = Logic.Conversion.ToInteger(Request.Params("cid"))
            Master.CurrentClient.VerifyContractAccess(contractId)

            Dim perms = Master.CurrentClient.Permissions
            If Not perms.Contains("View Roadside Inspections Page") Then Throw New HttpException(403, "Forbidden")

            dsInspections.ConnectionString = Logic.Database.ConnectionString
            dsInspections.SelectParameters("contractId").DefaultValue = contractId

            If Not Page.IsPostBack Then
                Master.SetParentPage("RoadsideInspections.aspx?cid=" & contractId)
            End If

        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId)
        End Try
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Response.Redirect("EditRoadsideInspection.aspx?cid=" & contractId)
    End Sub

    Private Sub gvInspections_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvInspections.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim data As DataRowView = e.Row.DataItem
            Dim url = String.Format("EditRoadsideInspection.aspx?id={0}&cid={1}", data("id"), data("ContractID"))
            e.Row.Attributes.Add("data-href", url)
        End If
    End Sub

End Class