Public Class Accidents
    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 Accidents Page") Then Throw New HttpException(403, "Forbidden")

            dsAccidents.ConnectionString = Logic.Database.connectionString
            dsAccidents.SelectParameters("contractId").DefaultValue = contractId

            If Not Page.IsPostBack Then
                Master.SetParentPage("Accidents.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("EditAccident.aspx?cid=" & contractId)
    End Sub

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

End Class