コード例 #1
0
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Tem certeza?", "Pergunta", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         int indiceExcluido = lbxLista.SelectedIndex;
         lbxLista.SelectedIndex = 0;
         lbxLista.Items.RemoveAt(indiceExcluido);
         List <Produto> produtosList = new List <Produto>();
         foreach (Produto produto in lbxLista.Items)
         {
             produtosList.Add(produto);
         }
         ManipuladorDeArquivos.EscreverArquivo(produtosList);
         CarregarListaProdutos();
         LimparCampos();
     }
 }
コード例 #2
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                Produto produto = new Produto
                {
                    Descricao  = txbDescricao.Text,
                    Preco      = txbPreco.Text.Replace(',', '.'),
                    Quantidade = Convert.ToInt32(txbQuantidade.Text)
                };
                List <Produto> produtoList = new List <Produto>();
                foreach (Produto produtos in lbxLista.Items)
                {
                    produtoList.Add(produtos);
                }

                if (acao == FluxoEnum.INCLUIR)
                {
                    produtoList.Add(produto);
                }
                if (acao == FluxoEnum.ALTERAR)
                {
                    int indice = lbxLista.SelectedIndex;
                    produtoList.RemoveAt(indice);
                    produtoList.Insert(indice, produto);
                }
                ManipuladorDeArquivos.EscreverArquivo(produtoList);
                CarregarListaProdutos();
                EstadoBotoesIncluirAlterarExcluir(true);
                EstadoBotesSalvarCancelar(false);
                LimparCampos();
                EstadoCampos(false);
            }
            catch (FormatException fx)
            {
                MessageBox.Show("Formato Inválido: " + fx);
            }
        }
コード例 #3
0
 private void CarregarListaProdutos()
 {
     lbxLista.Items.Clear();
     lbxLista.Items.AddRange(ManipuladorDeArquivos.LerArquivo().ToArray());
 }