/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { // Commit any uncommitted changes. Changes in a bound text box are // normally committed to the data source only when the text box // loses focus. However, application bar buttons do not receive or // change focus because they are not Silverlight controls. CommitItemWithFocus(); if (!CheckParams()) { return; } // Save the account, category, and/or subcategory if necessary if (AccountTextBox.Visibility == Visibility.Visible) { if (!Datastore.Accounts.Contains(AccountTextBox.Text)) { Datastore.Accounts.Add(AccountTextBox.Text); } } if (CategoryTextBox.Visibility == Visibility.Visible) { if (!Datastore.MasterCategories().Contains(CategoryTextBox.Text)) { Datastore.AddCategory(CategoryTextBox.Text); } } if (SubCategoryTextBox.Visibility == Visibility.Visible) { String cat = CategoryTextBox.Text; if (CategoryListPicker.Visibility == Visibility.Visible) { cat = (String)CategoryListPicker.SelectedItem; } if (!Datastore.SubCategories(cat).Contains(SubCategoryTextBox.Text)) { Datastore.AddSubcategory(cat, SubCategoryTextBox.Text); } } SaveResult result = new SaveResult(); if (transactionToEdit != null) { result = Datastore.DeleteTransaction(transactionToEdit, delegate { MessageBox.Show(Constants.MSG_DELETE); }); if (!result.SaveSuccessful) { goto Failure; } } result = Datastore.AddTransaction(currentTransaction, delegate { MessageBox.Show(Constants.MSG_NO_SPACE); }); if (result.SaveSuccessful) { Microsoft.Phone.Shell.PhoneApplicationService.Current.State[Constants.SAVED_KEY_TRANSACTIONS] = true; NavigationService.GoBack(); } Failure: if (!result.SaveSuccessful) { string errorMessages = String.Join(Environment.NewLine + Environment.NewLine, result.ErrorMessages.ToArray()); if (!String.IsNullOrEmpty(errorMessages)) { MessageBox.Show(errorMessages, "Warning: Invalid Values", MessageBoxButton.OK); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { // Commit any uncommitted changes. Changes in a bound text box are // normally committed to the data source only when the text box // loses focus. However, application bar buttons do not receive or // change focus because they are not Silverlight controls. CommitItemWithFocus(); if (!CheckParams()) { return; } // Save the account(s) if necessary if (AccountTextBox.Visibility == Visibility.Visible && (!Datastore.Accounts.Contains(AccountTextBox.Text))) { Datastore.Accounts.Add(AccountTextBox.Text); } if (PayeeTextBox.Visibility == Visibility.Visible && (!Datastore.Accounts.Contains(PayeeTextBox.Text))) { Datastore.Accounts.Add(PayeeTextBox.Text); } // Now that everything has cleared, it's safe to modify the payee field currentTransfer.Payee = "Transfer : " + currentTransfer.Payee; SaveResult result = new SaveResult(); if (transferToEdit != null) { result = Datastore.DeleteTransaction(transferToEdit, delegate { MessageBox.Show(Constants.MSG_DELETE); }); if (!result.SaveSuccessful) { goto Failure; } } result = Datastore.AddTransaction(currentTransfer, delegate { MessageBox.Show(Constants.MSG_NO_SPACE); }); if (result.SaveSuccessful) { Microsoft.Phone.Shell.PhoneApplicationService.Current.State[Constants.SAVED_KEY_TRANSACTIONS] = true; } // Perform the same functions for the inverse of this transfer if (transferToEdit != null) { Transaction inverseTransferToEdit = transferToEdit.InverseTransfer(); result = Datastore.DeleteTransaction(inverseTransferToEdit, delegate { MessageBox.Show(Constants.MSG_DELETE); }); if (!result.SaveSuccessful) { goto Failure; } } Transaction inverseTransfer = currentTransfer.InverseTransfer(); result = Datastore.AddTransaction(inverseTransfer, delegate { MessageBox.Show(Constants.MSG_NO_SPACE); }); if (result.SaveSuccessful) { Microsoft.Phone.Shell.PhoneApplicationService.Current.State[Constants.SAVED_KEY_TRANSACTIONS] = true; NavigationService.GoBack(); } Failure: if (!result.SaveSuccessful) { string errorMessages = String.Join(Environment.NewLine + Environment.NewLine, result.ErrorMessages.ToArray()); if (!String.IsNullOrEmpty(errorMessages)) { MessageBox.Show(errorMessages, "Warning: Invalid Values", MessageBoxButton.OK); } } }