private void deleteSelectedClientButton_Click(object sender, EventArgs e) { Client selectedClient = (Client)clientListBox.SelectedItem; if (selectedClient != null) { Clients.Remove(selectedClient); TextConnectorProcessor.SaveToClientFile(Clients, TextConnection.ClientFile); List <int> sessionsToRemove = new List <int>(); foreach (Session s in Sessions) { if (s.client.FullName == selectedClient.FullName) { sessionsToRemove.Add(s.Id); } } foreach (int i in sessionsToRemove) { Sessions.RemoveAll(p => p.Id == i); } TextConnectorProcessor.SaveToSessionFile(Sessions, TextConnection.SessionFile); WireUpLists(); } else { MessageBox.Show("There are no clients to delete."); } }
private void deleteSelectedSessionButton_Click(object sender, EventArgs e) { Session selectedSession = (Session)sessionListBox.SelectedItem; if (selectedSession != null) { Sessions.Remove(selectedSession); TextConnectorProcessor.SaveToSessionFile(Sessions, TextConnection.SessionFile); WireUpLists(); } else { MessageBox.Show("There are no clients to delete."); } }
private void viewSelectedSessionButton_Click(object sender, EventArgs e) { Session tempSession = (Session)sessionListBox.SelectedItem; if (tempSession != null) { using (var v = new viewSessionForm(tempSession)) { var result = v.ShowDialog(); if (result == DialogResult.OK) { returnSession = v.returnSession; v.FormClosing += new FormClosingEventHandler(this.V_FormClosing); } if (result == DialogResult.Cancel) { returnSession = tempSession; } } int editedSessionPosition = Sessions.IndexOf(tempSession); Sessions.Insert(editedSessionPosition, returnSession); Sessions.Remove(tempSession); TextConnectorProcessor.SaveToClientFile(Clients, TextConnection.ClientFile); TextConnectorProcessor.SaveToSessionFile(Sessions, TextConnection.SessionFile); WireUpLists(); sessionListBox.SetSelected(editedSessionPosition, true); } else { MessageBox.Show("There are no sessions available to view."); } //TODO: Fix error of x'ing out of add client box. Changes record to NULL in JSON? - or replaces model with last edited one?? }