private void OnSave(object sender, RoutedEventArgs e) { if (camera_name.Text == "") { camera_name.Background = new SolidColorBrush(Colors.Red); } else if (address.Text == "") { address.Background = new SolidColorBrush(Colors.Red); } else if (user.Text == "") { user.Background = new SolidColorBrush(Colors.Red); } else if (password.Password == "") { password.Background = new SolidColorBrush(Colors.Red); } else { CameraConnexion cc = new CameraConnexion(); cc.Address = address.Text; cc.CameraName = camera_name.Text; cc.Password = password.Password; cc.User = user.Text; // write login info in json file if (cameras == null) { cameras = new List <CameraConnexion>(); } // override camera if is already saved with same name int index = cameras.FindIndex(element => element.CameraName.Equals(cc.CameraName)); if (index == -1) { cameras.Add(cc); } else { cameras[index] = cc; } string json = JsonConvert.SerializeObject(cameras); if (!File.Exists(path_to_connexion_file)) { File.CreateText(path_to_connexion_file).Close(); } using (StreamWriter file = new StreamWriter(path_to_connexion_file, false)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, cameras); } LoadConnexion(); } }
private void OnSavedSelectionChanged(object sender, RoutedEventArgs e) { if (cameras != null && listBox_saved.SelectedIndex >= 0) { selectedCam = cameras.ElementAt(listBox_saved.SelectedIndex); address.Text = selectedCam.Address; password.Password = selectedCam.Password; user.Text = selectedCam.User; camera_name.Text = selectedCam.CameraName; // Can be Deleted delete_cam_btn.IsEnabled = true; if (previousSavedConnIndex == listBox_saved.SelectedIndex) { ConnectCam(); } previousSavedConnIndex = listBox_saved.SelectedIndex; } listBox_saved.SelectedIndex = -1; }