StrataFrame Forum

Detect new record in a form

http://forum.strataframe.net/Topic28470.aspx

By Tiong Diu King - 9/23/2010

Hi Ivan,

In the SF Maintenance form, How do we know the current form's record is new and then return me boolean ?



Please advice
By Ivan George Borges - 9/23/2010

Hi Tiong.

Have a look at the BO's EditingState property.

EditingState Property

All StrataFrame business objects have an EditingState property.  This property indicates the current state of the business object, and there are three valid states:
  • Idle - When a business object is not in Add or Edit mode, it is in an idle state.  When bound to controls and the editing state are managed by StrataFrame, the fields bound to a business object in this state will be disabled.

  • Adding - The current row within the business object is new.  Additionally, all fields bound to the business object, when managed by StrataFrame, will be enabled.

  • Editing - The current row within the business object is an existing record that is being modified.  All fields bound to the business object, when managed by StrataFrame, will be enabled.

By Tiong Diu King - 9/23/2010

Hi Ivan,

You had help me again with your solution.


Thanks
By Tiong Diu King - 9/23/2010

Hi Ivan,

Your solution still can't work when i test it. I did it with my own solution and please advice


 Private Sub ComboBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Validated
        If isnew = True Then
            Textbox1.Text = modEmployee.careerhis_sequence_increment(BO_hretCareerHis1.iChsEmployee_FK)
        End If

        'If MicroFour.StrataFrame.Business.BusinessEditingState.Adding Then
        '    Textbox1.Text = modEmployee.careerhis_sequence_increment(BO_hretCareerHis1.iChsEmployee_FK)
        'End If
    End Sub


    Public Property isnew() As Boolean
        Get
            Return x
        End Get
        Set(ByVal Value As Boolean)
            x = Value
        End Set
    End Property


    Private Sub MaintenanceFormToolStrip1_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MaintenanceFormToolStrip1.ItemClicked
        If e.ClickedItem.Text = "New" Then
            isnew = True
        Else
            isnew = False
        End If
    End Sub



Thanks
By Ivan George Borges - 9/23/2010

You should test you BO's editing state. As in:

    If YourBO.EditingState = MicroFour.StrataFrame.Business.BusinessEditingState.Adding Then
        Textbox1.Text = modEmployee.careerhis_sequence_increment(BO_hretCareerHis1.iChsEmployee_FK)
    End If


Or you can use the BO's EditingStateChanged event and set your isnew property:

    Private Sub YourBO_EditingStateChanged(ByVal e As MicroFour.StrataFrame.Business.EditingStateChangedEventArgs) _
        Handles YourBO.EditingStateChanged

        If e.EditingState = MicroFour.StrataFrame.Business.BusinessEditingState.Adding Then
            isnew = True
        Else
            isnew = False
        End If

    End Sub
By Tiong Diu King - 9/23/2010

Hi Ivan,

I did it with your solution.

Thanks
By Ivan George Borges - 9/23/2010

You are welcome, Tiong. Cool