Search dialog to handle cancel or clear value  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Search dialog to handle cancel or clear value

Postby perry » Tue Oct 18, 2022 1:30 pm

Hi All,

Just wondering if anyone has idea on how to best handle the Search Dialog when a custom field requires Select, Cancel or Clear (current value) actions.

I currently have, if cancelled, a message box to ask user if he wants to cancel or remove existing value.
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Search dialog to handle cancel or clear value

Postby SBarnes » Tue Oct 18, 2022 3:34 pm

Although I have not done this, you may find the following worth a look on how to add a context menu to the grid https://www.grapecity.com/spreadnet/doc ... tmenu.html
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Search dialog to handle cancel or clear value

Postby Scott.Pearce » Tue Oct 18, 2022 4:47 pm

Have a look at the Service Manager form, Main tab, "Prepaid Labour Pack" lookup. Right-click on it and you will see you get a "Clear" menu item in a context menu - this is how we tend to handle such a requirement. Here is the code:

In the form Setup():

Code: Select all
Dim NewToolStripMenuItem As ToolStripMenuItem
Dim myPrepaidLabourPackContextMenuStrip As ContextMenuStrip = New ContextMenuStrip
NewToolStripMenuItem = New ToolStripMenuItem("Clear", Nothing, AddressOf ClearPrepaidLabourPack, "Clear")
myPrepaidLabourPackContextMenuStrip.Items.Add(NewToolStripMenuItem)
PrepaidLabourPackLookup.ContextMenuStrip = myPrepaidLabourPackContextMenuStrip


The handler:

Code: Select all
Private Sub ClearPrepaidLabourPack(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If _Job.SelectedTaskNo >= 1 AndAlso _Job.SelectedTaskNo <= _Job.Tasks.Count Then
        Job.Tasks(Job.SelectedTaskNo).PrepaidLabourPack.Clear()
    End If
End Sub


Hope this helps. Let me know if you need more detail.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Search dialog to handle cancel or clear value  Topic is solved

Postby Scott.Pearce » Tue Oct 18, 2022 5:01 pm

Sorry, I just realised that you are referring to a grid lookup.

Have a look at the bank rec form (Jiwa->Cash Book->Bank Reconciliation). New demo data, create a new bank rec for Cash At Bank NSW, as of whatever the current date is. Right click in the Status column and see that you get a context menu. Code:

Properties:

Code: Select all
    Public WithEvents TransactionsContextMenuStrip As System.Windows.Forms.ContextMenuStrip
    Public WithEvents UnreconcileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Public WithEvents ReconcileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
    Public WithEvents ClearToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem


Setup:

Code: Select all
    Private Sub SetupObjects()
        TransactionsContextMenuStrip = New System.Windows.Forms.ContextMenuStrip()
        UnreconcileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        ReconcileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
        ClearToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()

        AddHandler TransactionsContextMenuStrip.Opening, AddressOf TransactionsContextMenuStrip_Opening
    End Sub


Grid Setup:

Code: Select all
    Private Sub SetupTransactionsGrid()
        TransactionsContextMenuStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.UnreconcileToolStripMenuItem, Me.ReconcileToolStripMenuItem, Me.ClearToolStripMenuItem})
        TransactionsContextMenuStrip.Name = "TransactionsContextMenuStrip"
        TransactionsContextMenuStrip.Size = New System.Drawing.Size(186, 92)

        UnreconcileToolStripMenuItem.Name = "UnreconcileToolStripMenuItem"
        UnreconcileToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
        UnreconcileToolStripMenuItem.Text = "Unreconcile"

        ReconcileToolStripMenuItem.Name = "ReconcileToolStripMenuItem"
        ReconcileToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
        ReconcileToolStripMenuItem.Text = "Reconcile"

        ClearToolStripMenuItem.Name = "ClearToolStripMenuItem"
        ClearToolStripMenuItem.Size = New System.Drawing.Size(185, 22)
        ClearToolStripMenuItem.Text = "Clear"
  End Sub


Control event handler:

Code: Select all
    Private Sub grdTransactions_CellClick(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs)
      If e.Button = Windows.Forms.MouseButtons.Right Then
            If e.ColumnHeader = False AndAlso e.Column = grdTransactions.ActiveSheet.Columns("Status").Index Then
                TransactionsContextMenuStrip.Show(Cursor.Position)
            End If
        End If
    End Sub


Transaction grid context menu handlers:

Code: Select all
#Region "Transactions grid context menu handlers"
    Private Sub TransactionsContextMenuStrip_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs)

        If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated And EditPermission = JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
            ClearToolStripMenuItem.Enabled = True
            UnreconcileToolStripMenuItem.Enabled = True
            ReconcileToolStripMenuItem.Enabled = True
            Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
            If Not selectedCells Is Nothing Then
                For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
                    For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
                        Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                        If Not TransactionType Is Nothing Then
                            If TransactionType.Trim = "Opening Balance Transaction" Then
                                ClearToolStripMenuItem.Enabled = False
                            ElseIf TransactionType.Trim = "Direct GL Transaction" Or TransactionType.Trim = "Direct Debtor Receipt" Or TransactionType.Trim = "Direct Debtor Payment" Or TransactionType.Trim = "Direct Creditor Receipt" Or TransactionType.Trim = "Direct Creditor Payment" Then
                                ClearToolStripMenuItem.Enabled = False
                                UnreconcileToolStripMenuItem.Enabled = False
                            End If
                        End If
                    Next
                Next
            Else
                e.Cancel = True
            End If
        Else
            e.Cancel = True
        End If
    End Sub

    Private Sub UnreconcileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim oldCursor As Cursor = Cursor

        Try
            Cursor = Cursors.WaitCursor
            If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
                Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
                If Not selectedCells Is Nothing Then
                    For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
                        If selectedCells(currentSelectionBlock).Row = -1 Then
                            'All rows
                            For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Unreconciled
                                    ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
                                        BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Unreconciled
                                    End If
                                End If
                            Next
                        Else
                            For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Unreconciled
                                    ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
                                        BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Unreconciled
                                    End If
                                End If
                            Next
                        End If
                    Next
                End If
            End If
        Finally
            Cursor = oldCursor
        End Try
    End Sub

    Private Sub ReconcileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim oldCursor As Cursor = Cursor

        Try
            Cursor = Cursors.WaitCursor
            If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
                Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
                If Not selectedCells Is Nothing Then
                    For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
                        If selectedCells(currentSelectionBlock).Row = -1 Then
                            'All rows
                            For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Reconciled
                                    ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
                                        BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Reconciled
                                    End If
                                End If
                            Next
                        Else
                            For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Reconciled
                                    ElseIf TransactionType.Trim = "Opening Balance Transaction" Then
                                        BankRec.OpeningBalTransactions(TransactionKey).Status = JiwaBankRec.OpeningBalTransaction.OpeningBalTransactionStatuses.Reconciled
                                    End If
                                End If
                            Next
                        End If
                    Next
                End If
            End If
        Finally
            Cursor = oldCursor
        End Try
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim oldCursor As Cursor = Cursor

        Try
            Cursor = Cursors.WaitCursor
            If BankRec.Status = JiwaBankRec.BankRec.BankRecStatuses.Unactivated Then
                Dim selectedCells() As FarPoint.Win.Spread.Model.CellRange = grdTransactions.ActiveSheet.GetSelections
                If Not selectedCells Is Nothing Then
                    For currentSelectionBlock As Integer = 0 To selectedCells.GetUpperBound(0)
                        If selectedCells(currentSelectionBlock).Row = -1 Then
                            'All rows
                            For myLoop As Integer = 0 To grdTransactions.ActiveSheet.RowCount - 1
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Cleared
                                    End If
                                End If
                            Next
                        Else
                            For myLoop As Integer = selectedCells(currentSelectionBlock).Row To selectedCells(currentSelectionBlock).Row + (selectedCells(currentSelectionBlock).RowCount - 1)
                                Dim TransactionType As String = grdTransactions.GridText("Type", myLoop)
                                Dim TransactionKey As String = grdTransactions.GridText("Key", myLoop)
                                If Not TransactionType Is Nothing Then
                                    If TransactionType.Trim = "GL Transaction" Then
                                        BankRec.GLTransactions(TransactionKey).Status = JiwaBankRec.GLTransaction.GLTransactionStatuses.Cleared
                                    End If
                                End If
                            Next
                        End If

                    Next
                End If
            End If
        Finally
            Cursor = oldCursor
        End Try
    End Sub
#End Region




As you can see from this post and my previous one, there are a few different ways that context menus can be done. Further, Infragistics (a control suite which we use and is shipped with Jiwa) offer a control agnostic context menu which can also be used, and it has many more features like icons, etc.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Search dialog to handle cancel or clear value

Postby perry » Thu Oct 20, 2022 4:53 pm

thank you both
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Search dialog to handle cancel or clear value

Postby Mike.Sheen » Wed Nov 02, 2022 5:25 pm

Coincidentally, I just had to do this for a customisation - so here's a plugin which demonstrates adding a context menu to custom field to clear the custom field contents for a lookup. It's for a line custom field, but the logic is interchangeable with plain custom fields.

The plugin adds a warehouse lookup custom field to the logical warehouses grid of the warehouse maintenance form - when the user clicks the lookup, a warehouse search is shown, and the user can select a warehouse. If the user wants to reset the value, right clicking on the custom field cell will show a context menu with a single option - "Clear" which does exactly what it implies - it clears the custom field contents to blank.

ClearContextMenu-WarehouseMaintenance.png
Attachments
Plugin Clearable Custom Field.xml
(22.9 KiB) Downloaded 50 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Search dialog to handle cancel or clear value

Postby SBarnes » Wed Nov 02, 2022 5:30 pm

Given this is a common theme on the Jiwa Grid and the Jiwa lookup control could there be a way to bake this in as a property(clearable) and an event if the popup was called?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Search dialog to handle cancel or clear value

Postby Mike.Sheen » Wed Nov 02, 2022 5:37 pm

SBarnes wrote:Given this is a common theme on the Jiwa Grid and the Jiwa lookup control could there be a way to bake this in as a property(clearable) and an event if the popup was called?


Good idea - but we'd need to recognise that people will sometimes want to have other context menu items, or be able to intercept the clear action of whatever we bake in - so we'd need to make sure it's customisable and overridable easily.

Logged as DEV-9640.

Shall I assign it to you, Stuart? :P
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Search dialog to handle cancel or clear value

Postby SBarnes » Wed Nov 02, 2022 5:39 pm

Sure I'll get to it after the current project is finalised and I've run out of things to do :lol: :lol:
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 33 guests