private void DeleteExpenseCategory() { //блок инициирования валидации FlagCanValidateinputOrDeleteExpenseCategories = true; SetOrDeleteExpenseCategoryText += " "; int x1 = SetOrDeleteExpenseCategoryText.Length - 1; SetOrDeleteExpenseCategoryText = SetOrDeleteExpenseCategoryText.Substring(0, x1); FlagCanValidateinputOrDeleteExpenseCategories = false; //если все поля верны if (valideteResultInputOrDeleteExpenseCategories) { SqlConnectExpenseCategories con = new SqlConnectExpenseCategories(); int countOfExpenseCategories = con.TateExpenseCategoriesCount(); //если количество категорий пользователя не равно нулю if (countOfExpenseCategories > 0 && countOfExpenseCategories != -1) { //удаляем категорию из БД con.DeleteExpenseCategory(SetOrDeleteExpenseCategoryText); //обновляем категории на странице SetExpenceCategories(); //обновляем comboboxы на странице ExpenseCategorySource = new ObservableCollection <ExpenseCategory>(expenseCategoriesView); SetOrDeleteExpenseCategoryText = ""; } } valideteResultInputOrDeleteExpenseCategories = true; }
private void AddExpenseAmount() { //блок инициирования валидации FlagCanValidateExpenseaddAmount = true; ExpenseAmount += " "; valideteaddExpenseAmount = true; int x1 = ExpenseAmount.Length - 1; ExpenseAmount = ExpenseAmount.Substring(0, x1); ExpenseCategoryText += " "; x1 = ExpenseCategoryText.Length - 1; ExpenseCategoryText = ExpenseCategoryText.Substring(0, x1); ExpenseCategory += " "; x1 = ExpenseCategory.Length - 1; ExpenseCategory = ExpenseCategory.Substring(0, x1); ExpenseWallet2 += " "; x1 = ExpenseWallet2.Length - 1; ExpenseWallet2 = ExpenseWallet2.Substring(0, x1); FlagCanValidateExpenseaddAmount = false; //если все поля верны if (valideteaddExpenseAmount) { SqlConnectExpenseCategories spam = new SqlConnectExpenseCategories(); //транзакция которая отнимает значение у кашелька и если значение большн 0 то прибавляет в категорию, иначе rollback bool transResult = spam.UpdateCategoryAmount(Convert.ToInt32(ExpenseAmount), ExpenseCategoryText, ExpenseWallet2); //если транзакция прошла if (transResult) { //обновляем кошельки SetWallets(); //обновляем категории SetExpenceCategories(); SqlConnectExpenseCategoriesStats sqlConnectStats = new SqlConnectExpenseCategoriesStats(); //получаем индекс не пользовательской категории int idcategory = sqlConnectStats.GiveCategoryIndex(ExpenseCategory); if (idcategory != 0) { // записываем статистику sqlConnectStats.InsertWalletStats(idcategory, ExpenseWallet2, ExpenseCategoryText, Convert.ToInt32(ExpenseAmount)); } SqlConnectUserInfo connectUserInfo = new SqlConnectUserInfo(); //обновляем информацию о общих расходах connectUserInfo.UpdateTotalExpense(Convert.ToInt32(ExpenseAmount)); //выводим информацию о общих расходах int sum2 = connectUserInfo.Take_TotalExpense(); if (sum2 != -1) { TotalExpense = sum2.ToString(); } ExpenseAmount = ""; } else { FlagCanValidateExpenseaddAmount = true; tranzfalseflag = true; ExpenseAmount = ""; tranzfalseflag = false; FlagCanValidateExpenseaddAmount = false; } } valideteaddExpenseAmount = true; }
/// <summary> /// устанавливаю значения в категории /// </summary> private void SetExpenceCategories() { SqlConnectExpenseCategories spam = new SqlConnectExpenseCategories(); expenseCategoriesView = spam.TakeExpenseCategories(Convert.ToInt32(Properties.Settings.Default.UserId)); int count = expenseCategoriesView.Count(); if (count > 0) { IsVisibilityExpense1 = true; ExpenseTitle1 = expenseCategoriesView[0].Title; ExpenseAmount1 = expenseCategoriesView[0].Amount.ToString(); } else { IsVisibilityExpense1 = false; } count--; if (count > 0) { IsVisibilityExpense2 = true; ExpenseTitle2 = expenseCategoriesView[1].Title; ExpenseAmount2 = expenseCategoriesView[1].Amount.ToString(); } else { IsVisibilityExpense2 = false; } count--; if (count > 0) { IsVisibilityExpense3 = true; ExpenseTitle3 = expenseCategoriesView[2].Title; ExpenseAmount3 = expenseCategoriesView[2].Amount.ToString(); } else { IsVisibilityExpense3 = false; } count--; if (count > 0) { IsVisibilityExpense4 = true; ExpenseTitle4 = expenseCategoriesView[3].Title; ExpenseAmount4 = expenseCategoriesView[3].Amount.ToString(); } else { IsVisibilityExpense4 = false; } count--; if (count > 0) { IsVisibilityExpense5 = true; ExpenseTitle5 = expenseCategoriesView[4].Title; ExpenseAmount5 = expenseCategoriesView[4].Amount.ToString(); } else { IsVisibilityExpense5 = false; } count--; if (count > 0) { IsVisibilityExpense6 = true; ExpenseTitle6 = expenseCategoriesView[5].Title; ExpenseAmount6 = expenseCategoriesView[5].Amount.ToString(); } else { IsVisibilityExpense6 = false; } count--; if (count > 0) { IsVisibilityExpense7 = true; ExpenseTitle7 = expenseCategoriesView[6].Title; ExpenseAmount7 = expenseCategoriesView[6].Amount.ToString(); } else { IsVisibilityExpense7 = false; } count--; if (count > 0) { IsVisibilityExpense8 = true; ExpenseTitle8 = expenseCategoriesView[7].Title; ExpenseAmount8 = expenseCategoriesView[7].Amount.ToString(); } else { IsVisibilityExpense8 = false; } count--; }