protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); if (State.ContainsKey("subTaskName")) { txtDescription.Text = State["subTaskName"].ToString(); } string idSubTask = NavigationContext.QueryString["idSubTask"]; //Caso seja uma edicao de subTask if (idSubTask != "") { using (MyLocalDatabase banco = new MyLocalDatabase(MyLocalDatabase.ConnectionString)) { //Busca no BD pelo id passado por parametro e seta o objeto de classe subTask subTask = banco.SubTasks.Where(o => o.Id.Equals(idSubTask)).First(); //Seta o txt da view txtDescription.Text = subTask.Description; //Verifica se o Alert esta true no BD if (subTask.Alert == 1) { btCheck.IsChecked = true; } } } App app = Application.Current as App; if (app.AuxParam != null && app.AuxParam.GetType() == typeof(Task)) { task = (Task)app.AuxParam; } }
private void btIcoDelete_Click(object sender, EventArgs e) { if (subTask != null) { if (MessageBox.Show("Deseja realmente remover?", "Confirmar", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { using (MyLocalDatabase banco = new MyLocalDatabase(MyLocalDatabase.ConnectionString)) { subTask = banco.SubTasks.Where(o => o.Id.Equals(subTask.Id)).First(); banco.SubTasks.DeleteOnSubmit(subTask); banco.SubmitChanges(); NavigationService.GoBack(); } } } else { NavigationService.GoBack(); } }
private void btSave_Click(object sender, RoutedEventArgs e) { if (txtDescription.Text != "") { using (MyLocalDatabase banco = new MyLocalDatabase(MyLocalDatabase.ConnectionString)) { int boolChecked = (Convert.ToBoolean(btCheck.IsChecked)) ? 1 : 0; if (subTask != null) { subTask.Description = txtDescription.Text; subTask.Alert = boolChecked; SubTask subTaskOld = banco.SubTasks.Where(o => o.Id.Equals(subTask.Id)).First(); subTaskOld.Description = subTask.Description; subTaskOld.Alert = subTask.Alert; } else { subTask = new SubTask() { Description = txtDescription.Text, Status = 0, Alert = boolChecked, TaskId = task.Id }; banco.SubTasks.InsertOnSubmit(subTask); } banco.SubmitChanges(); } NavigationService.GoBack(); } }