private void accountNameUpdatingTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { _pressedEnter = true; DataRowView currentRow = (DataRowView)AccountDataGrid.CurrentItem; string afterEdit = ((TextBox)(e.Source)).Text; Helper.updateDBValue("Accounts", new KeyValuePair <string, object>("AccountName", afterEdit), new Dictionary <string, string>() { { "AccountId", (string)currentRow["AccountId"] } }); } else { _pressedEnter = false; if (e.Key == Key.Escape) { CategoryDataGrid.Focus(); } } }
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e) { CategoryDataGrid.Focus(); }
private void budgetUpdatingTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Source.GetType() != typeof(TextBox)) { return; } DataRowView currentRow = (DataRowView)((TextBox)e.Source).DataContext; if ((string)currentRow["CategoryId"] != "") { if (e.Key == Key.Enter) { _pressedEnter = true; //Budget value string afterEdit = ((TextBox)(e.Source)).Text; decimal afterEditDecimal = 0; decimal updatedValue; try { if (!Decimal.TryParse(afterEdit, out afterEditDecimal)) { MessageBox.Show(this, "Budget amount must be a decimal.", "Budget Amount Error", MessageBoxButton.OK); var currentRowIndexError = CategoryDataGrid.Items.IndexOf(CategoryDataGrid.CurrentItem); _categoriesTable.Rows[currentRowIndexError]["Budgeted"] = _beforeBudgetEdit; selectedRowGoalText.Visibility = Visibility.Hidden; selectedRowGoalValue.Text = ""; _beforeBudgetEdit = ""; CategoryDataGrid.Focus(); return; } } catch (Exception) { MessageBox.Show(this, "Budget amount must be a decimal.", "Budget Amount Error", MessageBoxButton.OK); var currentRowIndexError = CategoryDataGrid.Items.IndexOf(CategoryDataGrid.CurrentItem); _categoriesTable.Rows[currentRowIndexError]["Budgeted"] = _beforeBudgetEdit; selectedRowGoalText.Visibility = Visibility.Hidden; selectedRowGoalValue.Text = ""; _beforeBudgetEdit = ""; CategoryDataGrid.Focus(); return; } updatedValue = Convert.ToDecimal(_beforeBudgetEdit) + afterEditDecimal; Helper.updateDBValue("CategoryMonths", new KeyValuePair <string, object>("Budget", updatedValue), new Dictionary <string, string>() { { "CategoryId", (string)currentRow["CategoryId"] }, { "Month", MonthDisplayed } }); var currentRowIndex = CategoryDataGrid.Items.IndexOf(CategoryDataGrid.CurrentItem); _categoriesTable.Rows[currentRowIndex]["Budgeted"] = updatedValue.ToString("0.00"); _beforeBudgetEdit = ""; //Accumulated value var accumulatedTotal = Convert.ToDecimal(_categoriesTable.Rows[currentRowIndex]["Accumulated"].ToString().Replace("$", "")) + afterEditDecimal; Helper.updateDBValue("Categories", new KeyValuePair <string, object>("RunningTotal", accumulatedTotal.ToString("0.00")), new Dictionary <string, string>() { { "CategoryId", (string)currentRow["CategoryId"] } }); _categoriesTable.Rows[currentRowIndex]["Accumulated"] = "$" + (accumulatedTotal).ToString("0.00"); for (int i = currentRowIndex - 1; i >= 0; i--) { if ((string)_categoriesTable.Rows[i]["CategoryId"] == "") { var groupBudgetTotal = Convert.ToDecimal(_categoriesTable.Rows[i]["Budgeted"].ToString().Replace("$", "")); _categoriesTable.Rows[i]["Budgeted"] = "$" + (groupBudgetTotal + afterEditDecimal).ToString("0.00"); var groupAccumulatedTotal = Convert.ToDecimal(_categoriesTable.Rows[i]["Accumulated"].ToString().Replace("$", "")); _categoriesTable.Rows[i]["Accumulated"] = "$" + (groupAccumulatedTotal + afterEditDecimal).ToString("0.00"); break; } } //ToBeBudgeted value var toBeBudgeted = Convert.ToDecimal(toBeBudgetedValueText.Text.Replace("$", "")) - afterEditDecimal; Helper.updateDBValue("GlobalValues", new KeyValuePair <string, object>("Value", toBeBudgeted.ToString("0.00")), new Dictionary <string, string>() { { "Name", "ToBeBudgeted" } }); toBeBudgetedValueText.Text = "$" + toBeBudgeted.ToString("0.00"); } else { _pressedEnter = false; if (e.Key == Key.Escape) { CategoryDataGrid.Focus(); } } } }