private void DeleteNote(int noteId) { if (noteId != -1) { try { TcpClient tcpClient = new TcpClient(); tcpClient.Connect(ServerIp, ServerPort); WriteToStream(tcpClient.GetStream(), $"DELN {noteId}"); tcpClient.Close(); Classes.Note bufNote = Groups.Where(g => g.Id == SelectedGroupId).FirstOrDefault().Notes.Where(n => n.Id == noteId).FirstOrDefault(); Groups.Where(g => g.Id == SelectedGroupId).FirstOrDefault().Notes.Remove(bufNote); SelectedNoteId = -1; NoteMenu.Visibility = Visibility.Hidden; OpenNotesMenu(); } catch (Exception) { ShowErrorWindow("Something went wrong"); } } else { ShowErrorWindow("Note is not selected"); } }
//Подробное меню заметки private void ShowNoteDescription() { NoteMenu.Visibility = Visibility.Visible; DoubleAnimation animation = new DoubleAnimation(); animation.From = 0; animation.To = 1; animation.AccelerationRatio = 0.1; animation.DecelerationRatio = 0.9; animation.Duration = TimeSpan.FromSeconds(0.5); try { Classes.Note note = Groups.Where(g => g.Id == SelectedGroupId).FirstOrDefault().Notes.Where(n => n.Id == SelectedNoteId).FirstOrDefault(); IsTextCurrentlyChanged = true; NoteNameBox.Text = note.Title; NoteDescriptionBox.Text = note.Description; IsTextCurrentlyChanged = false; NoteMenu.BeginAnimation(OpacityProperty, animation); } catch (Exception) { ShowErrorWindow("Something went wrong"); throw; } }
private void CreateNote() { try { TcpClient tcpClient = new TcpClient(); tcpClient.Connect(ServerIp, ServerPort); WriteToStream(tcpClient.GetStream(), $"CRTN {SelectedGroupId}"); string json = ReadStringFromStream(tcpClient.GetStream()); Classes.Note newNote = JsonConvert.DeserializeObject <Classes.Note>(json); tcpClient.Close(); Groups.Where(g => g.Id == SelectedGroupId).FirstOrDefault().Notes.Add(newNote); AddNote("n" + newNote.Id, newNote.Title, newNote.IsChecked, true); } catch (Exception) { ShowErrorWindow("Something went wrong"); } }