private void Save() { try { if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Name)) { throw new Exception("All fields are required."); } PasswordItem pwd = new PasswordItem(); pwd.Username = Username; pwd.Password = Password; pwd.Name = Name; if (isEdit) { pwd.ID = existing.ID; ds.UpdatePassword(pwd); } else { ds.AddPassword(pwd); } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void LoadDatabase() { try { if (string.IsNullOrEmpty(DatabasePath)) { throw new Exception("Path cannot be empty."); } var exists = File.Exists(databasePath); dataStore = new DataStore(databasePath, !exists); QuoteService.Instance.SetDataStore(dataStore); //Store Properties.Settings.Default.LastPath = databasePath; Properties.Settings.Default.Save(); RaisePropertyChanged("Loaded"); RaisePropertyChanged("NotLoaded"); RefreshQuote(); QuoteService.Instance.StartTimer(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SaveTag() { try { if (SelectedCategory == null) { return; } if (SelectedTag == null) { StateManager.Instance.DataStore.AddTag(SelectedCategory.ID, TagName); TagName = null; } else { SelectedTag.Name = TagName; StateManager.Instance.DataStore.UpdateTag(SelectedTag); } LoadWindow(SelectedCategory.ID); Changed = true; } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Export() { try { if (string.IsNullOrEmpty(SavePath)) { throw new Exception("Save path not defined."); } else if (string.IsNullOrEmpty(SelectedExporter)) { throw new Exception("No exporter selected."); } else if (SelectedBook == null) { throw new Exception("No book selected."); } if (File.Exists(SavePath) && !MessageBoxFactory.ShowConfirmAsBool("Overwrite existing file?", "File Exists")) { return; } BaseExporter exporter = GetExporter(); exporter.Export(SelectedBook, SavePath); MessageBoxFactory.ShowInfo("Book has been exported to: " + SavePath, "Book Exported"); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SaveSettings() { try { if (string.IsNullOrEmpty(DbPath) || !Path.IsPathRooted(DbPath)) { throw new Exception("DB Path is empty or not valid."); } settings.DbPath = DbPath; settings.Username = Username; settings.Password = settingsWindow.PasswordBox.Password; settings.HideChrome = HideBrowser; settings.Save(); Changed = true; settingsWindow.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
/// <summary> /// Comment on a specific rant using the RantSelector /// </summary> private async void ViewSpecificRant() { var rantSelector = new IDInputWindow(IDInputWindowViewModel.Type.Rant); rantSelector.Owner = window; rantSelector.ShowDialog(); if (!string.IsNullOrEmpty(rantSelector.InputValue)) { try { Dtos.Rant rant = await api.GetRant(Convert.ToInt64(rantSelector.InputValue)); var dlg = new RantViewerWindow(new ViewModels.Rant(rant), api); dlg.Owner = window; dlg.ShowDialog(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } } }
private void Save() { try { TaskList newList = new TaskList(Name, Description, ConvertType(SelectedListType)); var type = ConvertType(SelectedListType); if (existing != null) { Workspace.API.UpdateList(existing, Name, Description, type); } else { Workspace.API.InsertList(Name, Description, type); } Cancelled = false; window.Close(); } catch (Exception e) { Workspace.Instance.RejectChanges(); MessageBoxFactory.ShowError(e); } }
private async void RefreshWatchlistItemsAsync() { IsRefreshing = false; await Task.Run(() => { try { //TODO: Disable Button RefreshWatchlistItems(false); App.Current.Dispatcher.Invoke(() => { LoadFromContext(); IsRefreshing = true; }); } catch (Exception e) { App.Current.Dispatcher.Invoke(() => { MessageBoxFactory.ShowError(e); IsRefreshing = true; }); } }); }
private async void ViewSpecificProfile() { try { var dlg = new IDInputWindow(IDInputWindowViewModel.Type.Profile); dlg.Owner = window; dlg.ShowDialog(); string username = dlg.InputValue; if (!string.IsNullOrEmpty(username)) { bool valid = await api.IsValidUser(username); if (valid) { ViewProfile(username); } else { throw new Exception(username + " does not exist."); } } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void DoSearch() { try { if (IsSearching) { ClearSearch(); } else { if (SearchFilter == null || string.IsNullOrEmpty(SearchFilter.Trim())) { throw new Exception("No search string entered"); } items.Clear(); List <IDataItem> results = DataManager.Instance().DataStore.Search(SearchFilter); foreach (var i in results) { Items.Add(new ItemViewModel(i, SVMLookup[i.GetSource()])); } } SortedView.Refresh(); IsSearching = !IsSearching; RefreshViewModel(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private async void RefreshRecentMoviesAsync() { IsRefreshing = false; await Task.Run(() => { try { var result = RefreshRecentlyAdded(); App.Current.Dispatcher.Invoke(() => { ShowRefreshStatus(result); LoadFromContext(); IsRefreshing = true; }); } catch (Exception e) { App.Current.Dispatcher.Invoke(() => { MessageBoxFactory.ShowError(e); IsRefreshing = true; }); } }); }
private void DeleteItem() { try { if (SelectedTask == null) { return; } else if (!MessageBoxFactory.ShowConfirmAsBool("Are you sure you want to delete this Task and ALL it's SubTasks?", "Confirm Delete", System.Windows.MessageBoxImage.Exclamation)) { return; } var parent = SelectedTask.Parent; int?pid = parent == null ? null : (int?)parent.TaskItemID; Workspace.API.DeleteTask(SelectedTask); TasksChanged(); if (pid != null) { ExpandAndSelect(tasks, pid.Value); } //Need to update list as well //TODO Duplicate: RefreshListsView(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (string.IsNullOrEmpty(Comment)) { throw new Exception("The comment cannot be empty."); } Data = new Core.Comment() { Text = Comment, }; //Returns a List and then API checks if it has ID, if yes update, else add if (IsEdit) { Data.CommentID = existing.CommentID; } else { Data.Created = DateTime.Now; } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void EditLogin() { try { if (SelectedLogin == null) { return; } try { var dlg = new EditLoginWindow(ds, passwordsMap, SelectedLogin); dlg.Owner = mainWindow; dlg.ShowDialog(); if (!dlg.Cancelled) { LoadLists(); } } catch (Exception e) { MessageBoxFactory.ShowError(e); } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
public void Load() { try { if (string.IsNullOrEmpty(WorkspacePath)) { throw new Exception("The path cannot be empty."); } string dbFile = GetDbFilePath(WorkspacePath); if (!Directory.Exists(WorkspacePath)) { Directory.CreateDirectory(WorkspacePath); } else { ValidateWorkspace(workspacePath); } LoadWorkspaceAsync(dbFile); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void AddNewToCurrent() { try { if (string.IsNullOrEmpty(NewTagName)) { return; } var exists = ds.GetTags(NewTagName); if (exists.Count > 0) { throw new Exception("The tag already exists."); } else { CurrentList.Add(new Tag() { TagName = NewTagName }); NewTagName = ""; } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
//TODO: Clean, figure out whether should do in GameBoard or here private void OnClick(int r, int c) { if (board.IsMine(r, c)) { MessageBoxFactory.ShowError("Lose", "You Lose"); InGame = false; } else { CellsLeft--; var button = buttonGrid[r, c]; if (button.IsEmpty) { for (int row = r - 1; row <= r + 1; row++) { for (int col = c - 1; col <= c + 1; col++) { GridButton gb = GetButton(row, col); if (gb != null && gb != button && !gb.Clicked && !gb.IsMine) { gb.Click(); //This is recursive } } } } CheckWin(); } }
private void ClearDatabase() { if (MessageBoxFactory.ShowConfirmAsBool("Are you sure you want to clear the database?", "Confirm Clear Database", MessageBoxImage.Exclamation)) { QuoteService.Instance.DataStore.ClearTables(); //TODO: Change all to use QuoteService } }
public static void Main() { Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Configure main logic: var factory = new MessageBoxFactory(); var mainForm = new DataGridViewMain(); var controller = new StandardController(mainForm, null); #if !DEBUG try { controller.LoadApp(); } catch (Exception a) { factory.ShowMessageBox(EMessageBox.Standard, string.Format(Resources.UnknownExceptionMessage, a.Message), Settings.Default.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #else controller.LoadApp(); #endif Application.Run(mainForm); }
private void Execute(object sender) { var selectedItem = SelectionManager.SelectedItem; if (selectedItem == null) { MessageBoxFactory.Show("No Item selected", "Export"); return; } var textLines = _applicableTypes[selectedItem.GetType()](selectedItem); if (textLines == null || !textLines.Any()) { MessageBoxFactory.Show("Unable to export inline table because it does not contain any rows", "Export"); return; } var saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "Specify file to export data to"; saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { System.IO.File.WriteAllLines(saveFileDialog1.FileName, textLines); MessageBoxFactory.Show("Successfuly exported " + textLines.Count() + " rows to file: " + saveFileDialog1.FileName, "Export"); } }
private void Save() { try { if (String.IsNullOrEmpty(Name)) { throw new Exception("Name is empty"); } if (IsEdit) { existing.Name = Name; } else { Topic t = new Topic() { Name = Name }; Util.DB.Topics.Add(t); } Util.DB.SaveChanges(); window.Close(); } catch (Exception e) { Util.DB.RejectChanges(); MessageBoxFactory.ShowError(e); } }
private void ClearLogs() { try { if (selectedTask == null) { return; } else if (!MessageBoxFactory.ShowConfirmAsBool("Delete all log entries?", "Confirm Delete")) { return; } foreach (var t in Workspace.Instance.TasksLog.Where(x => x.TaskID == SelectedTask.Data.TaskItemID)) { Workspace.Instance.TasksLog.Remove(t); } Workspace.Instance.SaveChanges(); UpdateCalendar(); } catch (Exception e) { } }
private void OpenDataStore() { try { if (string.IsNullOrEmpty(Path) || string.IsNullOrEmpty(pwdBox.Password)) { throw new Exception("A path and password are required."); } else if (!Path.EndsWith(Extension)) { Path += Extension; } IDataStore ds = new SQLiteDataStore(Path, pwdBox.Password); ds.Open(); DataStore = ds; pathHistory.AddItem(Path); settings.History = pathHistory.SerializeToString(); settings.Save(); Cancelled = false; openDatabaseWindow.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (!Enabled) { Hotkey.ClearHotkey(); } else { ModifierKeys mod = ToModifier(SelectedModifier); Key key = ToKey(Character); Hotkey hk = new Hotkey(mod, key); Hotkey.RegisterHotkey(hk, showDashboardCb); } Changed = true; closeWindowCb.Invoke(); } catch (Exception e) { MessageBoxFactory.ShowError(e); Changed = false; } }
private void DeleteQuote() { if (SelectedQuote != null && MessageBoxFactory.ShowConfirmAsBool("Are you sure you want to delete the selected quote?", "Confirm Delete")) { dataStore.DeleteQuote(SelectedQuote); LoadItem(); } }
private void SaveChange() { try { if (string.IsNullOrEmpty(Location)) { throw new RequiredFieldException("Location"); } else if (string.IsNullOrEmpty(OriginalText)) { throw new RequiredFieldException("OriginalText"); } else if (SelectedTopic == null) { throw new RequiredFieldException("Topic"); } if (IsEdit) { note.Location = Location; note.OriginalText = OriginalText; note.Published = IsPublished; //note.SubTopic = SelectedSubTopic; note.Topic = SelectedTopic; note.Updated = DateTime.Now; note.WriteUp = WriteUp; note.Notes = Notes; } else { Note note = new Note() { Book = book, Topic = SelectedTopic, Location = Location, OriginalText = OriginalText, //SubTopic = SelectedSubTopic, Created = DateTime.Now, Updated = DateTime.Now, WriteUp = WriteUp, Notes = Notes }; Workspace.Current.DB.Notes.Add(note); } Workspace.Current.DB.SaveChanges(); cancelled = false; window.Close(); } catch (Exception e) { Workspace.Current.DB.RejectChanges(); MessageBoxFactory.ShowError(e); } }
private void Save() { try { ds.SetDefaultRange(DefaultStoryRange); ds.SetDefaultFeed(DefaultFeed); AddedUsers = ds.SetFollowing(users); ds.SetUpdatesInterval(UpdateCheckInterval); if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { api.User.Login(Username, Password); } ds.SetHideUsername(!ShowUsername); ds.SetShowCreateTime(ShowCreateTime); ds.SetFilterOutRead(FilterOutRead); ds.SetLimits(ResultsLimit, MinScore, MaxPages); //Check DBPath if (ds.DBFolder != DBFolder) { ds.SetDBFolder(DBFolder); DatabaseChanged = true; } //Check/Save Login if (Username != null && Password != null) { var info = ds.GetLoginInfo(); if (info != null) { if (Username != info.Username || Password != info.Password) { ds.SetLogin(new LoginInfo(Username, Password)); LoginChanged = true; } } else { ds.SetLogin(new LoginInfo(Username, Password)); LoginChanged = true; } } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SendSong() { try { waClient.SendMessage(azClient.GetRandom()); } catch (Exception e) { MessageBoxFactory.ShowError(e, owner: window); } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (vm.HasUnsaved) { var ctnu = MessageBoxFactory.ShowConfirmAsBool("There are unsaved documents. Continue closing?", "Unsaved Documents", MessageBoxImage.Exclamation); if (!ctnu) { e.Cancel = true; } } }
private void SendRandomMessage() { try { waClient.SendRandomMessage(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }