コード例 #1
0
        public void Cadastrar(
            int IdUsuario
            , int IdProduto
            , int IdEndereco
            , DateTime DataEntrega)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();

                cmd = new SqlCommand("INSERT INTO Pedido(IdUsuario, IdProduto, IdEndereco, DataDeEntrega) VALUES " +
                                     "(@IdUsuario, @IdProduto, @IdEndereco, @DataDeEntrega);", con);

                cmd.Parameters.AddWithValue("@IdUsuario", IdUsuario);
                cmd.Parameters.AddWithValue("@IdProduto", IdProduto);
                cmd.Parameters.AddWithValue("@IdEndereco", IdEndereco);
                cmd.Parameters.AddWithValue("@DataDeEntrega", DataEntrega.ToString("yyyy/MM/dd").Replace("/", "-"));


                if (cmd.ExecuteNonQuery() == 1)
                {
                    valor = 1;
                }
                else
                {
                    valor = 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
コード例 #2
0
        public void Login(string Usuario, string SenhaCriptografada)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();
                string result = "";
                cmd = new SqlCommand("SELECT Senha FROM Usuario WHERE Usuario = @Usuario;", con);
                cmd.Parameters.AddWithValue("@Usuario", Usuario);

                SqlDataReader resultado = cmd.ExecuteReader();

                while (resultado.Read())
                {
                    result = resultado["Senha"].ToString();
                }
                if (result == SenhaCriptografada)
                {
                    Validar = true;
                }
                else
                {
                    Validar = false;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
コード例 #3
0
        public void AtualizarStatus(int IdEntrega, string StatusEntrega)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();

                cmd = new SqlCommand("UPDATE Entregas SET StatusEntrega = @StatusEntrega WHERE IdEntregas = @IdEntrega;", con);

                cmd.Parameters.AddWithValue("@IdEntrega", IdEntrega);
                cmd.Parameters.AddWithValue("@StatusEntrega", StatusEntrega);

                if (cmd.ExecuteNonQuery() == 1)
                {
                    valor = 1;
                }
                else
                {
                    valor = 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
コード例 #4
0
        public string BuscaRole(string Usuario)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();

                cmd = new SqlCommand("SELECT NomeRole FROM Role r INNER JOIN Usuario u ON u.IdRole = r.IdRole WHERE u.Usuario = @Usuario;", con);

                cmd.Parameters.AddWithValue("@Usuario", Usuario);

                SqlDataReader resultado = cmd.ExecuteReader();
                var           result    = "";
                while (resultado.Read())
                {
                    result = resultado["NomeRole"].ToString();
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
コード例 #5
0
            public static ListaProduto RetornarProduto()
            {
                try
                {
                    con = ConnectionFactory.getConnection();
                    con.Open();

                    comando = "SELECT IdProduto, p.Tipo, p.Fragilidade, Descricao, Quantidade, Valor, Peso, TamanhoX, TamanhoY, TamanhoZ" +
                              " FROM Produto INNER JOIN Tipo_Produto p ON Produto.IdTipo_Produto = p.IdTipo_Produto" +
                              " ORDER BY p.Tipo;";

                    XmlSerializer ser = new XmlSerializer(typeof(ListaProduto));
                    list = new ListaProduto();

                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandText = comando.ToString();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                list.Items.Add(new Produto
                                {
                                    IdProduto   = rdr.GetInt32(0),
                                    Tipo        = rdr.GetString(1),
                                    Fragilidade = rdr.GetString(2),
                                    Descricao   = rdr.GetString(3),
                                    Quantidade  = rdr.GetInt32(4),
                                    Valor       = rdr.GetDouble(5),
                                    Peso        = rdr.GetDouble(6),
                                    TamanhoX    = rdr.GetDouble(7),
                                    TamanhoY    = rdr.GetDouble(8),
                                    TamanhoZ    = rdr.GetDouble(9),
                                });
                            }
                        }
                        cmd.Dispose();
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    try
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }

                    try
                    {
                        if (rdr != null)
                        {
                            rdr.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                    try
                    {
                        if (cmd != null)
                        {
                            cmd.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
            }
コード例 #6
0
            public static ListaPedido RetornarPedido()
            {
                try
                {
                    con = ConnectionFactory.getConnection();
                    con.Open();

                    comando = "SELECT IdPedido, u.Nome AS Nome_Solicitante, p.Descricao AS Nome_Produto, e.CEP, e.Estado, e.Cidade, e.Bairro, e.Logradouro, e.Numero, e.Complemento, DataDeEntrega " +
                              "FROM Pedido pe INNER JOIN Produto p  ON pe.IdProduto = p.IdProduto  " +
                              "INNER JOIN Endereco e ON e.IdEndereco = pe.IdEndereco " +
                              "INNER JOIN Usuario u ON pe.IdUsuario = u.IdUsuario  " +
                              "ORDER BY DataDeEntrega; ";

                    XmlSerializer ser = new XmlSerializer(typeof(ListaPedido));
                    list = new ListaPedido();

                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandText = comando.ToString();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                list.Items.Add(new Pedido
                                {
                                    IdPedido        = rdr.GetInt32(0),
                                    NomeSolicitante = rdr.GetString(1),
                                    NomeProduto     = rdr.GetString(2),
                                    CEP             = rdr.GetString(3),
                                    Estado          = rdr.GetString(4),
                                    Cidade          = rdr.GetString(5),
                                    Bairro          = rdr.GetString(6),
                                    Logradouro      = rdr.GetString(7),
                                    Numero          = rdr.GetInt32(8),
                                    Complemento     = rdr.GetString(9),
                                    DataDeEntrega   = rdr.GetDateTime(10).ToString("dd/MM/yyyy").Replace("-", "/"),
                                });
                            }
                        }
                        cmd.Dispose();
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    try
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }

                    try
                    {
                        if (rdr != null)
                        {
                            rdr.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                    try
                    {
                        if (cmd != null)
                        {
                            cmd.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
            }
コード例 #7
0
            public static ListaCliente RetornarCliente()
            {
                try
                {
                    con = ConnectionFactory.getConnection();
                    con.Open();

                    comando = "SELECT Nome, CPF, Usuario, Telefone, NomeRole  " +
                              "FROM Usuario INNER JOIN Role ON Usuario.IdRole = Role.IdRole " +
                              "ORDER BY NomeRole;";

                    XmlSerializer ser = new XmlSerializer(typeof(ListaCliente));
                    list = new ListaCliente();

                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandText = comando.ToString();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                list.Items.Add(new Cliente
                                {
                                    Nome     = rdr.GetString(0),
                                    CPF      = rdr.GetString(1),
                                    Usuario  = rdr.GetString(2),
                                    Telefone = rdr.GetString(3),
                                    Role     = rdr.GetString(4)
                                });
                            }
                        }
                        cmd.Dispose();
                    }

                    return(list);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
                finally
                {
                    try
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }

                    try
                    {
                        if (rdr != null)
                        {
                            rdr.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                    try
                    {
                        if (cmd != null)
                        {
                            cmd.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.ToString());
                    }
                }
            }
コード例 #8
0
        public void Cadastrar(
            int IdTipo_Produto
            , string Descricao
            , int Quantidade
            , double Valor
            , double Peso
            , double TamanhoX
            , double TamanhoY
            , double TamanhoZ)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();

                cmd = new SqlCommand("INSERT INTO Produto(IdTipo_Produto, Descricao, Quantidade, Valor, Peso, TamanhoX, TamanhoY, TamanhoZ) VALUES " +
                                     "(@IdTipo_Produto, @Descricao, @Quantidade, @Valor, @Peso, @TamanhoX, @TamanhoY, @TamanhoZ);", con);

                cmd.Parameters.AddWithValue("@IdTipo_Produto", IdTipo_Produto);
                cmd.Parameters.AddWithValue("@Descricao", Descricao);
                cmd.Parameters.AddWithValue("@Quantidade", Quantidade);
                cmd.Parameters.AddWithValue("@Valor", Valor.ToString().Replace(',', '.'));
                cmd.Parameters.AddWithValue("@Peso", Peso.ToString().Replace(',', '.'));
                cmd.Parameters.AddWithValue("@TamanhoX", TamanhoX.ToString().Replace(',', '.'));
                cmd.Parameters.AddWithValue("@TamanhoY", TamanhoY.ToString().Replace(',', '.'));
                cmd.Parameters.AddWithValue("@TamanhoZ", TamanhoZ.ToString().Replace(',', '.'));


                if (cmd.ExecuteNonQuery() == 1)
                {
                    valor = 1;
                }
                else
                {
                    valor = 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
コード例 #9
0
        public void Cadastrar(
            string Nome
            , string CPF
            , string Usuario
            , string Senha
            , string Telefone
            , int IdRole)
        {
            try
            {
                con = ConnectionFactory.getConnection();
                con.Open();

                cmd = new SqlCommand("INSERT INTO Usuario(Nome, CPF, Usuario, Senha, Telefone, IdRole) VALUES " +
                                     "(@Nome, @CPF, @Usuario, @Senha, @Telefone, @IdRole);", con);

                cmd.Parameters.AddWithValue("@Nome", Nome);
                cmd.Parameters.AddWithValue("@CPF", CPF);
                cmd.Parameters.AddWithValue("@Usuario", Usuario);
                cmd.Parameters.AddWithValue("@Senha", Senha);
                cmd.Parameters.AddWithValue("@Telefone", Telefone);
                cmd.Parameters.AddWithValue("@IdRole", IdRole);


                if (cmd.ExecuteNonQuery() == 1)
                {
                    valor = 1;
                }
                else
                {
                    valor = 0;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                try
                {
                    if (con != null)
                    {
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }

                try
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }