Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' http://pastebin.com/HiF6rp7b
- Imports CodiceFiscale.Model
- Public Class MainForm
- #Region "Proprietà per l'accesso ai controlli"
- ' il form dovrà gestire le info di una persona
- ' nome
- Property FirstName As String
- Get
- Return txtFirstName.Text.Trim
- End Get
- Set(value As String)
- txtFirstName.Text = value
- End Set
- End Property
- ' cognome
- Property LastName As String
- Get
- Return txtLastName.Text.Trim
- End Get
- Set(value As String)
- txtLastName.Text = value
- End Set
- End Property
- ' sesso
- Property Sex As SexType
- Get
- If rbFemale.Checked Then
- Return SexType.Female
- End If
- Return SexType.Male
- End Get
- Set(value As SexType)
- If value = SexType.Male Then
- rbMale.Checked = True
- Else
- rbFemale.Checked = True
- End If
- End Set
- End Property
- ' data di nascita
- Property Birthday As DateTime
- Get
- Return dateBirth.Value
- End Get
- Set(value As DateTime)
- dateBirth.Value = value
- End Set
- End Property
- ' città di nascita
- Property CityOfBirth As String
- Get
- Return txtCity.Text.Trim
- End Get
- Set(value As String)
- txtCity.Text = value
- End Set
- End Property
- #End Region
- Private Function ValidationRule() As Boolean
- Return Not String.IsNullOrEmpty(FirstName) AndAlso
- Not String.IsNullOrEmpty(LastName) AndAlso
- Not String.IsNullOrEmpty(CityOfBirth)
- End Function
- Private Sub CalcFC(sender As Object, e As EventArgs) Handles btnCalc.Click
- If Not ValidationRule() Then
- MessageBox.Show("Attenzione, mancano dei dati!")
- Else
- Dim p As New Person() With {
- .FirstName = FirstName,
- .LastName = LastName,
- .Birthday = Birthday,
- .CityOfBirth = CityOfBirth,
- .Sex = Sex
- }
- lblFiscalCode.Text = p.GetFiscalCode()
- End If
- End Sub
- Private Sub ValidationCheck(sender As Object, e As EventArgs) Handles txtLastName.TextChanged, txtFirstName.TextChanged, txtCity.TextChanged
- btnCalc.Enabled = ValidationRule()
- End Sub
- Private Sub txtFirstName_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtFirstName.Validating
- If String.IsNullOrEmpty(FirstName) Then
- ep.SetError(txtFirstName, "Inserire il nome.")
- e.Cancel = True
- Else
- ep.SetError(txtFirstName, "")
- End If
- End Sub
- Private Sub txtLastName_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtLastName.Validating
- If String.IsNullOrEmpty(LastName) Then
- ep.SetError(txtLastName, "Inserire il cognome.")
- e.Cancel = True
- Else
- ep.SetError(txtLastName, "")
- End If
- End Sub
- Private Sub txtCity_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtCity.Validating
- If String.IsNullOrEmpty(CityOfBirth) Then
- ep.SetError(txtCity, "Inserire la città di nascita.")
- e.Cancel = True
- Else
- ep.SetError(txtCity, "")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement