320 lines
13 KiB
VB.net
320 lines
13 KiB
VB.net
Public Class FormList
|
|
|
|
' ----- Privates Attributes -----
|
|
Private aTypeofPerson As PersonType
|
|
Private aFormMode As ListFormMode
|
|
|
|
' ----- Initialisators ------
|
|
Private Sub FormList_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
|
|
|
|
End Sub
|
|
|
|
Public Sub New(aTypeOfPerson As PersonType, aFormMode As ListFormMode, Optional aMeet As Meet = Nothing)
|
|
Console.WriteLine("FormList : Begining of a new instance")
|
|
' Cet appel est requis par le concepteur.
|
|
InitializeComponent()
|
|
|
|
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
|
|
Me.aTypeofPerson = aTypeOfPerson
|
|
Me.aFormMode = aFormMode
|
|
' If we show the list to pick up someone and return him back to the calling window
|
|
If aFormMode = ListFormMode.Selector Then
|
|
TSButtonClose.Text = "Cancel"
|
|
TSButtonSelect.Visible = True
|
|
TSPin.Visible = False
|
|
CMSSelect.Visible = True
|
|
CMSSep.Visible = True
|
|
ListView.HeaderStyle = ColumnHeaderStyle.None
|
|
ListView.Columns(0).Width = 300
|
|
ListView.Columns(1).Width = 1
|
|
ElseIf aFormMode = ListFormMode.Viewer Then ' If we show the list to manage peoples inside
|
|
TSButtonClose.Text = "Close"
|
|
TSButtonSelect.Visible = False
|
|
CMSSelect.Visible = False
|
|
CMSSep.Visible = False
|
|
If aTypeOfPerson = PersonType.BabySitter Then TSPin.Visible = True
|
|
ListView.HeaderStyle = ColumnHeaderStyle.None
|
|
ListView.Columns(0).Width = 300
|
|
ListView.Columns(1).Width = 1
|
|
ElseIf aFormMode = ListFormMode.SelectFiltered Then ' Special mode to pick up a babysitter, without the possibility to add or delete one.
|
|
TSButtonClose.Text = "Cancel"
|
|
TSButtonAdd.Visible = False
|
|
TSButtonSelect.Visible = True
|
|
TSButtonDelete.Visible = False
|
|
TSPin.Visible = False
|
|
CMSDelete.Visible = False
|
|
ListView.HeaderStyle = ColumnHeaderStyle.None
|
|
ListView.Columns(0).Width = 300
|
|
ListView.Columns(1).Width = 1
|
|
ElseIf aFormMode = ListFormMode.SelectWithAdress Then ' Special mode to pick up a parent address
|
|
TSButtonClose.Text = "Cancel"
|
|
TSButtonAdd.Visible = False
|
|
TSButtonSelect.Visible = True
|
|
TSButtonDelete.Visible = False
|
|
TSPin.Visible = False
|
|
ListView.HeaderStyle = ColumnHeaderStyle.Nonclickable
|
|
ListView.Columns(0).Width = 140
|
|
ListView.Columns(1).Width = 160
|
|
CMSDelete.Visible = False
|
|
End If
|
|
loadList(aMeet)
|
|
|
|
If aTypeOfPerson = PersonType.BabySitter Then
|
|
Me.Text = "List of babysitters"
|
|
Me.TSButtonAdd.Text = "Add a babysitter"
|
|
ElseIf aTypeOfPerson = PersonType.Parent Then
|
|
Me.Text = "List of parent"
|
|
Me.TSButtonAdd.Text = "Add a parent"
|
|
Else
|
|
Console.WriteLine("FormList : " + aTypeOfPerson)
|
|
Me.Text = "List of " + aTypeOfPerson.ToString
|
|
End If
|
|
|
|
End Sub
|
|
|
|
' ----- Methodes -----
|
|
|
|
Private Sub ViewSelected()
|
|
If Me.aTypeofPerson = PersonType.BabySitter Then
|
|
Dim aBS As BabySitter = dbdata.getBabysitterByID(ListView.SelectedItems(0).Tag)
|
|
Dim aFormBS As FormBabySitterID = New FormBabySitterID(IDFormMode.VIEWER, aBS)
|
|
Dim conclusion As DialogResult = aFormBS.ShowDialog()
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
aFormBS.Dispose()
|
|
ElseIf Me.aTypeofPerson = PersonType.Parent Then
|
|
Dim aParent As Parent = dbdata.getParentByID(ListView.SelectedItems(0).Tag)
|
|
Dim aFormParent As FormParentID = New FormParentID(IDFormMode.VIEWER, aParent)
|
|
Dim conclusion As DialogResult = aFormParent.ShowDialog
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
aFormParent.Dispose()
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Show a window to edit the element
|
|
''' </summary>
|
|
''' <remarks></remarks>
|
|
Private Sub EditSelected()
|
|
If Me.aTypeofPerson = PersonType.BabySitter Then
|
|
Dim aBS As BabySitter = dbdata.getBabysitterByID(ListView.SelectedItems(0).Tag)
|
|
Dim aFormBS As FormBabySitterID = New FormBabySitterID(IDFormMode.EDITOR, aBS)
|
|
Dim conclusion As DialogResult = aFormBS.ShowDialog()
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
aFormBS.Dispose()
|
|
ElseIf Me.aTypeofPerson = PersonType.Parent Then
|
|
Dim aParent As Parent = dbdata.getParentByID(ListView.SelectedItems(0).Tag)
|
|
Dim aFormParent As FormParentID = New FormParentID(IDFormMode.EDITOR, aParent)
|
|
Dim conclusion As DialogResult = aFormParent.ShowDialog
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
aFormParent.Dispose()
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Return the selected element to the calling window
|
|
''' </summary>
|
|
''' <remarks></remarks>
|
|
Private Sub ReturnSelected()
|
|
If PrepareSelected() Then
|
|
Console.WriteLine("FormList : Closing instance")
|
|
Me.DialogResult = Windows.Forms.DialogResult.OK
|
|
Me.Hide()
|
|
End If
|
|
End Sub
|
|
|
|
Private Function PrepareSelected() As Boolean
|
|
If ListView.SelectedItems.Count > 0 Then
|
|
Me.Tag = ListView.SelectedItems(0).Tag
|
|
Return True
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
Private Sub reloadList()
|
|
ListView.Items.Clear()
|
|
loadList(Nothing)
|
|
End Sub
|
|
|
|
Private Sub loadList(aMeet As Meet)
|
|
' Babysitter
|
|
If aTypeofPerson = PersonType.BabySitter Then
|
|
' Getting back babysitters
|
|
Dim BSList As List(Of BabySitter) = FilterList(aMeet)
|
|
|
|
For Each aBS As BabySitter In BSList
|
|
ListView.Items.Add(aBS.firstname + " " + aBS.lastname).Tag = aBS.id
|
|
Next
|
|
' Parent
|
|
ElseIf aTypeofPerson = PersonType.Parent Then
|
|
Dim ParentList As List(Of Parent) = dbdata.getParents()
|
|
|
|
For Each aParent As Parent In ParentList
|
|
Dim itemChild As ListViewItem = ListView.Items.Add(aParent.firstname + " " + aParent.lastname)
|
|
If aFormMode = ListFormMode.SelectWithAdress Then itemChild.SubItems.Add(aParent.address)
|
|
itemChild.Tag = aParent.id
|
|
Next
|
|
End If
|
|
End Sub
|
|
|
|
Private Function FilterList(wishedMeet As Meet) As List(Of BabySitter)
|
|
If wishedMeet Is Nothing Then
|
|
Return dbdata.getBabysitters()
|
|
End If
|
|
|
|
Dim ABSList As List(Of BabySitter) = dbdata.getAvailableBabysitters()
|
|
Dim FilteredBSList As List(Of BabySitter) = New List(Of BabySitter)
|
|
For Each aBS As BabySitter In ABSList
|
|
If Not (wishedMeet.overlap(aBS.meet1) Or
|
|
wishedMeet.overlap(aBS.meet2) Or
|
|
wishedMeet.overlap(aBS.meet3)) Then
|
|
FilteredBSList.Add(aBS)
|
|
End If
|
|
Next
|
|
Return FilteredBSList
|
|
End Function
|
|
|
|
' ----- Handles and Listerners -----
|
|
Private Sub DeleteSelected()
|
|
Dim msgResult As DialogResult = MsgBox("You are about to remove " & ListView.SelectedItems(0).Text & " from the software. Would you continue ?", MsgBoxStyle.YesNo, "Confirm deletion")
|
|
If msgResult = vbYes Then
|
|
If Me.aTypeofPerson = PersonType.BabySitter Then
|
|
dbdata.deleteBabysitterByID(ListView.SelectedItems(0).Tag)
|
|
ElseIf Me.aTypeofPerson = PersonType.Parent Then
|
|
dbdata.deleteParentByID(ListView.SelectedItems(0).Tag)
|
|
End If
|
|
reloadList()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CMSDelete_Click(sender As System.Object, e As System.EventArgs) Handles CMSDelete.Click
|
|
DeleteSelected()
|
|
End Sub
|
|
|
|
Private Sub TSButtonDelete_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonDelete.Click
|
|
DeleteSelected()
|
|
End Sub
|
|
|
|
Private Sub TSButtonAdd_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonAdd.Click
|
|
If (aTypeofPerson = PersonType.Parent) Then
|
|
Dim createParent As FormParentID = New FormParentID(IDFormMode.CREATOR)
|
|
Dim conclusion As DialogResult = createParent.ShowDialog
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
createParent.Dispose()
|
|
ElseIf aTypeofPerson = PersonType.BabySitter Then
|
|
Dim createBD As FormBabySitterID = New FormBabySitterID(IDFormMode.CREATOR)
|
|
Dim conclusion As DialogResult = createBD.ShowDialog
|
|
If conclusion = Windows.Forms.DialogResult.OK Then
|
|
reloadList()
|
|
End If
|
|
createBD.Dispose()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub TSButtonEdit_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonEdit.Click
|
|
EditSelected()
|
|
End Sub
|
|
Private Sub CMSEdit_Click(sender As System.Object, e As System.EventArgs) Handles CMSEdit.Click
|
|
EditSelected()
|
|
End Sub
|
|
|
|
Private Sub TSButtonSelect_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonSelect.Click
|
|
ReturnSelected()
|
|
End Sub
|
|
Private Sub CMSSelect_Click(sender As System.Object, e As System.EventArgs) Handles CMSSelect.Click
|
|
ReturnSelected()
|
|
End Sub
|
|
|
|
Private Sub CMSShow_Click(sender As System.Object, e As System.EventArgs) Handles CMSShow.Click
|
|
ViewSelected()
|
|
End Sub
|
|
|
|
Private Sub TSButtonShow_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonShow.Click
|
|
ViewSelected()
|
|
End Sub
|
|
|
|
Private Sub ListView_DoubleClick(sender As System.Object, e As System.EventArgs) Handles ListView.DoubleClick
|
|
If ListView.SelectedIndices.Count > 0 Then
|
|
If aFormMode = ListFormMode.Viewer Then
|
|
ViewSelected()
|
|
Else
|
|
ReturnSelected()
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub BeforeClose()
|
|
Console.WriteLine("FormList : Closing instance")
|
|
If aFormMode = ListFormMode.Viewer Then
|
|
Me.Dispose()
|
|
Else
|
|
Me.DialogResult = Windows.Forms.DialogResult.Cancel
|
|
Me.Hide()
|
|
End If
|
|
End Sub
|
|
|
|
'Private Sub FormList_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
|
|
' BeforeClose()
|
|
'End Sub
|
|
|
|
Private Sub TSButtonClose_Click(sender As System.Object, e As System.EventArgs) Handles TSButtonClose.Click
|
|
BeforeClose()
|
|
End Sub
|
|
|
|
Private Sub ListView_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView.SelectedIndexChanged
|
|
If ListView.SelectedItems.Count <= 0 Then
|
|
TSButtonDelete.Enabled = False
|
|
TSButtonEdit.Enabled = False
|
|
TSButtonSelect.Enabled = False
|
|
TSButtonShow.Enabled = False
|
|
CMSDelete.Enabled = False
|
|
CMSEdit.Enabled = False
|
|
CMSSelect.Enabled = False
|
|
CMSShow.Enabled = False
|
|
|
|
CMSDelete.Text = "Delete selection"
|
|
CMSEdit.Text = "Edit selection..."
|
|
CMSShow.Text = "Show selection..."
|
|
CMSSelect.Text = "Select"
|
|
Else
|
|
TSButtonDelete.Enabled = True
|
|
TSButtonEdit.Enabled = True
|
|
TSButtonSelect.Enabled = True
|
|
TSButtonShow.Enabled = True
|
|
CMSDelete.Enabled = True
|
|
CMSEdit.Enabled = True
|
|
CMSSelect.Enabled = True
|
|
CMSShow.Enabled = True
|
|
|
|
CMSDelete.Text = "Delete " + ListView.SelectedItems(0).Text
|
|
CMSEdit.Text = "Edit " + ListView.SelectedItems(0).Text + "..."
|
|
CMSShow.Text = "Show " + ListView.SelectedItems(0).Text + "..."
|
|
CMSSelect.Text = "Select " + ListView.SelectedItems(0).Text
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles TSPin.Click
|
|
If TSPin.Checked Then
|
|
TSPin.Text = "Pin windows"
|
|
TSPin.Image = My.Resources.UnpingedWindows
|
|
TSPin.Checked = False
|
|
Else
|
|
TSPin.Text = "Unpin windows"
|
|
TSPin.Image = My.Resources.PingedWindows
|
|
TSPin.Checked = True
|
|
Me.Top = FormMain.Top
|
|
Me.Left = FormMain.Right
|
|
End If
|
|
End Sub
|
|
|
|
End Class |