Public Class Contracts
    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 Subcontracts") Then Throw New HttpException(403, "Forbidden")
            
            dsContracts.ConnectionString = Logic.Database.connectionString
            dsContracts.SelectParameters("contractId").DefaultValue = contractId

        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("EditContract.aspx?cid=" & contractId)
    End Sub

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

End Class