public static Operador buscaOperador(string nome)
        {
            using (SqlConnection sqlConn = new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("nome", nome);
                    sqlCommand.CommandText = "select * from Operador where nome = @nome";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();

                    if (dataReader.Read())
                    {
                        Operador op = new Operador(int.Parse(dataReader[0].ToString()),
                                                    dataReader[1].ToString(),
                                                    dataReader[3].ToString(),
                                                    int.Parse(dataReader[2].ToString()),
                                                    dataReader[4].ToString(),
                                                    dataReader[5].ToString());
                        return op;
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }
        public static Operador AlterarOperador(int id,string nome, int tipo, string end, string tel)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.CommandText = "update operador set Nome = '" + nome + "',"
                                                                + " Tipo = " + tipo + ","
                                                                + " Endereco = '" + end + "',"
                                                                + " Telefone = '" + tel + "'"
                                                                + " where Id = " + id;
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        sqlCommand.Parameters.AddWithValue("Id", id);
                        sqlCommand.CommandText = "select * from operador where Id = @Id";
                        SqlDataReader dataReader;
                        dataReader = sqlCommand.ExecuteReader();
                        if (dataReader.Read())
                        {
                            Operador op = new Operador(int.Parse(dataReader[0].ToString()),
                                                    dataReader[1].ToString(),
                                                    dataReader[3].ToString(),
                                                    int.Parse(dataReader[2].ToString()),
                                                    dataReader[4].ToString(),
                                                    dataReader[5].ToString());
                            sqlConn.Close();
                            return op;
                        }
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }
        public static Operador RemoverOperador(Operador op)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("id", op.Id);
                    sqlCommand.CommandText = "delete from operador where Id = @id";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        return op;
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }
        public static Operador LoginChecker(string login, string senha)
        {
            using (SqlConnection sqlConn = new SqlConnection(ConnString))
            {
                using(SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("login", login);
                    sqlCommand.CommandText = "Select * from Operador where nome = @login";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();
                    SqlDataReader dataReader = sqlCommand.ExecuteReader();

                    if (dataReader.Read())
                    {
                        Operador op = new Operador(int.Parse(dataReader[0].ToString()),
                                                    dataReader[1].ToString(),
                                                    dataReader[3].ToString(),
                                                    int.Parse(dataReader[2].ToString()),
                                                    dataReader[4].ToString(),
                                                    dataReader[5].ToString());

                        //Compara as senhas
                        if (string.Compare(op.Senha, senha, true) == 0)
                        {
                            sqlConn.Close();
                            return op;
                        }
                        else
                        {
                            sqlConn.Close();
                            return null;
                        }
                    }
                    //Não encontrou nenhum resultado.
                    else
                    {
                        sqlConn.Close();
                        return null;
                    }
                }
            }
        }
        public static Operador InserirOperador(string nome, int tipo, string end, string tel)
        {
            using (SqlConnection sqlConn =
                        new SqlConnection(ConnString))
            {
                using (SqlCommand sqlCommand = new SqlCommand())
                {
                    sqlCommand.Parameters.AddWithValue("nome", nome);
                    sqlCommand.Parameters.AddWithValue("tipo", tipo);
                    sqlCommand.Parameters.AddWithValue("endereco", end);
                    sqlCommand.Parameters.AddWithValue("tel", tel);
                    sqlCommand.Parameters.AddWithValue("senha", 123);
                    sqlCommand.CommandText = "insert into operador values (@nome,@tipo,@endereco,@tel,@senha)";
                    sqlCommand.Connection = sqlConn;
                    sqlConn.Open();

                    if (sqlCommand.ExecuteNonQuery() > 0)
                    {
                        sqlCommand.CommandText = "select * from operador order by Id desc";
                        SqlDataReader dataReader;
                        dataReader = sqlCommand.ExecuteReader();
                        if (dataReader.Read())
                        {
                            Operador op = new Operador(int.Parse(dataReader[0].ToString()),
                                                dataReader[1].ToString(),
                                                dataReader[3].ToString(),
                                                int.Parse(dataReader[2].ToString()),
                                                dataReader[4].ToString(),
                                                dataReader[5].ToString());
                            sqlConn.Close();
                            return op;
                        }
                    }
                    sqlConn.Close();
                    return null;
                }
            }
        }