示例#1
0
        public static void SaveEnjoymentsFromRichTextBoxToTXTFile(RichTextBox richTextBox)
        {
            try
            {
                log.Debug($"Validating if directory {FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)} exists.");
                if (!Directory.Exists(Path.GetDirectoryName(FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt))))
                {
                    log.Debug($"Directory do not exists. Creating new directory {FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)}");
                    Directory.CreateDirectory(Path.GetDirectoryName(FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)));
                }
            }
            catch (Exception ex)
            {
                log.Error($"There are some problems with directory creation {FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)}", ex);
            }

            try
            {
                log.Debug($"Validating if file {FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)} exists.");
                if (!File.Exists(FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)))
                {
                    string originalFileName = DateTime.Now.ToString("dd.MM.yyyy.HH.mm.ss") + FilesNames.enjoymentsTxt;
                    log.Debug($"File do not exists. Creating new file with original file name {FilesHelper.FilePathToMyDesktop(originalFileName)}");

                    using (StreamWriter writer = new StreamWriter(FilesHelper.FilePathToMyDesktop(originalFileName)))
                    {
                        writer.Write($"ZÁŽITKY <3 \nUložené {DateTime.Now.ToString("dd.MM.yyyy HH:mm")} \n");
                        writer.Write(richTextBox.Text);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error($"There are some problems with file creation {FilesHelper.FilePathToMyDesktop(FilesNames.enjoymentsTxt)}", ex);
            }
        }
        public MyDearChildMainForm()
        {
            InitializeComponent();
            ListOfChildren            = FilesHelper.DeserializeJsonFileToList(ListOfChildren, FilesHelper.FilePathToAppDataFolder(FilesNames.childJson));
            ListOfEnjoymentCategories = FilesHelper.DeserializeJsonFileToList(ListOfEnjoymentCategories, FilesHelper.FilePathToAppDataFolder(FilesNames.enjoymentsCategoriesJson));
            ListOfEnjoyments          = FilesHelper.DeserializeJsonFileToList(ListOfEnjoyments, FilesHelper.FilePathToAppDataFolder(FilesNames.enjoymentsJson));

            if (ListOfEnjoymentCategories.Count == 0)
            {
                ListOfEnjoymentCategories.Add("Vtipný");
                ListOfEnjoymentCategories.Add("Sny");
                ListOfEnjoymentCategories.Add("Pohyb");
            }
        }
 private void MyDearChildMainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     FilesHelper.SerializeListToJsonFile(ListOfChildren, FilesHelper.FilePathToAppDataFolder(FilesNames.childJson));
     FilesHelper.SerializeListToJsonFile(ListOfEnjoymentCategories, FilesHelper.FilePathToAppDataFolder(FilesNames.enjoymentsCategoriesJson));
     FilesHelper.SerializeListToJsonFile(ListOfEnjoyments, FilesHelper.FilePathToAppDataFolder(FilesNames.enjoymentsJson));
 }
示例#4
0
 private void BtnSaveEnjoyments_Click(object sender, EventArgs e)
 {
     FilesHelper.SaveEnjoymentsFromRichTextBoxToTXTFile(richTextBoxEnjoyments);
     MessageBox.Show("Vaše zážitky máte uložené na pracovní ploše ve složce MyDearChild", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }