public void Alterar(ModelNotas nota) { try { if (string.IsNullOrEmpty(nota.Titulo)) { throw new Exception("Titulo da nota não informado!"); } if (string.IsNullOrEmpty(nota.Dados)) { throw new Exception("Dados da nota não informado!"); } if (nota.Id <= 0) { throw new Exception("Id da nota não informado!"); } var result = conn.Update(nota); StatusMessage = string.Format("{0} Registro(s) alterado(s) com sucesso!", result); } catch (Exception ex) { throw new Exception(string.Format("Erro: {0}", ex.Message)); } }
private void BtSalvar_Clicked(object sender, EventArgs e) { try { ModelNotas nota = new ModelNotas(); nota.Titulo = txtTitulo.Text; nota.Dados = txtDados.Text; nota.Favorito = swFavorito.IsToggled; ServicesDBNotas dbNotas = new ServicesDBNotas(App.DbPath); if (btSalvar.Text == "Inserir") { dbNotas.Inserir(nota); DisplayAlert("Resultado da operação", dbNotas.StatusMessage, "OK"); } else { //alterar nota.Id = Convert.ToInt32(txtCodigo.Text); dbNotas.Alterar(nota); DisplayAlert("Resultado da operação", dbNotas.StatusMessage, "OK"); } MasterDetailPage p = (MasterDetailPage)Application.Current.MainPage; p.Detail = new NavigationPage(new PageHome()); } catch (Exception ex) { DisplayAlert("Erro", ex.Message, "OK"); } }
public void Inserir(ModelNotas nota) { try { if (string.IsNullOrEmpty(nota.Titulo)) { throw new Exception("Titulo da nota não informado"); } if (string.IsNullOrEmpty(nota.Dados)) { throw new Exception("Dados da nota não informado(s)"); } int result = conn.Insert(nota); if (result != 0) { this.StatusMessage = string.Format("{0} registro(s) adicionado(s): [Nota: {1}]", result, nota.Titulo); } else { this.StatusMessage = string.Format("0 registro(s) adicionado(s): Informe o 'título' e os 'dados' da nota"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private void ListaNotas_ItemSelected(object sender, SelectedItemChangedEventArgs e) { ModelNotas nota = (ModelNotas)ListaNotas.SelectedItem; MasterDetailPage p = (MasterDetailPage)Application.Current.MainPage; p.Detail = new NavigationPage(new PageCadastrar(nota)); }
public PageCadastrar(ModelNotas nota) { InitializeComponent(); btSalvar.Text = "Alterar"; txtCodigo.IsVisible = true; btExcluir.IsVisible = true; txtCodigo.Text = nota.Id.ToString(); txtTitulo.Text = nota.Titulo; txtDados.Text = nota.Dados; swFavorito.IsToggled = nota.Favorito; }
public PageCadastrar(ModelNotas nota) { InitializeComponent(); button_pagecadastrar_salvar.Text = "Alterar"; entry_pagecadastrar_codigo.IsVisible = true; button_pagecadastrar_excluir.IsVisible = true; entry_pagecadastrar_codigo.Text = nota.Id.ToString(); entry_pagecadastrar_titulo.Text = nota.Titulo; editor_pagecadastrar_dados.Text = nota.Dados; switch_pagecadastrar_favorito.IsToggled = nota.Favorito; }
public ModelNotas GetNota(int id) { ModelNotas m = new ModelNotas(); try { m = conn.Table <ModelNotas>().First(n => n.Id == id); StatusMessage = "Encontrou a nota!"; } catch (Exception ex) { throw new Exception(string.Format("Erro {0}", ex.Message)); } return(m); }