예제 #1
0
        public IEnumerable <int> GetToungeTwisters()
        {
            WordsGroup cat = _context.Groups.Where(c => c.Name == "Toungue twisters").FirstOrDefault();

            if (cat == null)
            {
                return(null);
            }
            return(cat.Words.Count == 0 ? null : cat.Words.Select(w => w.Id).ToList());
        }
예제 #2
0
        public IEnumerable <int> GetWordsWithImages(int cat, ServerData type)
        {
            switch (type)
            {
            case ServerData.Group:
                WordsGroup group = _context.Groups.Where(g => g.Id == cat).FirstOrDefault();
                if (group == null)
                {
                    return(null);
                }
                return(group.Words.Where(w => w.ImgPath != null).Select(w => w.Id).ToList());

            case ServerData.WordCategory:
                WordCategory category = _context.WordCategories.Where(g => g.Id == cat).FirstOrDefault();
                if (category == null)
                {
                    return(null);
                }
                return(category.Words.Where(w => w.ImgPath != null).Select(w => w.Id).ToList());

            default:
                return(null);
            }
        }
예제 #3
0
        public IEnumerable <int> GetItemData(int id, ServerData data, ServerData res)
        {
            switch (data)
            {
            case ServerData.Video:
                Video video = _context.Videos.Where(u => u.Id == id).FirstOrDefault();
                if (video == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.VideoCategory:
                    return(video.Categories.Select(c => c.Id));

                case ServerData.Word:
                    return(video.Words.Count == 0 ? null : video.Words.Select(w => w.Id));
                }
                break;

            case ServerData.Book:
                Book book = _context.Books.Where(u => u.Id == id).FirstOrDefault();
                if (book == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Author:
                    return(book.Authors.Select(c => c.Id));

                case ServerData.BookCategory:
                    return(book.Categories.Select(c => c.Id));

                case ServerData.Word:
                    return(book.Words.Count == 0? null: book.Words.Select(w => w.Id));
                }
                break;

            case ServerData.Grammar:
                Grammar grammar = _context.Grammars.Where(u => u.Id == id).FirstOrDefault();
                if (grammar == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Rule:
                    return(grammar.Rules.Count == 0? null : grammar.Rules.Select(c => c.Id));

                case ServerData.GrammarExample:
                    return(grammar.Examples.Count == 0? null : grammar.Examples.Select(c => c.Id));

                case ServerData.GrammarException:
                    return(grammar.Exceptions.Count == 0 ? null : grammar.Exceptions.Select(w => w.Id));
                }
                break;

            case ServerData.Word:
                Word word = _context.Dictionary.Where(u => u.Id == id).FirstOrDefault();
                if (word == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.WordCategory:
                    IEnumerable <int> lst = _context.WordCategories.Where(w => w.Words.Contains(_context.Dictionary.Where(v => v.Id == word.Id).FirstOrDefault())).Select(c => c.Id);
                    return(lst);

                case ServerData.Translation:
                    return(word.Translations.Select(c => c.Id));

                case ServerData.Definition:
                    return(word.Descriptions.Select(c => c.Id));

                case ServerData.Group:
                    return(word.Groups.Select(c => c.Id));

                case ServerData.Example:
                    return(_context.Examples.Where(e => e.WordID == word.Id).Select(e => e.Id));
                }
                break;

            case ServerData.Author:
                Author author = _context.Authors.Where(u => u.Id == id).FirstOrDefault();
                if (author == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Book:
                    return(author.Books.Select(c => c.Id));
                }
                break;

            case ServerData.BookCategory:
                BookCategory bc = _context.BookCategories.Where(u => u.Id == id).FirstOrDefault();
                if (bc == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Book:
                    return(bc.Books.Select(c => c.Id));
                }
                break;

            case ServerData.VideoCategory:
                VideoCategory vc = _context.VideoCategories.Where(u => u.Id == id).FirstOrDefault();
                if (vc == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Video:
                    return(vc.Videos.Select(c => c.Id));
                }
                break;

            case ServerData.WordCategory:
                WordCategory wc = _context.WordCategories.Where(u => u.Id == id).FirstOrDefault();
                if (wc == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Word:
                    return(wc.Words.Select(c => c.Id));
                }
                break;

            case ServerData.Group:
                WordsGroup wg = _context.Groups.Where(u => u.Id == id).FirstOrDefault();
                if (wg == null)
                {
                    return(null);
                }
                switch (res)
                {
                case ServerData.Word:
                    return(wg.Words.Select(c => c.Id));
                }
                break;
            }
            return(null);
        }
예제 #4
0
        // Get data properties depending on the type.
        public string GetItemProperty(int id, ServerData data, PropertyData property)
        {
            switch (data)
            {
            case ServerData.Video:
                Video video = _context.Videos.Where(u => u.Id == id).FirstOrDefault();
                if (video == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(video.Name);

                case PropertyData.Description:
                    return(video.Description);

                case PropertyData.Path:
                    return(video.Path);

                case PropertyData.Imgpath:
                    return(video.ImgPath);

                case PropertyData.SubPath:
                    return(video.SubPath);

                case PropertyData.Year:
                    return(video.Year == null? null: video.Year.ToString());

                case PropertyData.Created:
                    return(video.Created.ToLongDateString());
                }
                break;

            case ServerData.Book:
                Book book = _context.Books.Where(u => u.Id == id).FirstOrDefault();
                if (book == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(book.Name);

                case PropertyData.Description:
                    return(book.Description);

                case PropertyData.Path:
                    return(book.Path);

                case PropertyData.Imgpath:
                    return(book.ImgPath);

                case PropertyData.Year:
                    return(book.Year == null ? null : book.Year.ToString());

                case PropertyData.Created:
                    return(book.Created.ToLongDateString());
                }
                break;

            case ServerData.Game:
                Game game = _context.Games.Where(u => u.Id == id).FirstOrDefault();
                if (game == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(game.Name);

                case PropertyData.Description:
                    return(game.Description);
                }
                break;

            case ServerData.Grammar:
                Grammar grammar = _context.Grammars.Where(u => u.Id == id).FirstOrDefault();
                if (grammar == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(grammar.Title);

                case PropertyData.Description:
                    return(grammar.Description);
                }
                break;

            case ServerData.Rule:
                Entities.Rule rule = _context.Rules.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(rule?.Name);
                }
                break;

            case ServerData.GrammarExample:
                GrammarExample ge = _context.GrammarExamples.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(ge?.Name);
                }
                break;

            case ServerData.GrammarException:
                GrammarException gex = _context.Exceptions.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(gex?.Name);
                }
                break;

            case ServerData.Role:
                Role role = _context.Roles.Where(u => u.Id == id).FirstOrDefault();
                switch (property)
                {
                case PropertyData.Name:
                    return(role?.Name);
                }
                break;

            case ServerData.User:
                User user = _context.Users.Where(u => u.Id == id).FirstOrDefault();
                if (user == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                case PropertyData.Login:
                    return(user.Username);

                case PropertyData.Imgpath:
                    return(user.Avatar);

                case PropertyData.Password:
                    return(user.Password);

                case PropertyData.ScoreCount:
                    int score = 0;
                    foreach (Score item in _context.Scores.Where(s => s.UserID == user.Id).ToList())
                    {
                        score += item.ScoreCount;
                    }
                    return(score.ToString());

                case PropertyData.Level:
                    return(user.Level.ToString());

                case PropertyData.Role:
                    return(user.RoleID.ToString());

                case PropertyData.RolesName:
                    return(_context.Roles.Where(r => r.Id == user.RoleID).FirstOrDefault()?.Name);
                }
                break;

            case ServerData.VideoCategory:
                VideoCategory videoCategory = _context.VideoCategories.Where(u => u.Id == id).FirstOrDefault();
                if (videoCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(videoCategory.Name);
                }
                break;

            case ServerData.BookCategory:
                BookCategory bookCategory = _context.BookCategories.Where(u => u.Id == id).FirstOrDefault();
                if (bookCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(bookCategory.Name);
                }
                break;

            case ServerData.Word:
                Word word = _context.Dictionary.Where(u => u.Id == id).FirstOrDefault();
                if (word == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(word.Name);

                case PropertyData.Imgpath:
                    return(word.ImgPath);

                case PropertyData.PluralForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PluralForm);

                case PropertyData.PastForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PastForm);

                case PropertyData.PastThForm:
                    return(_context.WordForms.Where(f => f.Id == word.FormID).FirstOrDefault()?.PastThForm);

                case PropertyData.Transcription:
                    return(word.TranscriptionID == null? null: word.TranscriptionID.ToString());
                }
                break;

            case ServerData.WordForm:
                WordForm wordForm = _context.WordForms.Where(u => u.Id == id).FirstOrDefault();
                if (wordForm == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.PastForm:
                    return(wordForm.PastForm);

                case PropertyData.PastThForm:
                    return(wordForm.PastThForm);

                case PropertyData.PluralForm:
                    return(wordForm.PluralForm);
                }
                break;

            case ServerData.Group:
                WordsGroup group = _context.Groups.Where(u => u.Id == id).FirstOrDefault();
                if (group == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(group.Name);
                }
                break;

            case ServerData.WordCategory:
                WordCategory wordCategory = _context.WordCategories.Where(u => u.Id == id).FirstOrDefault();
                if (wordCategory == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(wordCategory.Name);

                case PropertyData.Abbreviation:
                    return(wordCategory.Abbreviation);
                }
                break;

            case ServerData.Transcription:
                Transcription transcription = _context.Transcriptions.Where(u => u.Id == id).FirstOrDefault();
                if (transcription == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.British:
                    return(transcription.British);

                case PropertyData.Canadian:
                    return(transcription.Canadian);

                case PropertyData.Australian:
                    return(transcription.Australian);

                case PropertyData.American:
                    return(transcription.American);
                }
                break;

            case ServerData.Translation:
                Translation translation = _context.Translations.Where(u => u.Id == id).FirstOrDefault();
                if (translation == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(translation.Name);
                }
                break;

            case ServerData.Definition:
                Definition definition = _context.Definitions.Where(u => u.Id == id).FirstOrDefault();
                if (definition == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(definition.Name);
                }
                break;

            case ServerData.Author:
                Author author = _context.Authors.Where(u => u.Id == id).FirstOrDefault();
                if (author == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(author.Name);

                case PropertyData.Surname:
                    return(author.Surname);
                }
                break;

            case ServerData.Example:
                Example example = _context.Examples.Where(u => u.Id == id).FirstOrDefault();
                if (example == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Name:
                    return(example.Name);
                }
                break;

            case ServerData.VideoBookmark:
                VideoBookmark videoBookmark = _context.VideoBookmarks.Where(u => u.Id == id).FirstOrDefault();
                if (videoBookmark == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Position:
                    return(videoBookmark.Position.ToString());
                }
                break;

            case ServerData.Bookmark:
                Bookmark bookmark = _context.Bookmarks.Where(u => u.Id == id).FirstOrDefault();
                if (bookmark == null)
                {
                    return(null);
                }
                switch (property)
                {
                case PropertyData.Position:
                    return(bookmark.Position.ToString());
                }
                break;
            }

            return(null);
        }
예제 #5
0
        public void EditData(int id, string changes, ServerData data, PropertyData property)
        {
            switch (data)
            {
            case ServerData.User:
                User user = _context.Users.Where(u => u.Id == id).FirstOrDefault();
                if (user == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    user.Username = changes;
                    break;

                case PropertyData.Role:
                    user.Roles = _context.Roles.Where(r => r.Name == changes).FirstOrDefault();
                    break;

                case PropertyData.Imgpath:
                    user.Avatar = changes;
                    break;

                case PropertyData.Password:
                    user.Password = changes;
                    break;

                case PropertyData.Level:
                    user.Level = Convert.ToInt32(changes);
                    break;
                }
                break;

            case ServerData.Word:
                Word word = _context.Dictionary.Where(w => w.Id == id).FirstOrDefault();
                if (word == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    word.Name = changes;
                    break;

                case PropertyData.Imgpath:
                    word.ImgPath = changes;
                    break;

                case PropertyData.PastForm:
                    word.Form.PastForm = changes;
                    break;

                case PropertyData.PastThForm:
                    word.Form.PastThForm = changes;
                    break;

                case PropertyData.PluralForm:
                    word.Form.PluralForm = changes;
                    break;

                case PropertyData.British:
                    word.Transcriptions.British = changes;
                    break;

                case PropertyData.American:
                    word.Transcriptions.American = changes;
                    break;

                case PropertyData.Australian:
                    word.Transcriptions.Australian = changes;
                    break;

                case PropertyData.Canadian:
                    word.Transcriptions.Canadian = changes;
                    break;
                }
                break;

            case ServerData.Grammar:
                Grammar grammar = _context.Grammars.Where(w => w.Id == id).FirstOrDefault();
                if (grammar == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    grammar.Title = changes;
                    break;

                case PropertyData.Description:
                    grammar.Description = changes;
                    break;
                }
                break;

            case ServerData.Book:
                Book book = _context.Books.Where(u => u.Id == id).FirstOrDefault();
                if (book == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    book.Name = changes;
                    break;

                case PropertyData.Description:
                    book.Description = changes;
                    break;

                case PropertyData.Path:
                    if (File.Exists($@"Books\{book.Path}") && book.IsAbsolute == false)
                    {
                        File.Delete($@"Books\{book.Path}");
                    }
                    book.Path = changes;
                    break;

                case PropertyData.Imgpath:
                    book.ImgPath = changes;
                    break;

                case PropertyData.Year:
                    if (changes == null)
                    {
                        book.Year = null;
                    }
                    else
                    {
                        book.Year = Convert.ToInt32(changes);
                    }
                    break;

                case PropertyData.IsAbsolute:
                    book.IsAbsolute = changes != null;
                    break;
                }
                break;

            case ServerData.Video:
                Video video = _context.Videos.Where(u => u.Id == id).FirstOrDefault();
                if (video == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    video.Name = changes;
                    break;

                case PropertyData.Description:
                    video.Description = changes;
                    break;

                case PropertyData.Path:
                    if (File.Exists($@"Books\{video.Path}") && video.IsAbsolute == false)
                    {
                        File.Delete($@"Books\{video.Path}");
                    }
                    video.Path = changes;
                    break;

                case PropertyData.SubPath:
                    video.SubPath = changes;
                    break;

                case PropertyData.Imgpath:
                    video.ImgPath = changes;
                    break;

                case PropertyData.Year:
                    if (changes == null)
                    {
                        video.Year = null;
                    }
                    else
                    {
                        video.Year = Convert.ToInt32(changes);
                    }
                    break;

                case PropertyData.IsAbsolute:
                    video.IsAbsolute = changes != null;
                    break;
                }
                break;

            case ServerData.Author:
                Author author = _context.Authors.Where(u => u.Id == id).FirstOrDefault();
                if (author == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    author.Name = changes;
                    break;

                case PropertyData.Surname:
                    author.Surname = changes;
                    break;
                }
                break;

            case ServerData.BookCategory:
                BookCategory bc = _context.BookCategories.Where(u => u.Id == id).FirstOrDefault();
                if (bc == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    bc.Name = changes;
                    break;
                }
                break;

            case ServerData.VideoCategory:
                VideoCategory vc = _context.VideoCategories.Where(u => u.Id == id).FirstOrDefault();
                if (vc == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    vc.Name = changes;
                    break;
                }
                break;

            case ServerData.WordCategory:
                WordCategory wc = _context.WordCategories.Where(u => u.Id == id).FirstOrDefault();
                if (wc == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    wc.Name = changes;
                    break;

                case PropertyData.Abbreviation:
                    wc.Abbreviation = changes;
                    break;
                }
                break;

            case ServerData.Group:
                WordsGroup wg = _context.Groups.Where(u => u.Id == id).FirstOrDefault();
                if (wg == null)
                {
                    return;
                }
                switch (property)
                {
                case PropertyData.Name:
                    wg.Name = changes;
                    break;
                }
                break;
            }
            _context.SaveChanges();
        }
예제 #6
0
        public void AddItemData(int item, int cat, ServerData data)
        {
            switch (data)
            {
            case ServerData.VideoCategory:
                if (_context.Videos.Where(u => u.Id == item).FirstOrDefault() == null || _context.VideoCategories.Where(u => u.Id == cat).FirstOrDefault() == null)
                {
                    return;
                }
                _context.Videos.Where(u => u.Id == item).FirstOrDefault().Categories.Add(_context.VideoCategories.Where(u => u.Id == cat).FirstOrDefault());
                break;

            case ServerData.BookCategory:
                Book         book         = (_context.Books.Where(u => u.Id == item).FirstOrDefault());
                BookCategory bookCategory = _context.BookCategories.Where(u => u.Id == cat).FirstOrDefault();
                if (book == null || bookCategory == null)
                {
                    return;
                }
                book.Categories.Add(bookCategory);
                break;

            case ServerData.WordCategory:
                Word         word      = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                WordCategory wCategory = _context.WordCategories.Where(u => u.Id == cat).FirstOrDefault();
                if (word == null || wCategory == null)
                {
                    return;
                }
                word.Categories.Add(wCategory);
                break;

            case ServerData.Translation:
                Word        wordT = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Translation tr    = _context.Translations.Where(u => u.Id == cat).FirstOrDefault();
                if (wordT == null || tr == null)
                {
                    return;
                }
                wordT.Translations.Add(tr);
                break;

            case ServerData.Definition:
                Word       wordD = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Definition def   = _context.Definitions.Where(u => u.Id == cat).FirstOrDefault();
                if (wordD == null || def == null)
                {
                    return;
                }
                wordD.Descriptions.Add(def);
                break;

            case ServerData.Group:
                Word       wordG = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                WordsGroup gr    = _context.Groups.Where(u => u.Id == cat).FirstOrDefault();
                if (wordG == null || gr == null)
                {
                    return;
                }
                wordG.Groups.Add(gr);
                break;

            case ServerData.Example:
                Word    wordE = (_context.Dictionary.Where(u => u.Id == item).FirstOrDefault());
                Example ex    = _context.Examples.Where(u => u.Id == cat).FirstOrDefault();
                if (wordE == null || ex == null)
                {
                    return;
                }
                ex.WordID = wordE.Id;
                break;

            case ServerData.GrammarExample:
                Grammar        grammar = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                GrammarExample example = _context.GrammarExamples.Where(u => u.Id == cat).FirstOrDefault();
                if (grammar == null || example == null)
                {
                    return;
                }
                grammar.Examples.Add(example);
                break;

            case ServerData.GrammarException:
                Grammar          grammarE  = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                GrammarException exception = _context.Exceptions.Where(u => u.Id == cat).FirstOrDefault();
                if (grammarE == null || exception == null)
                {
                    return;
                }
                grammarE.Exceptions.Add(exception);
                break;

            case ServerData.Rule:
                Grammar       grammarR = (_context.Grammars.Where(u => u.Id == item).FirstOrDefault());
                Entities.Rule rule     = _context.Rules.Where(u => u.Id == cat).FirstOrDefault();
                if (grammarR == null || rule == null)
                {
                    return;
                }
                grammarR.Rules.Add(rule);
                break;
            }
            _context.SaveChanges();
        }
예제 #7
0
        private void SaveGroup(object sender, RoutedEventArgs e)
        {
            // first do validations that do not reqire db access

            string grpName = groupNameTxt.Text;

            if (grpName.Length == 0)
            {
                MessageBox.Show("חובה להזין שם לקבוצה");
                groupNameTxt.Focus();
                return;
            }
            ParagraphReader  reader = new ParagraphReader(); // use paragraph read to remove all "non-word" chars and split into words
            HashSet <string> items  = new HashSet <string>(reader.ReadWords(wordsListTxt.Text));

            if (items.Count == 0)
            {
                MessageBox.Show("חובה להזין מילים לקבוצה");
                wordsListTxt.SelectAll();
                return;
            }
            else if (items.Count > WordsGroup.MaxItemsInGroup)
            {
                MessageBox.Show(string.Format("לא ניתן להזין יותר מ-{0} מילים בקבוצה", WordsGroup.MaxItemsInGroup));
                return;
            }
            try
            {
                using (KnessetContext context = new KnessetContext())
                {
                    // now do validations that do reqire db access
                    WordsGroup existing = context.WordsGroups.Find(grpName);
                    if (existing != null)
                    {
                        MessageBox.Show("כבר קיימת קבוצה עם שם זה");
                        return;
                    }

                    // input is OK, save the new group, if a word is not in the words relation add it
                    // (we might define groups before loading protocols)
                    WordsGroup group = new WordsGroup {
                        g_name = grpName
                    };
                    context.WordsGroups.Add(group);

                    foreach (var wordStr in items)
                    {
                        Word wordObj = context.Words.Find(wordStr);
                        if (wordObj == null)
                        {
                            wordObj = new Word {
                                word = wordStr
                            };
                            context.Words.Add(wordObj);
                        }
                        context.WordInGroups.Add(new WordInGroup {
                            wordsGroup = group, WordObj = wordObj
                        });
                    }
                    context.SaveChanges(); // commit all changes to DB
                }
                DialogResult = true;       // can be used by parent window - marks success
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }