async public void OnDeleteClick(object sender, EventArgs e) { try { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { bool choice = await DisplayAlert("ALERT", "Are you sure you want to delete?", "Delete", "Cancel"); if (choice) { var deleteID = (ExpenseEntry)((sender as Button).CommandParameter); DataQuery.expenseSelect = "Select * From Totals "; DataQuery.expenseWhere = "Where Account_id = (Select top (1) ID from Account where AccountName = '" + deleteID.AccountName + "' and User_ID = '" + int.Parse(Preferences.Get("ExpenseT_UserID", "")) + "')"; ObservableCollection <Totals> totals = DataQuery.ExecuteAQuery <Totals>(); totals[0].Total -= (float)deleteID.ExpenseAmount; DataQuery.expenseSelect = "UPDATE [dbo].[Totals] SET [Total] = " + totals[0].Total.ToString("0.00"); DataQuery.expenseWhere = " Where ID = " + totals[0].ID; int count = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Select * From Totals "; DataQuery.expenseWhere = "Where Account_id = (Select top (1) ID from Account where AccountName = '" + deleteID.IncomeAccountName + "' and User_ID = '" + int.Parse(Preferences.Get("ExpenseT_UserID", "")) + "')"; totals = DataQuery.ExecuteAQuery <Totals>(); totals[0].Total -= (float)deleteID.ExpenseAmount; DataQuery.expenseSelect = "UPDATE [dbo].[Totals] SET [Total] = " + totals[0].Total.ToString("0.00"); DataQuery.expenseWhere = " Where ID = " + totals[0].ID; count = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From Expense"; DataQuery.expenseWhere = "where id = " + deleteID.ID; int results = DataQuery.AlterDataQuery(); focusFlag = true; var parent = this.Parent as NavigationPage; await parent.PopAsync(); } } else { DependencyService.Get <IToast>().Show("No Internet Connection."); } } catch (Exception ex) { DependencyService.Get <IToast>().Show(ex.Message); } }
async public void OnDeleteClick(object sender, EventArgs e) { try { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { bool choice = await DisplayAlert("ALERT", "This will delete all entries for this account. Are you sure you want to delete?", "Delete", "Cancel"); if (choice) { var deleteID = (Account)((sender as MenuItem).CommandParameter); if (deleteID.AccountType_ID == 1) { DataQuery.expenseSelect = "Delete From Expense"; DataQuery.expenseWhere = "where incomeaccount_id = " + deleteID.ID; int results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From Income"; DataQuery.expenseWhere = "where account_id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From totals"; DataQuery.expenseWhere = "where account_id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From Account"; DataQuery.expenseWhere = "where id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From Account"; DataQuery.expenseWhere = "where id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); } else if (deleteID.AccountType_ID == 2) { DataQuery.expenseSelect = "Delete From Expense"; DataQuery.expenseWhere = "where account_id = " + deleteID.ID; int results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From totals"; DataQuery.expenseWhere = "where account_id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); DataQuery.expenseSelect = "Delete From Account"; DataQuery.expenseWhere = "where id = " + deleteID.ID; results = DataQuery.AlterDataQuery(); } focusFlag = true; ExpIncAccPage_Appearing(sender, e); } } else { DependencyService.Get <IToast>().Show("No Internet Connection."); } } catch (Exception ex) { DependencyService.Get <IToast>().Show(ex.Message); } }