Example #1
0
        public List <UnidadeMedida> GetAllUnidadesIncomplete(string find)
        {
            List <UnidadeMedida> unidadeList = new List <UnidadeMedida>();
            MySqlConnection      connection  = fileConn.PrepareConnection();// PrepareConnection();


            sqlCommand = connection.CreateCommand();
            sqlCommand.Parameters.AddWithValue("NOME", "%" + find + "%");
            sqlCommand.CommandText = "SELECT * FROM `tupper`.`tb_unidademedida` WHERE `uni_Nome` LIKE @NOME;";
            connection.Open();
            dataReader = sqlCommand.ExecuteReader();

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    UnidadeMedida unidade = new UnidadeMedida();
                    unidade.Nome  = dataReader[1].ToString();
                    unidade.Sigla = dataReader[2].ToString();
                    unidadeList.Add(unidade);
                }
            }
            connection.Close();
            return(unidadeList);
        }
Example #2
0
 public Pecas(byte[] foto, decimal capacidade, int quantidade, bool vaiMicro, bool vaiFreezer, string cor, string nome, UnidadeMedida unidadeMedida)
 {
     Foto              = foto;
     Capacidade        = capacidade;
     Quantidade        = quantidade;
     VaiMicro          = vaiMicro;
     VaiFreezer        = vaiFreezer;
     Cor               = cor;
     Nome              = nome;
     UnidadeMedidaPeca = unidadeMedida;
 }
Example #3
0
        public Boolean Update(UnidadeMedida unidadeMedida)
        {
            MySqlConnection connection = PrepareConnection();

            connection.Open();
            sqlCommand = connection.CreateCommand();
            sqlCommand.Parameters.AddWithValue("@NOME", unidadeMedida.Nome);
            sqlCommand.Parameters.AddWithValue("@SIGLA", unidadeMedida.Sigla);
            sqlCommand.CommandText = "UPDATE `tb_unidademedida` SET `uni_Nome` = @NOME,`uni_Sigla` = @SIGLA WHERE `uni_Nome` = @NOME;";

            if (sqlCommand.ExecuteNonQuery() == 1)
            {
                connection.Close();
                return(true);
            }
            else
            {
                connection.Close();
                return(false);
            }
        }
Example #4
0
        public UnidadeMedida GetUnidadeMedida(UnidadeMedida find)
        {
            UnidadeMedida   unidade    = new UnidadeMedida();
            MySqlConnection connection = PrepareConnection();
            MySqlDataReader reader;

            sqlCommand = connection.CreateCommand();
            sqlCommand.Parameters.AddWithValue("NOME", find.Nome);
            sqlCommand.CommandText = "SELECT * FROM `tupper`.`tb_unidademedida` WHERE uni_Nome = @NOME;";
            connection.Open();
            reader = sqlCommand.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    unidade.Nome  = reader[1].ToString();
                    unidade.Sigla = reader[2].ToString();
                }
            }

            return(unidade);
        }
Example #5
0
        public Boolean Insert(UnidadeMedida unidadeMedida)
        {
            Boolean         valReturn     = false;
            MySqlConnection sqlConnection = PrepareConnection();

            sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.Parameters.AddWithValue("@NOME", unidadeMedida.Nome);
            sqlCommand.Parameters.AddWithValue("@SIGLA", unidadeMedida.Sigla);

            try
            {
                sqlConnection.Open();
                if (!Exists(sqlCommand.Parameters[0].Value.ToString()))
                {
                    sqlCommand.CommandText = "INSERT INTO `tupper`.`tb_UnidadeMedida` (`uni_Nome`, `uni_Sigla`) VALUES (@NOME, @SIGLA);";
                    if (sqlCommand.ExecuteNonQuery() == 1)
                    {
                        valReturn = true;
                    }
                    //return valReturn;
                }
                return(valReturn);
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("Erro ao inserir os dados:\n" + ex.ToString(), "ERRO!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
            finally
            {
                if (sqlConnection.State == System.Data.ConnectionState.Open)
                {
                    sqlConnection.Close();
                }
            }
        }
Example #6
0
        public List <UnidadeMedida> GetAllUnidades()
        {
            List <UnidadeMedida> unidadeList = new List <UnidadeMedida>();
            MySqlConnection      connection  = PrepareConnection();


            sqlCommand             = connection.CreateCommand();
            sqlCommand.CommandText = "SELECT * FROM `tupper`.`tb_unidademedida`;";
            connection.Open();
            dataReader = sqlCommand.ExecuteReader();

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    UnidadeMedida unidade = new UnidadeMedida();
                    unidade.Nome  = dataReader[1].ToString();
                    unidade.Sigla = dataReader[2].ToString();
                    unidadeList.Add(unidade);
                }
            }
            connection.Close();
            return(unidadeList);
        }
Example #7
0
        public Boolean Delete(UnidadeMedida unidade)
        {
            MySqlConnection sqlConnection = PrepareConnection();

            try
            {
                sqlCommand = sqlConnection.CreateCommand();
                sqlCommand.Parameters.AddWithValue("NOME", unidade.Nome);
                sqlCommand.Parameters.AddWithValue("SIGLA", unidade.Sigla);
                sqlConnection.Open();
                if (Exists(sqlCommand.Parameters[0].Value.ToString()))
                {
                    sqlCommand.CommandText = "SET SQL_SAFE_UPDATES=0; DELETE FROM `tupper`.`tb_unidademedida` WHERE `uni_Nome` = @NOME AND `uni_Sigla` = @SIGLA;";
                    if (sqlCommand.ExecuteNonQuery() == 1)
                    {
                        sqlConnection.Close();
                        return(true);
                    }
                    else
                    {
                        sqlConnection.Close();
                        return(false);
                    }
                }
                else
                {
                    sqlConnection.Close();
                    return(false);
                }
            }
            catch (MySqlException ex)
            {
                MessageBox.Show("Erro ao deletar os dados:\n" + ex.ToString(), "ERRO!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }