private void btn_edit_salvar_Click(object sender, RoutedEventArgs e) { try { ArmazemController armController = new ArmazemController(); Armazem arm = armController.BuscarPorId(id); arm.Local = txt_edit_localArmazem.Text; arm.ArmazemDesc = txt_edir_descArmazem.Text; if (string.IsNullOrEmpty(txt_edit_localArmazem.Text)) { throw new NullReferenceException("O campo local é obrigatório."); } if (string.IsNullOrEmpty(txt_edir_descArmazem.Text)) { throw new NullReferenceException("O campo descrição é obrigatório."); } armController.Atualizar(arm); MessageBox.Show("Armazem atualizado!"); ListarArmazens dg_listarArmazens = new ListarArmazens(); dg_listarArmazens.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show("Erro ao atualizar armazem! (" + ex.Message + ")"); } }
private void btnDelete_Armazem_Click(object sender, RoutedEventArgs e) { int id = (dg_ListarArmazens.SelectedItem as Armazem).ArmazemId; ArmazemController armazemController = new ArmazemController(); armazemController.Excluir(id); }
private void btn_salvarArmazem_Click(object sender, RoutedEventArgs e) { try { Armazem arm = new Armazem(); arm.Local = tb_local.Text; arm.ArmazemDesc = tb_DescArmazem.Text; ArmazemController armazemController = new ArmazemController(); if (string.IsNullOrEmpty(tb_local.Text)) { throw new NullReferenceException("O campo nome é obrigatório."); } if (string.IsNullOrEmpty(tb_DescArmazem.Text)) { throw new NullReferenceException("O campo descrição é obrigatório."); } armazemController.Adicionar(arm); this.Close(); MessageBox.Show("Armazem salvo com sucesso!"); ListarArmazens dg_listarArmazens = new ListarArmazens(); dg_listarArmazens.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show("Erro ao salvar o armazem (" + ex.Message + ")"); } }
private void Window_Loaded_Armazem(object sender, RoutedEventArgs e) { ArmazemController armazemController = new ArmazemController(); dg_ListarArmazens.ItemsSource = armazemController.ListarTodos(); }