Esempio n. 1
0
        private async Task SaveUpdatedNotesToFileAsync(List <NotesData> notes, ProgressData progressData)
        {
            progressData.Reset("Saving local copy of changes.", notes.Count);

            var saveFileDialog = new SaveFileDialog
            {
                Title            = "Save a record of updated notes",
                InitialDirectory = FileUtils.GetDefaultDirectory(null),
                FileName         = $"Ancestry Notes Changes {DateTime.Now.ToString("yyyy-MM-dd")}.xlsx",
                DefaultExt       = ".xlsx",
                Filter           = "Excel Workbook (*.xlsx)|*.xlsx",
            };

            if (saveFileDialog.ShowDialog() != true)
            {
                return;
            }
            Settings.Default.LastUsedDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
            Settings.Default.Save();
            var fileName = saveFileDialog.FileName;

            using (var p = new ExcelPackage())
            {
                await Task.Run(() =>
                {
                    var ws = p.Workbook.Worksheets.Add("Updated Notes");

                    var row = 1;
                    ws.Cells[row, 1].Value = "Name";
                    ws.Cells[row, 2].Value = "Test ID";
                    ws.Cells[row, 3].Value = "Old Notes";
                    ws.Cells[row, 4].Value = "New Notes";

                    foreach (var note in notes)
                    {
                        row++;

                        ws.Cells[row, 1].Value = note.Name;
                        ws.Cells[row, 2].Value = note.TestId;
                        ws.Cells[row, 3].Value = note.OldNotes;
                        ws.Cells[row, 4].Value = note.NewNotes;

                        progressData.Increment();
                    }
                });

                FileUtils.Save(p, fileName);
                FileUtils.LaunchFile(fileName);
            }
        }
Esempio n. 2
0
        private async Task SaveUpdatedNotesToFileAsync(List <NotesData> notes, List <Tag> originalTags, ProgressData progressData)
        {
            progressData.Reset("Saving local copy of changes.", notes.Count);

            var saveFileDialog = new SaveFileDialog
            {
                Title            = "Save a record of updated notes",
                InitialDirectory = FileUtils.GetDefaultDirectory(null),
                FileName         = $"Ancestry Notes Changes {DateTime.Now.ToString("yyyy-MM-dd")}.xlsx",
                DefaultExt       = ".xlsx",
                Filter           = "Excel Workbook (*.xlsx)|*.xlsx",
            };

            if (saveFileDialog.ShowDialog() != true)
            {
                return;
            }
            Settings.Default.LastUsedDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
            Settings.Default.Save();
            var fileName = saveFileDialog.FileName;

            var affectedNotes   = notes.Any(note => note.NewNotes != null);
            var affectedStarred = notes.Any(note => note.NewStarred != null);
            var affectedTagIds  = new HashSet <int>(notes.SelectMany(note => note.NewTags.Concat(note.NewTagsRemoved)));
            var affectedTags    = originalTags.Where(tag => affectedTagIds.Contains(tag.TagId)).ToList();

            using (var p = new ExcelPackage())
            {
                await Task.Run(() =>
                {
                    var ws = p.Workbook.Worksheets.Add("Updated Notes");

                    var row = 1;
                    var col = 1;
                    ws.Cells[row, col++].Value = "Name";
                    ws.Cells[row, col++].Value = "Test ID";
                    if (affectedNotes)
                    {
                        ws.Cells[row, col++].Value = "Old Notes";
                        ws.Cells[row, col++].Value = "New Notes";
                    }
                    if (affectedStarred)
                    {
                        ws.Cells[row, col++].Value = "Old Starred";
                        ws.Cells[row, col++].Value = "New Starred";
                    }
                    foreach (var tag in affectedTags)
                    {
                        ws.Cells[row, col++].Value = $"Old {tag.Label}";
                        ws.Cells[row, col++].Value = $"New {tag.Label}";
                    }

                    foreach (var note in notes)
                    {
                        row++;
                        col = 1;

                        ws.Cells[row, col++].Value = note.Name;
                        ws.Cells[row, col++].Value = note.TestId;
                        if (affectedNotes)
                        {
                            ws.Cells[row, col++].Value = note.OldNotes;
                            ws.Cells[row, col++].Value = note.NewNotes;
                        }
                        if (affectedStarred)
                        {
                            ws.Cells[row, col++].Value = note.OldStarred ? "*" : null;
                            ws.Cells[row, col++].Value = (note.NewStarred ?? note.OldStarred) ? "*" : null;
                        }
                        foreach (var tag in affectedTags)
                        {
                            ws.Cells[row, col++].Value = note.OldTags.Contains(tag.TagId) ? "." : null;
                            ws.Cells[row, col++].Value = note.NewTagsRemoved.Contains(tag.TagId) ? null : note.NewTags.Contains(tag.TagId) || note.OldTags.Contains(tag.TagId) ? "." : null;
                        }

                        progressData.Increment();
                    }
                });

                FileUtils.Save(p, fileName);
                FileUtils.LaunchFile(fileName);
            }
        }