243 lines
9.2 KiB
VB.net
243 lines
9.2 KiB
VB.net
Imports ApplicationCrèche_1.IDFormMode
|
|
|
|
Public Class FormBabySitterID
|
|
' ----- Attributes -----
|
|
Private actualFormMode As IDFormMode
|
|
|
|
' ----- Initialisators -----
|
|
Private Sub FormBabySitterID_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
|
|
|
|
End Sub
|
|
|
|
Public Sub New(aFormMode As IDFormMode, Optional aBS As BabySitter = Nothing)
|
|
Console.WriteLine("FormBabySitterID : Begining of a new instance")
|
|
' Cet appel est requis par le concepteur.
|
|
InitializeComponent()
|
|
|
|
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
|
|
If aFormMode = CREATOR Or aBS Is Nothing Then
|
|
ChangeMode(CREATOR)
|
|
Else
|
|
ChangeMode(aFormMode, aBS)
|
|
End If
|
|
End Sub
|
|
|
|
' ----- Methodes -----
|
|
Private Function getBSFromIntern() As BabySitter
|
|
Dim newBS As BabySitter = New BabySitter(Me.Tag)
|
|
newBS.firstname = TBFirstName.Text
|
|
newBS.lastname = TBLastName.Text
|
|
newBS.gender = RBMale.Checked
|
|
newBS.address = TBAddress.Text
|
|
newBS.phone1 = TBPhone1.Text
|
|
If Not String.IsNullOrEmpty(TBPhone2.Text) Then
|
|
newBS.phone2 = TBPhone2.Text
|
|
End If
|
|
|
|
Return newBS
|
|
End Function
|
|
|
|
Private Function updateBSFromExtern(aBS As BabySitter) As Boolean
|
|
If Not aBS Is Nothing Then
|
|
' Fill up controls with all the data we have.
|
|
Me.TBFirstName.Text = aBS.firstname 'Firstname
|
|
Me.TBLastName.Text = aBS.lastname 'Lastname
|
|
If aBS.gender Then 'Gender
|
|
Me.RBMale.Checked = True
|
|
Else
|
|
Me.RBFemale.Checked = True
|
|
End If
|
|
Me.TBAddress.Text = aBS.address
|
|
Me.TBPhone1.Text = aBS.phone1
|
|
Me.TBPhone2.Text = aBS.phone2
|
|
Me.Tag = aBS.id
|
|
If Not aBS.meet1 Is Nothing Then
|
|
Dim child1 As Child = dbdata.getChildByMeetID(aBS.meet1.id)
|
|
updateMeet(child1)
|
|
End If
|
|
If Not aBS.meet2 Is Nothing Then
|
|
Dim child2 As Child = dbdata.getChildByMeetID(aBS.meet2.id)
|
|
updateMeet(child2)
|
|
End If
|
|
If Not aBS.meet3 Is Nothing Then
|
|
Dim child3 As Child = dbdata.getChildByMeetID(aBS.meet3.id)
|
|
updateMeet(child3)
|
|
End If
|
|
Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Private Sub updateMeet(aChild As Child)
|
|
|
|
If aChild.meet.monday Then
|
|
Keep1.Enabled = aChild.meet.monday
|
|
Keep1.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.tuesday Then
|
|
Keep2.Enabled = aChild.meet.tuesday
|
|
Keep2.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.wednesday Then
|
|
Keep3.Enabled = aChild.meet.wednesday
|
|
Keep3.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.thursday Then
|
|
Keep4.Enabled = aChild.meet.thursday
|
|
Keep4.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.friday Then
|
|
Keep5.Enabled = aChild.meet.friday
|
|
Keep5.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.saturday Then
|
|
Keep6.Enabled = aChild.meet.saturday
|
|
Keep6.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
|
|
If aChild.meet.sunday Then
|
|
Keep7.Enabled = aChild.meet.sunday
|
|
Keep7.Text &= " : " & aChild.firstname & " " & aChild.lastname
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub ChangeMode(aFormMode As IDFormMode, Optional aBS As BabySitter = Nothing)
|
|
updateBSFromExtern(aBS)
|
|
If aFormMode = IDFormMode.CREATOR Then ' CREATOR MODE
|
|
Me.actualFormMode = CREATOR
|
|
Console.WriteLine("FormBabySitterID : Switch to CREATOR Mode")
|
|
|
|
'Change of the main triggers labels + title
|
|
Me.Text = "New babysitter"
|
|
Me.ButtonClose.Text = "Cancel"
|
|
Me.ButtonEdit.Text = "Save"
|
|
Me.RBMale.Checked = True
|
|
Me.Tag = 0
|
|
Me.ButtonEdit.Image = My.Resources.AddSheet2
|
|
|
|
ElseIf aFormMode = IDFormMode.VIEWER And Not aBS Is Nothing Then ' VIEW MODE
|
|
Me.actualFormMode = VIEWER
|
|
Console.WriteLine("FormBabySitterID : Switch to VIEWER Mode")
|
|
|
|
'We change the main triggers labels + title
|
|
Me.Text = aBS.firstname + " " + aBS.lastname
|
|
Me.ButtonClose.Text = "Close"
|
|
Me.ButtonEdit.Text = "Edit"
|
|
Me.ButtonEdit.Image = My.Resources.EditSheet2
|
|
|
|
'Activate most important security aspect (not show a window that can mat a save somewhere else)
|
|
TBAddress.Enabled = False
|
|
TBFirstName.Enabled = False
|
|
TBLastName.Enabled = False
|
|
TBPhone1.Enabled = False
|
|
TBPhone2.Enabled = False
|
|
RBFemale.Enabled = False
|
|
RBMale.Enabled = False
|
|
|
|
ElseIf aFormMode = IDFormMode.EDITOR Then ' EDITOR MODE WITH THE CURRENT BS
|
|
Console.WriteLine("FormBabySitterID : Switch to Editor Mode")
|
|
Me.actualFormMode = EDITOR
|
|
|
|
'We change the main triggers labels + title
|
|
Me.Text = Me.TBFirstName.Text + " " + Me.TBLastName.Text + " (Edit)"
|
|
Me.ButtonClose.Text = "Cancel"
|
|
Me.ButtonEdit.Text = "Update"
|
|
Me.ButtonEdit.Image = My.Resources.ValidedSheet
|
|
|
|
'Turn off anti edit security
|
|
TBAddress.Enabled = True
|
|
TBFirstName.Enabled = True
|
|
TBLastName.Enabled = True
|
|
TBPhone1.Enabled = True
|
|
TBPhone2.Enabled = True
|
|
RBFemale.Enabled = True
|
|
RBMale.Enabled = True
|
|
|
|
Else
|
|
Console.WriteLine("FormChildId : No correct mode has been found.")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
' ----- Handles and Listeners -----
|
|
Protected Overrides Sub ButtonEdit_Click(sender As System.Object, e As System.EventArgs)
|
|
Dim Validated As Boolean = True
|
|
If Me.actualFormMode = VIEWER Then 'EDIT'
|
|
Me.ChangeMode(EDITOR)
|
|
ElseIf Me.actualFormMode = CREATOR Then 'SAVE'
|
|
' Error Provider
|
|
If String.IsNullOrEmpty(TBFirstName.Text) Then
|
|
ErrorProvider1.SetError(TBFirstName, "The first name field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBLastName.Text) Then
|
|
ErrorProvider1.SetError(TBLastName, "The last name field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBPhone1.Text) Then
|
|
ErrorProvider1.SetError(TBPhone1, "At least on phone number is required." & vbNewLine & "Please put a phone number here.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBAddress.Text) Then
|
|
ErrorProvider1.SetError(LabelAddress, "The address field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
|
|
If Not Validated Then
|
|
Exit Sub
|
|
End If
|
|
|
|
'Validation
|
|
Dim aBS As BabySitter = getBSFromIntern()
|
|
dbdata.addBabysitter(aBS)
|
|
Me.DialogResult = Windows.Forms.DialogResult.OK
|
|
Me.Hide()
|
|
|
|
ElseIf Me.actualFormMode = EDITOR Then 'UPDATE'
|
|
' Error Provider
|
|
If String.IsNullOrEmpty(TBFirstName.Text) Then
|
|
ErrorProvider1.SetError(TBFirstName, "The first name field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBLastName.Text) Then
|
|
ErrorProvider1.SetError(TBLastName, "The last name field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBPhone1.Text) Then
|
|
ErrorProvider1.SetError(TBPhone1, "At least on phone number is required." & vbNewLine & "Please put a phone number here.")
|
|
Validated = False
|
|
End If
|
|
If String.IsNullOrEmpty(TBAddress.Text) Then
|
|
ErrorProvider1.SetError(LabelAddress, "The address field could not be empty." & vbNewLine & "Please fill this field.")
|
|
Validated = False
|
|
End If
|
|
|
|
|
|
If Not Validated Then
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
'Validation
|
|
Dim aBS As BabySitter = getBSFromIntern()
|
|
dbdata.editBabysitter(aBS)
|
|
Me.DialogResult = Windows.Forms.DialogResult.OK
|
|
Me.Hide()
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ButtonClose_Click_1(sender As System.Object, e As System.EventArgs) Handles ButtonClose.Click
|
|
Console.WriteLine("FormBabySitterID : Closing instance")
|
|
Me.Close()
|
|
Me.Finalize()
|
|
End Sub
|
|
|
|
End Class
|