コード例 #1
0
        public void Incluir(ProdutoInformation produto)
        {
            //conexao
            SqlConnection cn = new SqlConnection();

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");

                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "insert into Produtos(nome,preco,estoque) values (@nome,@preco,@estoque); select @@IDENTITY;";

                cmd.Parameters.AddWithValue("@nome", produto.Nome);
                cmd.Parameters.AddWithValue("@preco", produto.Preco);
                cmd.Parameters.AddWithValue("@estoque", produto.Estoque);

                cn.Open();
                produto.Codigo = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro: " + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #2
0
        public ArrayList ProdutosEmFalta()
        {
            SqlConnection cn = new SqlConnection();

            DTICrypto objCrypto = new DTICrypto();

            cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");

            SqlCommand cmd = new SqlCommand("Select * from Produtos Where Estoque < 10", cn);

            cn.Open();

            SqlDataReader dr    = cmd.ExecuteReader();
            ArrayList     lista = new ArrayList();

            while (dr.Read())
            {
                ProdutoInformation produto = new ProdutoInformation();
                produto.Codigo  = Convert.ToInt32(dr["codigo"]);
                produto.Nome    = dr["nome"].ToString();
                produto.Estoque = Convert.ToInt32(dr["estoque"]);
                produto.Preco   = Convert.ToDecimal(dr["preco"]);
                lista.Add(produto);
            }

            dr.Close();
            cn.Close();

            return(lista);
        }
コード例 #3
0
        public void Excluir(int codigo)
        {
            //conexao
            SqlConnection cn = new SqlConnection();

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");

                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandText = "delete from Produtos where codigo = " + codigo;

                cn.Open();
                int resultado = cmd.ExecuteNonQuery();
                if (resultado != 1)
                {
                    throw new Exception("Não foi possível excluir o produto " + codigo);
                }
            }
            catch (SqlException ex)
            {
                throw new Exception("SQL Erro:" + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #4
0
        public void Incluir(ClienteInformation cliente)
        {
            //conexao
            SqlConnection cn = new SqlConnection();

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");
                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;

                cmd.CommandType = CommandType.StoredProcedure;
                //nome da stored procedure
                cmd.CommandText = "insere_cliente";

                //parâmetros da stored procedure
                SqlParameter pcodigo = new SqlParameter("@codigo", SqlDbType.Int);
                pcodigo.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(pcodigo);
                SqlParameter pnome = new SqlParameter("@nome", SqlDbType.NVarChar, 100);
                pnome.Value = cliente.Nome;
                cmd.Parameters.Add(pnome);
                SqlParameter pemail = new SqlParameter("@email", SqlDbType.NVarChar, 100);
                pemail.Value = cliente.Email;
                cmd.Parameters.Add(pemail);
                SqlParameter ptelefone = new SqlParameter("@telefone", SqlDbType.NVarChar, 80);
                ptelefone.Value = cliente.Telefone;
                cmd.Parameters.Add(ptelefone);

                cn.Open();
                cmd.ExecuteNonQuery();

                cliente.Codigo = (Int32)cmd.Parameters["@codigo"].Value;
            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro:" + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #5
0
        public void Excluir(int codigo)
        {
            //conexao
            SqlConnection cn = new SqlConnection();

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");
                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;

                cmd.CommandType = CommandType.StoredProcedure;
                //nome da stored procedure
                cmd.CommandText = "exclui_cliente";

                //parâmetros da stored procedure
                SqlParameter pcodigo = new SqlParameter("@codigo", SqlDbType.Int);
                pcodigo.Value = codigo;
                cmd.Parameters.Add(pcodigo);

                cn.Open();

                int resultado = cmd.ExecuteNonQuery();
                if (resultado != 1)
                {
                    throw new Exception("Não foi possível excluir o cliente " + codigo);
                }
            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro:" + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #6
0
ファイル: UsersForm.cs プロジェクト: cadore/SysChef
        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            string cp = ((user)bdgUsers.Current).password;

            if (!String.IsNullOrEmpty(cp))
            {
                cp = new DTICrypto().Decifrar(cp, Util.keyCrypto);
            }
            ChangePasswordUserForm cpuf = new ChangePasswordUserForm(cp)
            {
                desk = this.desk
            };
            DialogResult rs = cpuf.ShowDialog();

            if (rs == DialogResult.OK)
            {
                this.NewPassword = new DTICrypto().Cifrar(cpuf.NewPassword, Util.keyCrypto);
            }
        }
コード例 #7
0
        public DataTable Listagem(string filtro)
        {
            DataTable tabela = new DataTable();
            string    strSql;

            if (filtro == "")
            {
                strSql = "select * from produtos";
            }
            else
            {
                strSql = "select * from produtos where nome like '%" + filtro + "%'";
            }

            DTICrypto objCrypto = new DTICrypto();

            SqlDataAdapter da = new SqlDataAdapter(strSql, objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008"));

            da.Fill(tabela);
            return(tabela);
        }
コード例 #8
0
        public DataTable Listagem(string filtro)
        {
            SqlConnection  cn = new SqlConnection();
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable      dt = new DataTable();


            try
            {
                DTICrypto myCrypto = new DTICrypto();
                cn.ConnectionString = myCrypto.Decifrar(Dados.StringDeConexao, "camacho2008").ToString();
                //adapter
                da.SelectCommand             = new SqlCommand();
                da.SelectCommand.CommandText = "seleciona_cliente";
                da.SelectCommand.Connection  = cn;
                da.SelectCommand.CommandType = CommandType.StoredProcedure;

                //parâmetros da stored procedure
                SqlParameter pfiltro;
                pfiltro       = da.SelectCommand.Parameters.Add("@filtro", SqlDbType.Text);
                pfiltro.Value = filtro;

                da.Fill(dt);

                return(dt);
            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro:" + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #9
0
        public void Alterar(ProdutoInformation produto)
        {
            //conexao
            SqlConnection cn = new SqlConnection();

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");

                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "update Produtos set nome = @nome, preco = @preco, estoque = @estoque where codigo = @codigo;";
                cmd.Parameters.AddWithValue("@codigo", produto.Codigo);
                cmd.Parameters.AddWithValue("@nome", produto.Nome);
                cmd.Parameters.AddWithValue("@preco", produto.Preco);
                cmd.Parameters.AddWithValue("@estoque", produto.Estoque);

                cn.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception("Servidor SQL Erro: " + ex.Number);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
コード例 #10
0
        private void btDecripta_Click(object sender, EventArgs e)
        {
            DTICrypto myCrypto = new DTICrypto();

            txtResultado.Text = myCrypto.Decifrar(txtEntrada.Text, txtPalavraSecreta.Text);
        }
コード例 #11
0
        public void Incluir(VendaInformation venda)
        {
            //conexao
            SqlConnection  cn = new SqlConnection();
            SqlTransaction t  = null;

            try
            {
                DTICrypto objCrypto = new DTICrypto();
                cn.ConnectionString = objCrypto.Decifrar(Dados.StringDeConexao, "camacho2008");
                //command
                SqlCommand cmd1 = new SqlCommand();
                cmd1.Connection  = cn;
                cmd1.CommandText = @"insert into vendas
                           (CodigoCliente, 
                            CodigoProduto,
                            Data,
                            Quantidade,
                            Faturado)
                            VALUES 
                            (@CodigoCliente, 
                            @CodigoProduto,
                            @Data,
                            @Quantidade,
                            @Faturado);select @@IDENTITY;";

                SqlCommand cmd2 = new SqlCommand();
                cmd2.Connection  = cn;
                cmd2.CommandText = @"Update Produtos
                            Set Estoque = Estoque - @Quantidade 
                            Where Codigo=@CodigoProduto";

                cn.Open();

                t = cn.BeginTransaction(IsolationLevel.Serializable);//default

                cmd1.Transaction = t;
                cmd2.Transaction = t;

                cmd1.Parameters.AddWithValue("@codigocliente", venda.CodigoCliente);
                cmd1.Parameters.AddWithValue("@codigoproduto", venda.CodigoProduto);
                cmd1.Parameters.AddWithValue("@data", venda.Data);
                cmd1.Parameters.AddWithValue("@quantidade", venda.Quantidade);
                cmd1.Parameters.AddWithValue("@faturado", venda.Faturado);

                cmd2.Parameters.AddWithValue("@quantidade", venda.Quantidade);
                cmd2.Parameters.AddWithValue("@codigoproduto", venda.CodigoProduto);

                venda.Codigo = Convert.ToInt32(cmd1.ExecuteScalar());
                cmd2.ExecuteNonQuery();

                t.Commit();
            }
            catch (Exception ex)
            {
                t.Rollback();
                throw new Exception("Servidor no Servidor:" + ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }