示例#1
0
        public void Atualizar(Comestivel comestivel)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = ConnectionString;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection = conexao;

            comando.CommandText = @"UPDATE produtos_comestiveis SET
nome = @NOME,
quantidade = @QUANTIDADE,
marca = @MARCA,
valor = @VALOR,
data_vencimento = @DATA_VENCIMENTO
WHERE id = @ID";

            comando.Parameters.AddWithValue("@NOME", comestivel.Nome);
            comando.Parameters.AddWithValue("@QUANTIDADE", comestivel.Quantidade);
            comando.Parameters.AddWithValue("@MARCA", comestivel.Marca);
            comando.Parameters.AddWithValue("@VALOR", comestivel.Valor);
            comando.Parameters.AddWithValue("@DATA_VENCIMENTO", comestivel.Vencimento.ToString("yyyy-MM-dd"));
            comando.Parameters.AddWithValue("@ID", comestivel.Id);

            comando.ExecuteNonQuery();
            conexao.Close();
        }
        public List <Comestivel> Obtertodos()
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaConexao;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = "SELECT * FROM comestiveis";

            DataTable tabela = new DataTable();

            tabela.Load(comando.ExecuteReader());

            List <Comestivel> comestiveis = new List <Comestivel>();

            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                DataRow    linha      = tabela.Rows[i];
                Comestivel comestivel = new Comestivel();
                comestivel.id             = Convert.ToInt32(linha["id"]);
                comestivel.nome           = linha["nome"].ToString();
                comestivel.valor          = Convert.ToDecimal(linha["valor"]);
                comestivel.dataVencimento = Convert.ToDateTime(linha["data_vencimento"]);
                comestivel.quantidade     = Convert.ToInt32(linha["quantidade"]);
                comestivel.marca          = linha["marca"].ToString();
                comestiveis.Add(comestivel);
                conexao.Close();
            }
            return(comestiveis);
        }
示例#3
0
        public Comestivel ObterPeloID(int id)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = ConnectionString;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = "SELECT * FROM produtos_comestiveis WHERE id = @ID";
            comando.Parameters.AddWithValue("@ID", id);

            DataTable dt = new DataTable();

            dt.Load(comando.ExecuteReader());
            conexao.Close();
            if (dt.Rows.Count == 1)
            {
                DataRow    row        = dt.Rows[0];
                Comestivel comestivel = new Comestivel();
                comestivel.Id         = Convert.ToInt32(row["id"]);
                comestivel.Nome       = row["nome"].ToString();
                comestivel.Marca      = row["marca"].ToString();
                comestivel.Valor      = Convert.ToDecimal(row["valor"]);
                comestivel.Vencimento = Convert.ToDateTime(row["data_vencimento"]);
                comestivel.Quantidade = Convert.ToInt32(row["quantidade"]);

                return(comestivel);
            }
            return(null);
        }
        public Comestivel ObterPeloId(int id)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaConexao;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = "SELECT * FROM comestiveis WHERE id = @ID";

            comando.Parameters.AddWithValue("@ID", id);

            DataTable dataTable = new DataTable();

            dataTable.Load(comando.ExecuteReader());
            conexao.Close();
            if (dataTable.Rows.Count == 1)
            {
                DataRow    linha      = dataTable.Rows[0];
                Comestivel comestivel = new Comestivel();
                comestivel.id             = Convert.ToInt32(linha["id"]);
                comestivel.nome           = linha["nome"].ToString();
                comestivel.valor          = Convert.ToDecimal(linha["valor"]);
                comestivel.dataVencimento = Convert.ToDateTime(linha["data_Vencimento"]);
                comestivel.quantidade     = Convert.ToInt32(linha["quantidade"]);
                comestivel.marca          = linha["marca"].ToString();
                return(comestivel);
            }
            return(null);
        }
示例#5
0
        public Comestivel ObterPeloId(int id)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaDeConexao;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = @"SELECT * FROM comestiveis 
            where id = @ID";
            comando.Parameters.AddWithValue("@ID", id);

            DataTable tabela = new DataTable();

            tabela.Load(comando.ExecuteReader());
            conexao.Close();
            if (tabela.Rows.Count == 1)
            {
                DataRow    linha      = tabela.Rows[0];
                Comestivel comestivel = new Comestivel();

                comestivel.Id             = Convert.ToInt32(linha["id"]);
                comestivel.Nome           = Convert.ToString(linha["nome"]);
                comestivel.Marca          = (linha["marca"].ToString());
                comestivel.Quantidade     = Convert.ToInt32(linha["quantidade"]);
                comestivel.DataVencimento = Convert.ToDateTime(linha["data_vencimento"]);
                comestivel.Preco          = Convert.ToDecimal(linha["preco"]);

                return(comestivel);
            }
            return(null);
        }
示例#6
0
        public void AtualizarRegistro(Comestivel comestivel)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaDeConexao;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = @"UPDATE comestiveis SET
            nome = @NOME,
            marca = @MARCA,
            preco = @PRECO,
            quantidade = @QUANTIDADE,
            data_vencimento = @DATA_VENCIMENTO
            WHERE id = @ID";

            comando.Parameters.AddWithValue("@NOME", comestivel.Nome);
            comando.Parameters.AddWithValue("@MARCA", comestivel.Marca);
            comando.Parameters.AddWithValue("@PRECO", comestivel.Preco);
            comando.Parameters.AddWithValue("@QUANTIDADE", comestivel.Quantidade);
            comando.Parameters.AddWithValue("@DATA_VENCIMENTO", comestivel.DataVencimento);
            comando.Parameters.AddWithValue("@ID", comestivel.Id);

            comando.ExecuteNonQuery();
            conexao.Close();
        }
示例#7
0
        public void Inserir(Comestivel comestivel)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaDeConexao;
            conexao.Open();


            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = @"INSERT INTO comestiveis
            (nome, preco, data_vencimento, quantidade, marca)

            VALUES
            (@NOME, @PRECO, @DATA_VENCIMENTO, @QUANTIDADE, @MARCA)";

            comando.Parameters.AddWithValue("@NOME", comestivel.Nome);
            comando.Parameters.AddWithValue("@PRECO", comestivel.Preco);
            comando.Parameters.AddWithValue("@DATA_VENCIMENTO", comestivel.DataVencimento);
            comando.Parameters.AddWithValue("@QUANTIDADE", comestivel.Quantidade);
            comando.Parameters.AddWithValue("@MARCA", comestivel.Marca);

            comando.ExecuteNonQuery();
            conexao.Close();
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text.Length == 0)
            {
                Comestivel comestivel = new Comestivel();
                comestivel.Nome           = txtNome.Text;
                comestivel.Valor          = Convert.ToDecimal(txtValor.Text);
                comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Value);
                comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
                comestivel.Marca          = txtMarca.Text;
                ComestivelRepository repository = new ComestivelRepository();
                repository.Inserir(comestivel);
                Close();
            }
            else
            {
                Comestivel comestivel = new Comestivel();
                comestivel.Id             = Convert.ToInt32(txtCodigo.Text);
                comestivel.Nome           = txtNome.Text;
                comestivel.Valor          = Convert.ToDecimal(txtValor.Text);
                comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Value);
                comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
                comestivel.Marca          = txtMarca.Text;
                ComestivelRepository repository = new ComestivelRepository();
                repository.Update(comestivel);

                MessageBox.Show("Editado com sucesso");
                Close();
            }
        }
示例#9
0
        public List <Comestivel> ObterTodos()
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = CadeiaDeConexao;
            connection.Open();

            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandText = "SELECT * FROM comestiveis";

            DataTable table = new DataTable();

            table.Load(command.ExecuteReader());

            List <Comestivel> comestiveis = new List <Comestivel>();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow    row        = table.Rows[i];
                Comestivel comestivel = new Comestivel();
                comestivel.Id             = Convert.ToInt32(row["id"]);
                comestivel.Nome           = row["nome"].ToString();
                comestivel.Valor          = Convert.ToDecimal(row["valor"]);
                comestivel.DataVencimento = Convert.ToDateTime(row["data_vencimento"]);
                comestivel.Quantidade     = Convert.ToInt32(row["quantidade"]);
                comestivel.Marca          = row["marca"].ToString();
                comestiveis.Add(comestivel);
            }
            connection.Close();
            return(comestiveis);
        }
        public void Atualizar(Comestivel comestivel)
        {
            SqlConnection conexao = new SqlConnection();

            conexao.ConnectionString = CadeiaConexao;
            conexao.Open();

            SqlCommand comando = new SqlCommand();

            comando.Connection  = conexao;
            comando.CommandText = @"UPDATE comestiveis SET 
nome = @NOME , 
valor = @VALOR , 
data_vencimento = @DATA_VENCIMENTO , 
quantidade = @QUANTIDADE , 
marca = @MARCA
WHERE id = @ID";

            comando.Parameters.AddWithValue("@NOME", comestivel.nome);
            comando.Parameters.AddWithValue("@VALOR", comestivel.valor);
            comando.Parameters.AddWithValue("@DATA_VENCIMENTO", comestivel.dataVencimento);
            comando.Parameters.AddWithValue("@QUANTIDADE", comestivel.quantidade);
            comando.Parameters.AddWithValue("@MARCA", comestivel.marca);
            comando.Parameters.AddWithValue("@ID", comestivel.id);
            comando.ExecuteNonQuery();
            conexao.Close();
        }
示例#11
0
 public FormEditarCadastroComestivel(Comestivel comestivel)
 {
     InitializeComponent();
     txtId.Text              = comestivel.Id.ToString();
     txtNome.Text            = comestivel.Nome;
     txtPreco.Text           = Convert.ToString(comestivel.Preco);
     dtpDataVencimento.Value = Convert.ToDateTime(comestivel.DataVencimento);
     txtQuantidade.Text      = comestivel.Quantidade.ToString();
     txtMarca.Text           = comestivel.Marca;
 }
示例#12
0
 public ComestivelEditar(Comestivel comestivel)
 {
     InitializeComponent();
     txtCodigo.Text         = comestivel.id.ToString();
     txtNome.Text           = comestivel.nome;
     txtValor.Text          = Convert.ToString(comestivel.valor);
     dtpDataVencimento.Text = comestivel.dataVencimento.ToString();
     txtQuantidade.Text     = Convert.ToString(comestivel.quantidade);
     txtMarca.Text          = comestivel.marca;
 }
示例#13
0
 public ProdutosComestiveisEditar(Comestivel comestivel)
 {
     InitializeComponent();
     txtNome.Text        = comestivel.Nome;
     txtMarca.Text       = comestivel.Marca;
     txtQuantidade.Text  = comestivel.Quantidade.ToString();
     txtValor.Text       = comestivel.Valor.ToString();
     dtpVencimento.Value = comestivel.Vencimento;
     lblId.Text          = comestivel.Id.ToString();
 }
 public CadastroComestiveis(Comestivel comestivel)
 {
     InitializeComponent();
     txtCodigo.Text          = comestivel.Id.ToString();
     txtNome.Text            = comestivel.Nome;
     txtValor.Text           = Convert.ToString(comestivel.Valor);
     dtpDataVencimento.Value = Convert.ToDateTime(comestivel.DataVencimento);
     txtQuantidade.Text      = Convert.ToString(comestivel.Quantidade);
     txtMarca.Text           = comestivel.Marca;
 }
示例#15
0
 public EditarComestivel(Comestivel comestivel)
 {
     InitializeComponent();
     txtId.Text             = comestivel.Id.ToString();
     txtNome.Text           = comestivel.Nome;
     mtdValor.Text          = Convert.ToString(comestivel.Valor);
     dtpDataVencimento.Text = comestivel.DataVencimento.ToString("yyyy-MM-dd");
     txtQuantidade.Text     = Convert.ToString(comestivel.Quantidade);
     txtMarca.Text          = comestivel.Marca;
 }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);

            ComestivelRepositorio repositorio = new ComestivelRepositorio();
            Comestivel            comestivel  = repositorio.ObterPeloId(id);

            ComestivelEditar comestivelEditar = new ComestivelEditar(comestivel);

            comestivelEditar.ShowDialog();
        }
        private void dgvListaComestiveis_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dgvListaComestiveis.CurrentRow.Cells[0].Value);

            RepositorioComestiveis repositorio = new RepositorioComestiveis();
            Comestivel             comestivel  = repositorio.ObterPeloId(id);

            CadastroAlterar cadastroAlterar = new CadastroAlterar(comestivel);

            cadastroAlterar.ShowDialog();
        }
示例#18
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);

            ComestiveisRepository repositorio = new ComestiveisRepository();
            Comestivel            comestivel  = repositorio.ObterPeloID(id);

            ProdutosComestiveisEditar editar = new ProdutosComestiveisEditar(comestivel);

            editar.ShowDialog();
        }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);

            ComestivelRepository repository = new ComestivelRepository();
            Comestivel           comestivel = repository.ObterPeloID(id);

            CadastroComestiveis cadastroComestiveis = new CadastroComestiveis(comestivel);

            cadastroComestiveis.ShowDialog();
        }
        public CadastroAlterar(Comestivel comesestivel)
        {
            InitializeComponent();

            txtNome.Text            = comesestivel.Nome;
            txtMarca.Text           = comesestivel.Marca;
            txtPreco.Text           = Convert.ToString(comesestivel.Preco);
            txtQuantidade.Text      = comesestivel.Quantidade.ToString();
            lblID.Text              = comesestivel.Id.ToString();
            dtpDataVencimento.Value = comesestivel.DataVencimento;
        }
        public EditarComestiveis(Comestivel comestivel)
        {
            InitializeComponent();

            txtNome.Text           = comestivel.Nome;
            txtValor.Text          = comestivel.Valor.ToString();
            dtpDataVencimento.Text = comestivel.DataVencimento.ToString();
            txtQuantidade.Text     = comestivel.Quantidade.ToString();
            txtMarca.Text          = comestivel.Marca.ToString();
            lblId.Text             = comestivel.Id.ToString();
        }
        private void AtualizarTabela()
        {
            ComestivelRepositorio repositorio = new ComestivelRepositorio();
            List <Comestivel>     comestiveis = repositorio.ObterTodos();

            dataGridView1.Rows.Clear();
            for (int i = 0; i < comestiveis.Count; i++)
            {
                Comestivel comestivel = comestiveis[i];
                dataGridView1.Rows.Add(new object[] { comestivel.Id, comestivel.Nome, comestivel.Preco, comestivel.DataVencimento, comestivel.Quantidade, comestivel.Marca });
            }
        }
示例#23
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            if (txtNome.Text.Length == 0)
            {
                MessageBox.Show("Digite no minimo 1 caracter no campo Nome");
                txtNome.Focus();
                return;
            }
            comestivel.Nome = txtNome.Text;

            try
            {
                comestivel.Valor = Convert.ToDouble(txtValor.Text);
                if (comestivel.Valor < 0)
                {
                    MessageBox.Show("Valor nao aceita número menor que 0");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Digite apenas Números no campo Valor");
                txtValor.Focus();
                return;
            }

            comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text);
            try
            {
                comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text);
            }
            catch
            {
                MessageBox.Show("Digite apenas Números inteiros no campo Quantidade");
                txtQuantidade.Focus();
                return;
            }

            if (txtMarca.Text.Length == 0)
            {
                MessageBox.Show("Digite no minimo 1 caracter no campo Marca");
                txtMarca.Focus();
                return;
            }
            comestivel.Marca = txtMarca.Text;

            ComestivelRepositorio repositorio = new ComestivelRepositorio();

            repositorio.Inserir(comestivel);
            Close();
        }
示例#24
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            comestivel.Id = Convert.ToInt32(txtId.Text);
            if (txtNome.Text.Length < 1)
            {
                MessageBox.Show("Registre o nome corretamente");
                txtNome.Focus();
                return;
            }
            comestivel.Nome = txtNome.Text;

            try
            {
                comestivel.Preco = Convert.ToDecimal(txtPreco.Text);
                if (comestivel.Preco < 0)
                {
                    MessageBox.Show("Números devem ser maior do que zero");
                }
            }
            catch
            {
                MessageBox.Show("Campo deve conter apenas números");
                txtPreco.Focus();
                return;
            }
            comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text);
            try
            {
                comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text);
                if (comestivel.Quantidade < 0)
                {
                    MessageBox.Show("Test");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Campo deve conter apenas números");
                txtQuantidade.Focus();
                return;
            }
            comestivel.Marca = txtMarca.Text;
            ComestivelRepositorio repositorio = new ComestivelRepositorio();

            repositorio.Atualizar(comestivel);
            MessageBox.Show("Editado com sucesso");
            Close();
        }
        private void btnSalvar_Click_1(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            comestivel.nome           = txtNome.Text;
            comestivel.valor          = Convert.ToDecimal(txtValor.Text);
            comestivel.dataVencimento = Convert.ToDateTime(dtpDataVencimento.Text);
            comestivel.quantidade     = Convert.ToInt32(txtQuantidade.Text);
            comestivel.marca          = txtMarca.Text;

            ComestiveisRepositorio repositorio = new ComestiveisRepositorio();

            repositorio.Inserir(comestivel);
            Close();
        }
        private void btnSalvarComestivel_Click(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            comestivel.Nome = txtNome.Text;

            comestivel.Valor          = Convert.ToDecimal(mtdValor.Text.Replace("R$", "").Replace(" ", ""));
            comestivel.DataVencimento = dtpDataVencimento.Value;
            comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
            comestivel.Marca          = txtMarca.Text;
            ComestivelRepositorio repositorio = new ComestivelRepositorio();

            repositorio.Inserir(comestivel);
            Close();
        }
示例#27
0
        public void AtualizarLista()
        {
            ComestiveisRepository repositorio = new ComestiveisRepository();
            List <Comestivel>     comestiveis = repositorio.ObterTodos();

            dataGridView1.Rows.Clear();

            for (int i = 0; i < comestiveis.Count; i++)
            {
                Comestivel comestivel = comestiveis[i];
                dataGridView1.Rows.Add(new object[] {
                    comestivel.Id, comestivel.Nome, comestivel.Marca, comestivel.Valor, comestivel.Quantidade, comestivel.Vencimento.ToString("dd/MM/yyyy")
                });
            }
        }
示例#28
0
        private void btnSalvarComestivel_Click(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            comestivel.Id             = Convert.ToInt32(txtId.Text);
            comestivel.Nome           = txtNome.Text;
            comestivel.Valor          = Convert.ToDecimal(mtdValor.Text.Replace("R$", "").Replace(" ", ""));
            comestivel.DataVencimento = Convert.ToDateTime(dtpDataVencimento.Text);
            comestivel.Quantidade     = Convert.ToInt32(txtQuantidade.Text);
            comestivel.Marca          = txtMarca.Text;
            ComestivelRepositorio repositorio = new ComestivelRepositorio();

            repositorio.Atualizar(comestivel);

            MessageBox.Show("Editado com sucesso");
        }
示例#29
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Comestivel comestivel = new Comestivel();

            comestivel.Nome       = txtNome.Text;
            comestivel.Marca      = txtMarca.Text;
            comestivel.Quantidade = Convert.ToInt32(txtQuantidade.Text);
            comestivel.Valor      = Convert.ToDecimal(txtValor.Text);
            comestivel.Vencimento = dtpVencimento.Value;

            ComestiveisRepository repositorio = new ComestiveisRepository();

            repositorio.Inserir(comestivel);

            MessageBox.Show("Cadastrado com sucesso!");
            Close();
        }
示例#30
0
        private void AtualizarTabela()
        {
            ComestiveisRepositorio repositorio = new ComestiveisRepositorio();
            List <Comestivel>      comestiveis = repositorio.Obtertodos();

            dataGridView1.Rows.Clear();
            for (int i = 0; i < comestiveis.Count; i++)
            {
                Comestivel comestivel = comestiveis[i];
                dataGridView1.Rows.Add(
                    new object[]
                {
                    comestivel.id, comestivel.nome, comestivel.valor, comestivel.quantidade, comestivel.marca
                }
                    );
            }
        }