Ok, there's just a few things to address and you should have it working.
Firstly, Add a handler for cmdReset.Click in the SetupBeforeHandlers OR Setup but not both.
In your case you want to add the handler in SetupBeforeHandlers, and do absolutely nothing in the Setup method. Then in your handler, show your dialog and then throw a ClientCancelledException
So your FormPlugin class should look like this:
- Code: Select all
Public Class FormPlugin
Inherits System.MarshalByRefObject
Implements JiwaApplication.IJiwaFormPlugin
Public Overrides Function InitializeLifetimeService() As Object
' returning null here will prevent the lease manager
' from deleting the Object.
Return Nothing
End Function
Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
If TypeOf JiwaForm Is JiwaStaffUI.frmMain
Dim StaffForm As JiwaStaffUI.frmMain = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)
AddHandler StaffForm.cmdReset.Click , AddressOf cmdResetClick
End If
End Sub
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
End Sub
Private Sub cmdResetClick ( sender As Object , e As System.EventArgs )
Dim myForm As frmResetPassword
myForm = New frmResetPassword
'myForm.Staff = Staff
'myForm.OldPassword = Staff.Password
Try
MessageBox.Show ("before myfor.setup ")
If myForm.SetupForm = True Then
MessageBox.Show ("before calling my reset password form ")
myForm.ShowDialog(Nothing)
If myForm.Cancelled = False Then
'Staff.Password = myForm.NewPassword
End If
End If
Catch ex As Exception
MessageBox.Show ("error loading myform " & ex.Message )
End Try
Throw New JiwaApplication.Exceptions.ClientCancelledException()
End Sub
End Class
Secondly, note that I modified the call to myForm.ShowDialog above to pass nothing instead of Me - ShowDialog wants a Windows Form to be passed as the owner or nothing - you were passing me, which was a class of that did not implement the interfaces it wanted "system.Windows.Forms.IwinWindow'" as per your error message.
Ideally you should pass the Staff Maintenance form, so it knows that the password reset dialog is modal to the staff maintenance form. Do this by storing the JiwaForm passed to SetupBeforeHandlers into a class variable, and passing that.
ie:
- Code: Select all
Public Class FormPlugin
Inherits System.MarshalByRefObject
Implements JiwaApplication.IJiwaFormPlugin
Private staffMaintenanceForm as JiwaStaffUI.frmMain
Public Overrides Function InitializeLifetimeService() As Object
' returning null here will prevent the lease manager
' from deleting the Object.
Return Nothing
End Function
Public Sub SetupBeforeHandlers(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.SetupBeforeHandlers
If TypeOf JiwaForm Is JiwaStaffUI.frmMain
staffMaintenanceForm = DirectCast(JiwaForm, JiwaApplication.IJiwaForm)
AddHandler staffMaintenanceForm.cmdReset.Click , AddressOf cmdResetClick
End If
End Sub
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
End Sub
Private Sub cmdResetClick ( sender As Object , e As System.EventArgs )
Dim myForm As frmResetPassword
myForm = New frmResetPassword
'myForm.Staff = Staff
'myForm.OldPassword = Staff.Password
Try
MessageBox.Show ("before myfor.setup ")
If myForm.SetupForm = True Then
MessageBox.Show ("before calling my reset password form ")
myForm.ShowDialog(staffMaintenanceForm)
If myForm.Cancelled = False Then
'Staff.Password = myForm.NewPassword
End If
End If
Catch ex As Exception
MessageBox.Show ("error loading myform " & ex.Message )
End Try
Throw New JiwaApplication.Exceptions.ClientCancelledException()
End Sub
End Class