Håller på att översätta lite C# (från http://www.cerquit.com/blogs/post/MVP-Part-I-e28093-Building-it-from-Scratch.aspx)Close + Implements i en form
Ett interface kräver sub close(). I C# exemplet så är det inte med och det fungerar. I Vb verkar det som om det måste kodas. Men hur gör man för att komma åt subbeb close i en form och lägga till
<code>
... close ..... Implements IEmployeeView.Close
</code>
/Magnus
Hela IEmployeeView
<code>
Imports System.Collections
Imports System.Collections.Generic
Imports System.Text
Imports MVPsession.Common
Namespace MVP
Public Interface IEmployeeView
ReadOnly Property EmployeeID() As Integer
ReadOnly Property Firstname() As String
ReadOnly Property Lastname() As String
ReadOnly Property EmployeeType() As EnumEmployeeType
WriteOnly Property TAXAmount() As Double
ReadOnly Property Salary() As Double
Property TAX() As Single
ReadOnly Property IsDirty() As Boolean
WriteOnly Property SalaryRanges() As IList(Of String)
WriteOnly Property EmployeeTypes() As IList(Of String)
Function ConfirmClose() As Boolean
Sub Close()
Function ConfirmDelete() As Boolean
Sub ShowValidationErrors(ByVal errorMessages As ErrorMessageCollection)
End Interface
End Namespace
</code>
Hela FormEmployee
<code>
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports MVPsession.Common
Imports MVPsession.MVP
Namespace WinUI
Partial Public Class FormEmployee
Inherits Form
Implements IEmployeeView
Private _presenter As EmployeePresenter
Private _isDirty As Boolean
Private _id As Integer = 0
Private _suppressEvents As Boolean = False
Public Sub New()
'InitializeComponent()
End Sub
Private Sub FormEmployee_Load(ByVal sender As Object, ByVal e As EventArgs)
_presenter = New EmployeePresenter(Me, New EmployeeModel(), New EmployeeService())
'-- NOTE: using employee web service
Try
_suppressEvents = True
'-- initialize presenter
_presenter.Initialize()
_isDirty = False
Finally
_suppressEvents = False
End Try
End Sub
#Region "IEmployeeView Members"
Public ReadOnly Property EmployeeID() As Integer Implements IEmployeeView.EmployeeID
Get
Return _id
End Get
End Property
Public ReadOnly Property Firstname() As String Implements IEmployeeView.Firstname
Get
Return textBoxFirstname.Text
End Get
End Property
Public ReadOnly Property Lastname() As String Implements IEmployeeView.Lastname
Get
Return textBoxLastname.Text
End Get
End Property
Public ReadOnly Property EmployeeType() As EnumEmployeeType Implements IEmployeeView.EmployeeType
Get
Return Enums.GetEmployeeTypeByName(comboBoxEmployeeType.SelectedItem.ToString())
End Get
End Property
Public WriteOnly Property TAXAmount() As Double Implements IEmployeeView.TAXAmount
Set(ByVal value As Double)
textBoxTaxAmount.Text = value.ToString("0.00")
End Set
End Property
Public ReadOnly Property Salary() As Double Implements IEmployeeView.Salary
Get
Return Convert.ToDouble(comboBoxSalary.SelectedItem.ToString())
End Get
End Property
Public Property TAX() As Single Implements IEmployeeView.TAX
Get
Return Convert.ToSingle(textBoxTAX.Text)
End Get
Set(ByVal value As Single)
textBoxTAX.Text = value.ToString("0.00")
End Set
End Property
Public ReadOnly Property IsDirty() As Boolean Implements IEmployeeView.IsDirty
Get
Return _isDirty
End Get
End Property
Public WriteOnly Property SalaryRanges() As IList(Of String) Implements IEmployeeView.SalaryRanges
Set(ByVal value As IList(Of String))
comboBoxSalary.DataSource = value
End Set
End Property
Public WriteOnly Property EmployeeTypes() As IList(Of String) Implements IEmployeeView.EmployeeTypes
Set(ByVal value As IList(Of String))
comboBoxEmployeeType.DataSource = value
End Set
End Property
Public Function ConfirmClose() As Boolean Implements IEmployeeView.ConfirmClose
Return MessageBox.Show("Are you sure you want to proceed?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) = DialogResult.Yes
End Function
Public Function ConfirmDelete() As Boolean Implements IEmployeeView.ConfirmDelete
Return MessageBox.Show("Are you sure you want to delete?", "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes
End Function
Public Sub ShowValidationErrors(ByVal errorMessages As ErrorMessageCollection) Implements IEmployeeView.ShowValidationErrors
MessageBox.Show(errorMessages.ToString())
End Sub
#End Region
Private Sub FormEmployee_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
e.Cancel = Not _presenter.CloseForm(True)
End Sub
Private Sub buttonCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.Close()
End Sub
Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As EventArgs)
If _presenter.Save() Then
_isDirty = False
MessageBox.Show("Successfully saved.")
Close()
End If
End Sub
Private Sub Input_Changed(ByVal sender As Object, ByVal e As EventArgs)
If _suppressEvents Then
Return
End If
_isDirty = True
End Sub
Private Sub comboBoxEmployeeType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If _suppressEvents Then
Return
End If
_isDirty = True
_presenter.OnEmployeeTypeChanged()
End Sub
Private Sub comboBoxSalary_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If _suppressEvents Then
Return
End If
_isDirty = True
_presenter.OnEmployeeSalaryChanged()
End Sub
Private Sub InitializeComponent()
Me.textBoxTaxAmount = New System.Windows.Forms.TextBox
Me.labelTaxAmount = New System.Windows.Forms.Label
Me.buttonSave = New System.Windows.Forms.Button
Me.buttonCancel = New System.Windows.Forms.Button
Me.textBoxTAX = New System.Windows.Forms.TextBox
Me.labelTax = New System.Windows.Forms.Label
Me.labelSalary = New System.Windows.Forms.Label
Me.comboBoxSalary = New System.Windows.Forms.ComboBox
Me.labelEmployeeType = New System.Windows.Forms.Label
Me.comboBoxEmployeeType = New System.Windows.Forms.ComboBox
Me.textBoxLastname = New System.Windows.Forms.TextBox
Me.labelLastname = New System.Windows.Forms.Label
Me.textBoxFirstname = New System.Windows.Forms.TextBox
Me.labelFirsname = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'textBoxTaxAmount
'
Me.textBoxTaxAmount.Location = New System.Drawing.Point(101, 170)
Me.textBoxTaxAmount.Name = "textBoxTaxAmount"
Me.textBoxTaxAmount.ReadOnly = True
Me.textBoxTaxAmount.Size = New System.Drawing.Size(179, 20)
Me.textBoxTaxAmount.TabIndex = 27
'
'labelTaxAmount
'
Me.labelTaxAmount.AutoSize = True
Me.labelTaxAmount.Location = New System.Drawing.Point(12, 173)
Me.labelTaxAmount.Name = "labelTaxAmount"
Me.labelTaxAmount.Size = New System.Drawing.Size(70, 13)
Me.labelTaxAmount.TabIndex = 26
Me.labelTaxAmount.Text = "TAX Amount:"
'
'buttonSave
'
Me.buttonSave.Location = New System.Drawing.Point(124, 212)
Me.buttonSave.Name = "buttonSave"
Me.buttonSave.Size = New System.Drawing.Size(75, 23)
Me.buttonSave.TabIndex = 25
Me.buttonSave.Text = "&Save"
Me.buttonSave.UseVisualStyleBackColor = True
'
'buttonCancel
'
Me.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.buttonCancel.Location = New System.Drawing.Point(205, 212)
Me.buttonCancel.Name = "buttonCancel"
Me.buttonCancel.Size = New System.Drawing.Size(75, 23)
Me.buttonCancel.TabIndex = 24
Me.buttonCancel.Text = "&Cancel"
Me.buttonCancel.UseVisualStyleBackColor = True
'
'textBoxTAX
'
Me.textBoxTAX.Location = New System.Drawing.Point(101, 144)
Me.textBoxTAX.Name = "textBoxTAX"
Me.textBoxTAX.ReadOnly = True
Me.textBoxTAX.Size = New System.Drawing.Size(179, 20)
Me.textBoxTAX.TabIndex = 23
Me.textBoxTAX.Text = "0.10"
'
'labelTax
'
Me.labelTax.AutoSize = True
Me.labelTax.Location = New System.Drawing.Point(12, 147)
Me.labelTax.Name = "labelTax"
Me.labelTax.Size = New System.Drawing.Size(31, 13)
Me.labelTax.TabIndex = 22
Me.labelTax.Text = "TAX:"
'
'labelSalary
'
Me.labelSalary.AutoSize = True
Me.labelSalary.Location = New System.Drawing.Point(12, 120)
Me.labelSalary.Name = "labelSalary"
Me.labelSalary.Size = New System.Drawing.Size(39, 13)
Me.labelSalary.TabIndex = 20
Me.labelSalary.Text = "Salary:"
'
'comboBoxSalary
'
Me.comboBoxSalary.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboBoxSalary.FormattingEnabled = True
Me.comboBoxSalary.Location = New System.Drawing.Point(101, 117)
Me.comboBoxSalary.Name = "comboBoxSalary"
Me.comboBoxSalary.Size = New System.Drawing.Size(179, 21)
Me.comboBoxSalary.TabIndex = 21
'
'labelEmployeeType
'
Me.labelEmployeeType.AutoSize = True
Me.labelEmployeeType.Location = New System.Drawing.Point(12, 93)
Me.labelEmployeeType.Name = "labelEmployeeType"
Me.labelEmployeeType.Size = New System.Drawing.Size(83, 13)
Me.labelEmployeeType.TabIndex = 18
Me.labelEmployeeType.Text = "Employee Type:"
'
'comboBoxEmployeeType
'
Me.comboBoxEmployeeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.comboBoxEmployeeType.FormattingEnabled = True
Me.comboBoxEmployeeType.Location = New System.Drawing.Point(101, 90)
Me.comboBoxEmployeeType.Name = "comboBoxEmployeeType"
Me.comboBoxEmployeeType.Size = New System.Drawing.Size(179, 21)
Me.comboBoxEmployeeType.TabIndex = 19
'
'textBoxLastname
'
Me.textBoxLastname.Location = New System.Drawing.Point(101, 64)
Me.textBoxLastname.Name = "textBoxLastname"
Me.textBoxLastname.Size = New System.Drawing.Size(179, 20)
Me.textBoxLastname.TabIndex = 17
'
'labelLastname
'
Me.labelLastname.AutoSize = True
Me.labelLastname.Location = New System.Drawing.Point(12, 67)
Me.labelLastname.Name = "labelLastname"
Me.labelLastname.Size = New System.Drawing.Size(56, 13)
Me.labelLastname.TabIndex = 16
Me.labelLastname.Text = "Lastname:"
'
'textBoxFirstname
'
Me.textBoxFirstname.Location = New System.Drawing.Point(101, 38)
Me.textBoxFirstname.Name = "textBoxFirstname"
Me.textBoxFirstname.Size = New System.Drawing.Size(179, 20)
Me.textBoxFirstname.TabIndex = 15
'
'labelFirsname
'
Me.labelFirsname.AutoSize = True
Me.labelFirsname.Location = New System.Drawing.Point(12, 41)
Me.labelFirsname.Name = "labelFirsname"
Me.labelFirsname.Size = New System.Drawing.Size(55, 13)
Me.labelFirsname.TabIndex = 14
Me.labelFirsname.Text = "Firstname:"
'
'FormEmployee
'
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.textBoxTaxAmount)
Me.Controls.Add(Me.labelTaxAmount)
Me.Controls.Add(Me.buttonSave)
Me.Controls.Add(Me.buttonCancel)
Me.Controls.Add(Me.textBoxTAX)
Me.Controls.Add(Me.labelTax)
Me.Controls.Add(Me.labelSalary)
Me.Controls.Add(Me.comboBoxSalary)
Me.Controls.Add(Me.labelEmployeeType)
Me.Controls.Add(Me.comboBoxEmployeeType)
Me.Controls.Add(Me.textBoxLastname)
Me.Controls.Add(Me.labelLastname)
Me.Controls.Add(Me.textBoxFirstname)
Me.Controls.Add(Me.labelFirsname)
Me.Name = "FormEmployee"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Private WithEvents textBoxTaxAmount As System.Windows.Forms.TextBox
Private WithEvents labelTaxAmount As System.Windows.Forms.Label
Private WithEvents buttonSave As System.Windows.Forms.Button
Private WithEvents buttonCancel As System.Windows.Forms.Button
Private WithEvents textBoxTAX As System.Windows.Forms.TextBox
Private WithEvents labelTax As System.Windows.Forms.Label
Private WithEvents labelSalary As System.Windows.Forms.Label
Private WithEvents comboBoxSalary As System.Windows.Forms.ComboBox
Private WithEvents labelEmployeeType As System.Windows.Forms.Label
Private WithEvents comboBoxEmployeeType As System.Windows.Forms.ComboBox
Private WithEvents textBoxLastname As System.Windows.Forms.TextBox
Private WithEvents labelLastname As System.Windows.Forms.Label
Private WithEvents textBoxFirstname As System.Windows.Forms.TextBox
Private WithEvents labelFirsname As System.Windows.Forms.Label
Private Sub FormEmployee_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
End Namespace
</code>Sv: Close + Implements i en form
Får bort felet med följande men är det ok?
<code>
Public Overloads Sub Close() Implements IEmployeeView.Close
End Sub
</code>