private void SaveDiary(string title, DateTime date, string content, bool encrypted, byte[] key, byte[] iv) { var diary = new DiaryData(); diary.Title = title; diary.Content = content; diary.Date = date; diary.Encrypted = encrypted; if (encrypted != false) { diary.key = key; diary.iv = iv; } diary.Tags = _tagList .Select(x => x.TagText) .ToList(); var jsonText = JsonConvert.SerializeObject(diary, Formatting.Indented); var fileName = $"{date:yyyyMMdd}.json"; //현업에서 쓰이는 문법 var diaryPath = Path.Combine(_rootPath, fileName); File.WriteAllText(diaryPath, jsonText); Dispose(); }
/*private void InsertData() * { * _tagList = * }*/ private void UpdateView(DiaryData diaryData) { dateTimePicker1.Value = diaryData.Date; txtTitle.Text = diaryData.Title; string decrypted = diaryData.Content; if (diaryData.Encrypted == true) { var bytes = decrypted.Split(',') .Select(x => (byte)int.Parse(x)) .ToArray(); decrypted = Encryptor.DecryptStringFromBytes(bytes, diaryData.key, diaryData.iv); } txtContents.Text = decrypted; _tagTexts = diaryData.Tags; int index = 0; foreach (string tagText in _tagTexts) { Label label = new Label(); label.Text = tagText; Button button = new Button(); button.Text = "X"; // x버튼 누를 시 삭제 추가 TagControlData ControlData = new TagControlData(); ControlData.Control = label; ControlData.DeleteButton = button; ControlData.Index = index; ControlData.TagText = tagText; _tagList.Add(ControlData); index++; } #region Tags #region Remove tag Controls RefreshTagList(); /* foreach (var tagData in _tagData) * { * Controls.Remove(tagData.Control); * Controls.Remove(tagData.DeleteButton); * } */ #endregion /*#region Create tag Controls * _tagList = diaryData.Tags.Select((x, i) => new TagControlData * { * Index = i, * TagText = x, * Control = new Label { Text = x }, * DeleteButton = new Button { Text = "X" } * }).ToList(); //리스트 불러오기 * #endregion*/ #endregion }