public bool VerificaTipoUsuario(String login)
        {
            bool retorno = true;

            try{
                FactoryConnection conn = new FactoryConnection();

                String query = "select tipoUsuario from Usuario where Login='******' AND tipoUsuario = '1'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();


                if (reader.Read())
                {
                    conn.FecharConnecxao();
                    retorno = true;
                }
                else
                {
                    conn.FecharConnecxao();
                    retorno = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }

            return(retorno);
        }
        public bool Autenticar(String usuario, String senha)
        {
            bool retorno = false;

            try{
                FactoryConnection conn = new FactoryConnection();

                String query = "select Login, Senha, Ativo from Usuario where Login='******' and Senha='" + senha + "' and Ativo=1 ";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                if (reader.Read())
                {
                    retorno = true;
                }
                else
                {
                    retorno = false;
                }

                conn.FecharConnecxao();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }

            return(retorno);
        }
        public Usuario BuscarUsuario(String login)
        {
            FactoryConnection conn = new FactoryConnection();
            Usuario           usu  = new Usuario();

            try
            {
                String query = "SELECT * FROM Usuario WHERE login = '******'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                while (reader.Read())
                {
                    usu.Nome     = (String)reader["nome"];
                    usu.Login    = (String)reader["login"];
                    usu.Senha    = (String)reader["senha"];
                    usu.isGestor = (int)reader["TipoUsuario"];
                }
                reader.Close();
                conn.FecharConnecxao();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }

            return(usu);
        }
        public void CadastrarFuncionario(Funcionario funionario)
        {
            if (this.VerificaFunc(funionario.Cpf))
            {
                MessageBox.Show("Já existe Funcionário cadastrado com este CPF!");
            }
            else
            {
                FactoryConnection conn = new FactoryConnection();
                try
                {
                    String query = "insert into Funcionario (Nome, cpf, telefone, endereco, porcentagem, datanascimento, ativo) values" +
                                   "('" + funionario.Nome + "', '" + funionario.Cpf + "', '" + funionario.Telefone +
                                   "', '" + funionario.Endereco + "', '" + funionario.Porcentagem + "', '" + funionario.DataNascimento + "', '" + funionario.Ativo + "')";

                    SqlCommand    comand = new SqlCommand(query, conn.AbrirConnexao());
                    SqlDataReader reader = comand.ExecuteReader();
                    MessageBox.Show("Cadastro Efetuado com sucesso !!");
                }
                catch (Exception e)
                {
                    MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
                }
                finally
                {
                    conn.FecharConnecxao();
                }
            }
        }
Beispiel #5
0
        public Cliente BuscarCliente(String cpf)
        {
            FactoryConnection conn = new FactoryConnection();
            Cliente           cli  = new Cliente();

            try
            {
                String query = "SELECT * FROM Cliente WHERE cpf = '" + cpf + "'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                while (reader.Read())
                {
                    cli.Nome           = (String)reader["nome"];
                    cli.Cpf            = (String)reader["cpf"];
                    cli.DataNascimento = (String)reader["dataNascimento"];
                    cli.Email          = (String)reader["email"];
                    cli.Endereco       = (String)reader["endereco"];
                    cli.Telefone       = (String)reader["telefone"];
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }

            return(cli);
        }
        public Servico BuscarServico(int idServico)
        {
            FactoryConnection conn = new FactoryConnection();
            Servico           serv = new Servico();

            try
            {
                String query = "SELECT * FROM Servico WHERE IdServico = '" + idServico + "' and ativo = 1";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                while (reader.Read())
                {
                    serv.IdServico = (int)reader["IdServico"];
                    serv.Descricao = (String)reader["Descricao"];
                    serv.Valor     = (Decimal)reader["Valor"];
                    serv.Ativo     = (Boolean)reader["Ativo"];
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }

            return(serv);
        }
        public int CadastrarVenda(Modelo.Venda venda)
        {
            FactoryConnection conn = new FactoryConnection();
            int    id   = 0;
            string sSQL = @"INSERT INTO venda
					(ValorTotal, Data, CPFFuncionario, CPFCliente) VALUES (@valorTotal, @data, @cpfFuncionario, @cpfCliente)
					SET @idVenda = SCOPE_IDENTITY()"                    ;

            try {
                SqlCommand cmd = new SqlCommand(sSQL, conn.AbrirConnexao());
                cmd.Parameters.AddWithValue("@valorTotal", venda.ValorTotal);
                cmd.Parameters.AddWithValue("@data", venda.Data);
                cmd.Parameters.AddWithValue("@cpfFuncionario", venda.CPFFuncionario);
                cmd.Parameters.AddWithValue("@cpfCliente", venda.CPFCliente);
                cmd.Parameters.AddWithValue("@idVenda", 0).Direction = System.Data.ParameterDirection.Output;


                cmd.ExecuteNonQuery();

                id = Convert.ToInt32(cmd.Parameters["@idVenda"].Value);
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
            return(id);
        }
        public void CadastrarItensVenda(Modelo.ItensVenda item)
        {
            FactoryConnection conn  = new FactoryConnection();
            String            query = "";

            try
            {
                if (item.IdProduto == 0)
                {
                    query = "insert into VendaProdutoServico (idVenda, idServico) values" +
                            "('" + item.IdVenda + "', '" + item.IdServico + "')";
                }
                if (item.IdServico == 0)
                {
                    query = "insert into VendaProdutoServico (idVenda,  idProduto) values" +
                            "('" + item.IdVenda + "', '" + item.IdProduto + "')";
                }


                SqlCommand    comand = new SqlCommand(query, conn.AbrirConnexao());
                SqlDataReader reader = comand.ExecuteReader();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
        }
Beispiel #9
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("CaixaMovimentacao", "ChaveCaixaMovimentacao"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `CaixaMovimentacao` (
                                         `ChaveCaixaMovimentacao` BIGINT NOT NULL AUTO_INCREMENT,
                                         `ChaveCaixa` BIGINT DEFAULT NULL,
                                         `ChavePessoa` BIGINT DEFAULT NULL,
                                         `ChavePedido` BIGINT DEFAULT NULL,
                                         `ChaveFile` BIGINT DEFAULT NULL,
                                         `ChaveFormaPagamento` BIGINT DEFAULT NULL,
                                         `Descricao` varchar(300) COLLATE utf8_bin DEFAULT NULL,
                                         `DataCadastro` datetime NULL,
                                         `DataPago` datetime NULL,
                                         `DataEstorno` datetime NULL,
                                         `TipoLancamento` BIGINT DEFAULT NULL,
                                         `FecharCaixaAutomatico` BOOLEAN DEFAULT NULL,     
                                         `Valor` DECIMAL(10,2) DEFAULT NULL,
                                         `ValorAntecipado` DECIMAL(10,2) DEFAULT NULL,
                                         `Ativo` BOOLEAN DEFAULT NULL,
                                         PRIMARY KEY (`ChaveCaixaMovimentacao`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela CaixaMovimentacao.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela CaixaMovimentacao: {error.Message}");
             }
         }
     }
 }
        public bool VerificaFunc(String cpf)
        {
            bool retorno = true;

            FactoryConnection conn = new FactoryConnection();

            try
            {
                String query = "select cpf from Funcionario where cpf ='" + cpf + "'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                if (reader.Read())
                {
                    retorno = true;
                }
                else
                {
                    retorno = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
            return(retorno);
        }
Beispiel #11
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("Banco", "ChaveBanco"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `Banco` (
                                       `ChaveBanco` BIGINT NOT NULL AUTO_INCREMENT,
                                       `NomeBanco` varchar(300) DEFAULT NULL,
                                       `NumeroConta` BIGINT NULL,
                                       `Agencia` BIGINT NULL,
                                       `DataCadastro` datetime NOT NULL,
                                       `Saldo` double DEFAULT NULL,
                                       `Descricao` varchar(300) DEFAULT NULL,
                                       `Ativo` BOOLEAN DEFAULT NULL, 
                                     PRIMARY KEY (`ChaveBanco`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela Banco.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela Banco: {error.Message}");
             }
         }
     }
 }
        public bool VerificaExistenciaServico(String Descricao)
        {
            bool retorno = true;

            FactoryConnection conn = new FactoryConnection();

            try
            {
                String query = "select Descricao from Servico where Descricao ='" + Descricao + "'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                if (reader.Read())
                {
                    retorno = true;
                }
                else
                {
                    retorno = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
            return(retorno);
        }
Beispiel #13
0
        public Produto BuscarProduto(int idProduto)
        {
            FactoryConnection conn = new FactoryConnection();
            Produto           prod = new Produto();

            try
            {
                String query = "SELECT * FROM Produto WHERE IdProduto = '" + idProduto + "' AND Ativo = 1";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                while (reader.Read())
                {
                    prod.Descricao  = (String)reader["Descricao"];
                    prod.Valor      = (Decimal)reader["Valor"];
                    prod.Quantidade = (int)reader["Quantidade"];
                    prod.IdProduto  = (int)reader["IdProduto"];
                    prod.Ativo      = (Boolean)reader["Ativo"];
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }

            return(prod);
        }
Beispiel #14
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("PedidosItens", "ChavePedidoItem"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `PedidosItens` (
                                       `ChavePedidoItem` BIGINT NOT NULL AUTO_INCREMENT,
                                       `ChavePedido` BIGINT NOT NULL,
                                       `ChaveProduto` BIGINT DEFAULT NULL,
                                       `Nome` varchar(300) DEFAULT NULL,  
                                       `Quatidade` BIGINT NULL,
                                     PRIMARY KEY (`ChavePedidoItem`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela PedidosItens.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela PedidosItens: {error.Message}");
             }
         }
     }
 }
Beispiel #15
0
        public void AlterarProduto(Produto produto)
        {
            FactoryConnection conn = new FactoryConnection();

            try
            {
                String query = "UPDATE Produto SET Descricao = '" + produto.Descricao +
                               "', Valor = '" + produto.Valor +
                               "', Quantidade = '" + produto.Quantidade +
                               "' WHERE IdProduto = '" + produto.IdProduto + "'";

                SqlCommand    comand = new SqlCommand(query, conn.AbrirConnexao());
                SqlDataReader reader = comand.ExecuteReader();

                MessageBox.Show("Alterado com sucesso!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
        }
Beispiel #16
0
        public void CadastrarProdutos(Produto produto)
        {
            FactoryConnection conn = new FactoryConnection();

            try
            {
                String query = "insert into Produto (Descricao, Valor, Quantidade, Ativo) values" +
                               "('" + produto.Descricao + "', '" + produto.Valor + "', '" + produto.Quantidade +
                               "','" + produto.Ativo + "')";

                SqlCommand    comand = new SqlCommand(query, conn.AbrirConnexao());
                SqlDataReader reader = comand.ExecuteReader();


                MessageBox.Show("Cadastrado com sucesso!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco!");
            }
            finally
            {
                conn.FecharConnecxao();
            }
        }
        public static bool ExisteColunaNaTabela(string pTable, string pColumn)
        {
            int resultado = 0;

            using (var cmd = FactoryConnection.NewCommand())
            {
                string pBanco   = XConfig.DataSouce;
                var    strQuery = $@"SELECT Count(*)
                                    FROM INFORMATION_SCHEMA.COLUMNS
                                    WHERE TABLE_NAME = '{pTable}'
                                    AND TABLE_SCHEMA = '{pBanco}'
                                    AND COLUMN_NAME = '{pColumn}'";
                try
                {
                    cmd.CommandText = strQuery;
                    resultado       = cmd.ExecuteScalar().AsInt64();
                }
                catch (Exception error)
                {
                    throw new Exception($"Erro ao validar existencia da coluna: \n{pColumn} da tabela {pTable}\n{error.Message}");
                }
                finally
                {
                    cmd.Prepare();
                }
            }
            return(resultado > 0);
        }
Beispiel #18
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("FormaPagamento", "ChaveFormaPagamento"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `FormaPagamento` (
                                     `ChaveFormaPagamento` BIGINT NOT NULL AUTO_INCREMENT,
                                     `Tipo` varchar(200) DEFAULT NULL,
                                     `Categoria` varchar(100) DEFAULT NULL,
                                     `Descricao` varchar(100) DEFAULT NULL,
                                     `Ativo` BOOLEAN DEFAULT NULL,
                                     PRIMARY KEY (`ChaveFormaPagamento`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela FormaPagamento.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela FormaPagamento: {error.Message}");
             }
         }
     }
 }
Beispiel #19
0
 public Cotacao get(String ativo)
 {
     using (ConnectionManager manager = FactoryConnection.getInstance().getConnection())
     {
         return(get(manager.getConnection(), ativo));
     }
 }
Beispiel #20
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("FileToUpload", "ChaveFile"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `FileToUpload` (
                                     `ChaveFile` BIGINT NOT NULL AUTO_INCREMENT,
                                     `FileName` text(21845) COLLATE utf8_bin DEFAULT NULL,
                                     `FileSize` text(21845) COLLATE utf8_bin DEFAULT NULL,
                                     `FileType` text(21845) COLLATE utf8_bin DEFAULT NULL,
                                     `FileAsBase64` text(21845) COLLATE utf8_bin DEFAULT NULL,
                                     `LastModifiedDate` datetime NULL,
                                     PRIMARY KEY (`ChaveFile`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela FileToUpload.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela FileToUpload: {error.Message}");
             }
         }
     }
 }
Beispiel #21
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("Pedidos", "ChavePedido"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `Pedidos` (
                                     `ChavePedido` BIGINT NOT NULL AUTO_INCREMENT,
                                     `ChavePessoa` BIGINT DEFAULT NULL,
                                     `ChaveFormaPagamento` BIGINT DEFAULT NULL,
                                     `DataPedido` datetime NOT NULL,
                                     `Orcamento` BIGINT DEFAULT NULL,
                                     `LancamentoCaixa` bit(1) NOT NULL,
                                     `Status` varchar(300) COLLATE utf8_bin DEFAULT NULL,
                                     `Descricao` varchar(300) COLLATE utf8_bin DEFAULT NULL,
                                     `Quatidade` BIGINT DEFAULT NULL,
                                     `PrecoTotal` DECIMAL(12,2) DEFAULT NULL,
                                     `Parcela` BiGINT DEFAULT NULL,
                                     `ValorAntecipado` DECIMAL(12,2) DEFAULT NULL,
                                     PRIMARY KEY (`ChavePedido`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela Pedidos.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela Pedidos: {error.Message}");
             }
         }
     }
 }
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("Pessoas", "ChavePessoa"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `Pessoas` (
                                       `ChavePessoa` BIGINT NOT NULL AUTO_INCREMENT,
                                       `ChaveControleAcesso` BIGINT DEFAULT NULL,
                                       `Nome` varchar(100) DEFAULT NULL,
                                       `Email` varchar(100) DEFAULT NULL,
                                       `Senha` varchar(100) DEFAULT NULL,
                                       `CnpjCpf` varchar(14) DEFAULT NULL,                                              
                                       `Telefone` varchar(20) DEFAULT NULL,
                                       `DataCadastro` datetime NOT NULL,
                                       `Cep` varchar(8) DEFAULT NULL,
                                       `Endereco` varchar(500) DEFAULT NULL,
                                       `Observacoes` varchar(1000) DEFAULT NULL,
                                       `Ativo` BOOLEAN DEFAULT NULL,
                                     PRIMARY KEY (`ChavePessoa`))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela Pessoas.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error Tabela Pessoas: {error.Message}");
             }
         }
     }
 }
 public static List <T> FindCustom(SQLBuilder sqlBuilder)
 {
     using (var connection = FactoryConnection.GetConnection())
     {
         var result = connection.Query <T>(sqlBuilder.ToString()).ToList <T>();
         return(result);
     }
 }
Beispiel #24
0
        /// <summary>
        /// Executa ao iniciar o Form
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                foreach (var groupUser in GlobalUser.User.GroupUsers)
                {
                    foreach (var groupPermission in groupUser.GroupAccess.GroupPermissions)
                    {
                        if (groupPermission.Permission.TypeComponent != TypeComponent.Screen)
                        {
                            continue;
                        }
                        if (groupPermission.Permission.NamePermission != Name)
                        {
                            continue;
                        }
                        if (groupPermission.Permission.Visible)
                        {
                            continue;
                        }
                        MessageBox.Show(@"Você não tem acesso a está tela", @"ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        StateForm = StateForm.Waiting;
                        Close();
                    }
                }

                var text = "ESR Softwares";

                text = GetAttribute <DisplayNameAttribute>()?.DisplayName ?? Name;

                if (!GlobalUser.Forms.Any(t => t.TableName == Name))
                {
                    var table = new Domain.Catalog.Table()
                    {
                        Status          = Status.Confirmed,
                        TableName       = Name,
                        DescriptionForm = text
                    };
                    _tableApp.InsertOrUpdate(table);
                    if (FactoryConnection.Save())
                    {
                        GlobalUser.Forms.Add(table);
                    }
                }

                Text = text;

                RefreshControls();
            }
            catch (Exception)
            {
            }
            base.OnLoad(e);
        }
 private NpgsqlConnection GetConnection()
 {
     if (_connection == null)
     {
         return(FactoryConnection.GetConnection());
     }
     else
     {
         return(_connection);
     }
 }
        public static List <T> FindAll()
        {
            using (var connection = FactoryConnection.GetConnection())
            {
                string scriptSelect = FactoryScript.Select(typeof(T), "public");

                var Result = connection.Query <T>(scriptSelect).ToList <T>();

                return(Result);
            }
        }
        public static T FindById(int Id)
        {
            using (var connection = FactoryConnection.GetConnection())
            {
                string scriptSelect = FactoryScript.Select(typeof(T), Id, "public");

                var Result = connection.Query <T>(scriptSelect).FirstOrDefault <T>();

                return(Result);
            }
        }
Beispiel #28
0
 private static void CriarTabelaSql()
 {
     if (!VerificarExisteTabela.ExisteColunaNaTabela("Versao_Migration", "ChaveVersao"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"CREATE TABLE `Versao_Migration`(
                                         `ChaveVersao` BIGINT NOT NULL AUTO_INCREMENT,
                                         `Data` datetime NOT NULL,
                                         `Versao` BIGINT NOT NULL, 
                                     PRIMARY KEY(ChaveVersao))";
                 cmd.ExecuteNonQuery();
                 XLog.RegistraLog($"Tabela Versao_Migration.", "ModeloBanco");
             }
             catch (Exception error)
             {
                 throw new Exception($"Error criação da Tabela Versao_Migration: {error.Message}");
             }
         }
     }
     if (!VerificarExisteTabela.ExisteRegistro("Versao_Migration", "versao", "1"))
     {
         using (var cmd = FactoryConnection.NewCommand())
         {
             try
             {
                 cmd.CommandText = @"INSERT INTO VERSAO_MIGRATION (DATA, VERSAO) VALUES(NOW(),'1')";
                 cmd.ExecuteNonQuery();
             }
             catch (Exception eX)
             {
                 throw new Exception($"Error preencher versão Versao_Migration: {eX.Message}");
             }
         }
     }
     //var M01 = _contexto.Versao_Migration.FirstOrDefault(px => px.Versao == 1);
     //if (M01 is null)
     //{
     //    try
     //    {
     //        _contexto.Versao_Migration.Add(new Versao_Migration { Data = DateTime.Now, Versao = 1 });
     //        _contexto.SaveChanges();
     //    }
     //    catch (Exception eX)
     //    {
     //        throw new Exception($"Error 'Versao_Migration': {eX.Message}");
     //    }
     //}
 }
        public void AlterarFuncionario(Funcionario func)
        {
            FactoryConnection conn = new FactoryConnection();

            try
            {
                String query = "UPDATE Funcionario SET nome = '" + func.Nome + "', telefone = '" + func.Telefone +
                               "', endereco = '" + func.Endereco + "', porcentagem = '" + func.Porcentagem +
                               "', dataNascimento = '" + func.DataNascimento + "' WHERE cpf = '" + func.Cpf + "'";

                SqlCommand    comand = new SqlCommand(query, conn.AbrirConnexao());
                SqlDataReader reader = comand.ExecuteReader();

                MessageBox.Show("Alterado com sucesso!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }

            /*
             * try
             * {
             *  comm.CommandText = "UPDATE FUNCIONARIOS set NOME=@nome, endereco=@endereco, datnascimento=@datNascimento," +
             *                     "telefone=@telefone";
             *  comm.Parameters.AddWithValue("@nome", funionario.Nome);
             *  comm.Parameters.AddWithValue("@endereco", funionario.Endereco);
             *  comm.Parameters.AddWithValue("@datNascimento", funionario.Data_Nascimento);
             *  comm.Parameters.AddWithValue("@telefone", funionario.Telefone);
             *  comm.Parameters.AddWithValue("@cpf", funionario.Cpf);
             *
             *  fc.AbrirConnexao();
             *  comm.ExecuteNonQuery();
             *  fc.FecharConnecxao();
             * }
             * catch (SqlException e)
             * {
             *  e.Message.GetType();
             * }
             */
        }
Beispiel #30
0
        public ArrayList ListarCliente(String busca)
        {
            FactoryConnection conn  = new FactoryConnection();
            ArrayList         lista = new ArrayList();

            try
            {
                String query = "SELECT * FROM Cliente WHERE nome LIKE '%" + busca + "%'";

                SqlCommand comand = new SqlCommand(query, conn.AbrirConnexao());

                SqlDataReader reader = comand.ExecuteReader();

                while (reader.Read())
                {
                    Cliente cli = new Cliente();

                    cli.Nome           = (String)reader["nome"];
                    cli.Cpf            = (String)reader["cpf"];
                    cli.DataNascimento = (String)reader["dataNascimento"];
                    cli.Email          = (String)reader["email"];
                    cli.Endereco       = (String)reader["endereco"];
                    cli.Telefone       = (String)reader["telefone"];
                    cli.Ativo          = (Boolean)reader["Ativo"];

                    if (cli.Ativo == true)
                    {
                        lista.Add(cli);
                    }
                }
                reader.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("Não foi possível conectar-se ao banco de dados!");
            }
            finally
            {
                conn.FecharConnecxao();
            }

            return(lista);
        }