private void btn_salvar_update_material_Click(object sender, RoutedEventArgs e) { try { MaterialController materialController = new MaterialController(); Material mat = materialController.BuscarPorId(Id); mat.MaterialNome = tb_update_nome_material.Text; mat.MaterialDesc = tb_update_desc_material.Text; mat.QuantidadeCadastrada = tb_update_qtde_material.Text; if (string.IsNullOrEmpty(tb_update_nome_material.Text)) { throw new NullReferenceException("O campo nome é obrigatório."); } if (string.IsNullOrEmpty(tb_update_desc_material.Text)) { throw new NullReferenceException("O campo descrição é obrigatório."); } if (string.IsNullOrEmpty(tb_update_qtde_material.Text)) { throw new NullReferenceException("O campo quantidade é obrigatório."); } materialController.Atualizar(mat); MessageBox.Show("Material salvo com sucesso!"); ListaMateriais dg_listarMateriais = new ListaMateriais(); dg_listarMateriais.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show("Erro ao atualizar material! (" + ex.Message + ")"); } }
private void btn_SalvarMaterial_Click(object sender, RoutedEventArgs e) { try { Material mat = new Material(); //mat.Local_Armazem = (Armazem)this.cbo_armazens.SelectedItem; mat.MaterialNome = tb_NomeMaterial.Text; mat.MaterialDesc = tb_MaterialDesc.Text; mat.QuantidadeCadastrada = txt_Quantidade_Cadastrada.Text; //var selectedItem = ((Armazem)cbo_armazens.SelectedItem).ArmazemId; //var item = cbo_armazens.SelectedItem as Armazem; //mat.Local_Armazem = cbo_armazens //mat.Local_Armazem = cbo_armazens.SelectedItem.ToString; //var selectedItem = cbo_armazens.SelectedItem; //ComboBoxItem cbi = cbo_armazens.ItemContainerGenerator.ContainerFromItem(selectedItem) as ComboBoxItem; MaterialController materialController = new MaterialController(); if (string.IsNullOrEmpty(tb_NomeMaterial.Text)) { throw new NullReferenceException("O campo nome é obrigatório."); } if (string.IsNullOrEmpty(tb_MaterialDesc.Text)) { throw new NullReferenceException("O campo descrição é obrigatório."); } if (string.IsNullOrEmpty(txt_Quantidade_Cadastrada.Text)) { throw new NullReferenceException("O campo quantidade é obrigatório."); } materialController.Adicionar(mat); MessageBox.Show("Material salvo com sucesso!"); this.Close(); ListaMateriais dg_ListaMateriais = new ListaMateriais(); dg_ListaMateriais.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show("Erro ao salvar o usuário (" + ex.Message + ")"); } }
private void btnDelete_Material_Click(object sender, RoutedEventArgs e) { int id = (dg_ListaMateriais.SelectedItem as Material).MaterialId; MaterialController matController = new MaterialController(); matController.Excluir(id); MessageBox.Show("Material excluido com Sucesso!"); ListaMateriais dg_listamateriais = new ListaMateriais(); dg_listamateriais.Show(); this.Close(); }