<commit_before>Option Strict On

Imports ProjectTracker.Library

Partial Class ProjectEdit
  Inherits System.Web.UI.Page

  Private Enum Views
    MainView = 0
    AssignView = 1
  End Enum

  Protected Sub Page_Load( _
    ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
      ApplyAuthorizationRules()

    Else
      Me.ErrorLabel.Text = ""
    End If

  End Sub

  Private Sub ApplyAuthorizationRules()

    ' project display
    If Project.CanEditObject Then
      Dim obj As Project = GetProject()
      If obj.IsNew Then
        Me.DetailsView1.DefaultMode = DetailsViewMode.Insert

      Else
        Me.DetailsView1.DefaultMode = DetailsViewMode.Edit
      End If
      Me.AddResourceButton.Visible = Not obj.IsNew

    Else
      Me.DetailsView1.DefaultMode = DetailsViewMode.ReadOnly
      Me.AddResourceButton.Visible = False
    End If
    Me.DetailsView1.Rows(Me.DetailsView1.Rows.Count - 1).Visible = _
      Project.CanEditObject

    ' resources display
    Me.GridView1.Columns(Me.GridView1.Columns.Count - 1).Visible = _
      Project.CanEditObject

  End Sub

#Region " Project DetailsView "

  Protected Sub DetailsView1_ItemCreated( _
    ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.ItemCreated

    Dim obj As Project = GetProject()

    CType(DetailsView1.Rows(0).Cells(1).Controls(0), TextBox).Text = obj.Id.ToString
    CType(DetailsView1.Rows(1).Cells(1).Controls(0), TextBox).Text = obj.Name
    CType(DetailsView1.Rows(2).Cells(1).Controls(0), TextBox).Text = obj.Started
    CType(DetailsView1.Rows(3).Cells(1).Controls(0), TextBox).Text = obj.Ended
    CType(DetailsView1.FindControl("TextBox1"), System.Web.UI.WebControls.TextBox).Text = obj.Description

  End Sub

  Protected Sub DetailsView1_ItemInserted( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) _
    Handles DetailsView1.ItemInserted

    Dim project As Project = GetProject()
    If Not project.IsNew Then
      Response.Redirect("ProjectEdit.aspx?id=" & project.Id.ToString)

    Else
      e.KeepInInsertMode = True
    End If

  End Sub

  Protected Sub DetailsView1_ItemUpdated( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) _
    Handles DetailsView1.ItemUpdated

    ApplyAuthorizationRules()
<commit_msg>Fix code that loads default values for a new project to only load the values on insert.<commit_after>Option Strict On

Imports ProjectTracker.Library

Partial Class ProjectEdit
  Inherits System.Web.UI.Page

  Private Enum Views
    MainView = 0
    AssignView = 1
  End Enum

  Protected Sub Page_Load( _
    ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
      ApplyAuthorizationRules()

    Else
      Me.ErrorLabel.Text = ""
    End If

  End Sub

  Private Sub ApplyAuthorizationRules()

    ' project display
    If Project.CanEditObject Then
      Dim obj As Project = GetProject()
      If obj.IsNew Then
        Me.DetailsView1.DefaultMode = DetailsViewMode.Insert

      Else
        Me.DetailsView1.DefaultMode = DetailsViewMode.Edit
      End If
      Me.AddResourceButton.Visible = Not obj.IsNew

    Else
      Me.DetailsView1.DefaultMode = DetailsViewMode.ReadOnly
      Me.AddResourceButton.Visible = False
    End If
    Me.DetailsView1.Rows(Me.DetailsView1.Rows.Count - 1).Visible = _
      Project.CanEditObject

    ' resources display
    Me.GridView1.Columns(Me.GridView1.Columns.Count - 1).Visible = _
      Project.CanEditObject

  End Sub

#Region " Project DetailsView "

  Protected Sub DetailsView1_ItemCreated( _
    ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.ItemCreated

    If DetailsView1.DefaultMode = DetailsViewMode.Insert Then
      Dim obj As Project = GetProject()

      CType(DetailsView1.Rows(1).Cells(1).Controls(0), TextBox).Text = obj.Name
      CType(DetailsView1.Rows(2).Cells(1).Controls(0), TextBox).Text = obj.Started
      CType(DetailsView1.Rows(3).Cells(1).Controls(0), TextBox).Text = obj.Ended
      CType(DetailsView1.FindControl("TextBox1"), System.Web.UI.WebControls.TextBox).Text = obj.Description
    End If

  End Sub

  Protected Sub DetailsView1_ItemInserted( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) _
    Handles DetailsView1.ItemInserted

    Dim project As Project = GetProject()
    If Not project.IsNew Then
      Response.Redirect("ProjectEdit.aspx?id=" & project.Id.ToString)

    Else
      e.KeepInInsertMode = True
    End If

  End Sub

  Protected Sub DetailsView1_ItemUpdated( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) _
    Handles DetailsView1.ItemUpdated

    ApplyAuthorizationRules()

{'fraction_non_alphanumeric': 0.07685984381422113, 'fraction_numerical': 0.013769009453349773, 'mean_word_length': 3.2432432432432434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2133425', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1435, 'n_words': 357}