Beispiel #1
0
        public int editaProduto(Produto_DTO USU)
        {
            try
            {
                SqlConnection CON = new SqlConnection();
                CON.ConnectionString = Properties.Settings.Default.CST;
                SqlCommand CM = new SqlCommand();
                CM.CommandType = System.Data.CommandType.Text;

                CM.CommandText = "UPDATE tb_produtos SET nome_produtos=@nome_produtos," +
                                 "nome_fabrica=@nome_fabrica," + "Endereco=@Endereco "
                                 + "WHERE cod_produtos=@cod_produtos";

                CM.Parameters.Add("nome_produtos", System.Data.SqlDbType.VarChar).Value = USU.nome_produtos;
                CM.Parameters.Add("nome_fabrica", System.Data.SqlDbType.VarChar).Value  = USU.nome_fabrica;
                CM.Parameters.Add("Endereco", System.Data.SqlDbType.VarChar).Value      = USU.Endereco;
                CM.Parameters.Add("cod_produtos", System.Data.SqlDbType.VarChar).Value  = USU.cod_produtos;
                CM.Connection = CON;

                CON.Open();
                int qtd = CM.ExecuteNonQuery();
                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public int insereProduto(Produto_DTO USU)
        {
            try
            {
                SqlConnection CON = new SqlConnection();
                CON.ConnectionString = Properties.Settings.Default.CST;
                SqlCommand CM = new SqlCommand();
                CM.CommandType = System.Data.CommandType.Text;
                CM.CommandText = "INSERT INTO tb_produtos (nome_produtos, nome_fabrica, Endereco)"
                                 + "VALUES (@nome_produtos, @nome_fabrica, @Endereco)";

                CM.Parameters.Add("nome_produtos", System.Data.SqlDbType.VarChar).Value = USU.nome_produtos;
                CM.Parameters.Add("nome_fabrica", System.Data.SqlDbType.VarChar).Value  = USU.nome_fabrica;
                CM.Parameters.Add("Endereco", System.Data.SqlDbType.VarChar).Value      = USU.Endereco;

                CM.Connection = CON;
                CON.Open();
                int qtd = CM.ExecuteNonQuery();
                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public IList <Produto_DTO> cargaProduto()
        {
            try
            {
                SqlConnection CON = new SqlConnection();
                CON.ConnectionString = Properties.Settings.Default.CST;
                SqlCommand CM = new SqlCommand();
                CM.CommandType = System.Data.CommandType.Text;
                CM.CommandText = "SELECT*FROM tb_produtos";
                CM.Connection  = CON;
                SqlDataReader       ER;
                IList <Produto_DTO> listProdutoDTO = new List <Produto_DTO>();
                CON.Open();
                ER = CM.ExecuteReader();
                if (ER.HasRows)
                {
                    while (ER.Read())
                    {
                        Produto_DTO usu = new Produto_DTO();

                        usu.cod_produtos  = Convert.ToInt32(ER["cod_produtos"]);
                        usu.nome_produtos = Convert.ToString(ER["nome_produtos"]);
                        usu.nome_fabrica  = Convert.ToString(ER["nome_fabrica"]);
                        usu.Endereco      = Convert.ToString(ER["Endereco"]);

                        listProdutoDTO.Add(usu);
                    }
                }
                return(listProdutoDTO);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        private void btnCadastro_Click(object sender, EventArgs e)
        {
            Produto_DTO obj = new Produto_DTO();

            obj.Codigo  = textBox9.Text;
            obj.Nome    = textBox10.Text;
            obj.Preco   = textBox11.Text;
            obj.Unidade = textBox13.Text + " " + comboBox1.Text;
            MessageBox.Show(obj.Unidade);
            File.Copy(ImgOrigem, ImgDestino);
        }
Beispiel #5
0
 public int deletaProduto(Produto_DTO USU)
 {
     try
     {
         return(new Produto_DAL().deletaProduto(USU));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
 public int insereProduto(Produto_DTO USU)
 {
     try
     {
         return(new Produto_DAL().insereProduto(USU));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #7
0
        public int deletaProduto(Produto_DTO USU)
        {
            try
            {
                SqlConnection CON = new SqlConnection();
                CON.ConnectionString = Properties.Settings.Default.CST;
                SqlCommand CM = new SqlCommand();
                CM.CommandType = System.Data.CommandType.Text;
                CM.CommandText = "DELETE tb_produtos WHERE cod_produtos = @cod_produtos";

                CM.Parameters.Add("cod_produtos", System.Data.SqlDbType.Int).Value = USU.cod_produtos;
                CM.Connection = CON;
                CON.Open();
                int qtd = CM.ExecuteNonQuery();

                return(qtd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            if (modo == "novo")
            {
                try
                {
                    Produto_DTO USU = new Produto_DTO();
                    USU.nome_produtos = txtNome_Produto.Text;
                    USU.nome_fabrica  = txtNome_Fabrica.Text;
                    USU.Endereco      = txtEndereco.Text;

                    int x = new Produto_BLL().insereProduto(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Gravado com Sucesso!");
                    }
                    carregaGrid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }
            if (modo == "editar")
            {
                try
                {
                    if (codPodSelecionado < 0)
                    {
                        MessageBox.Show("Selecione um usuario antes de prosseguir");
                        return;
                    }

                    Produto_DTO USU = new Produto_DTO();
                    USU.cod_produtos  = codPodSelecionado;
                    USU.nome_produtos = txtNome_Produto.Text;
                    USU.nome_fabrica  = txtNome_Fabrica.Text;
                    USU.Endereco      = txtEndereco.Text;

                    int x = new Produto_BLL().editaProduto(USU);

                    if (x > 0)
                    {
                        MessageBox.Show("Alterado com Sucesso!");
                    }

                    carregaGrid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }
            if (modo == "deletar")
            {
                try
                {
                    if (codPodSelecionado < 0)
                    {
                        //lblMensagem.Text = "Selecione um usuario antes de prosseguir";
                        return;
                    }
                    Produto_DTO USU = new Produto_DTO();
                    USU.cod_produtos = codPodSelecionado;
                    int x = new Produto_BLL().deletaProduto(USU);
                    if (x > 0)
                    {
                        MessageBox.Show("Excluido com Sucesso!");
                    }
                    /*Recarrega o Grid após os dados serem gravados*/
                    carregaGrid();
                    limpar_campos();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro inesperado" + ex.Message);
                }
            }

            modo = " ";
        }