//apagar registo
        public void Delete_registo(int id)
        {
            int     index = listaRegistos.FindIndex(listaRegistos => listaRegistos.Id_Registo == id);
            Registo r     = listaRegistos[index];

            listaRegistos[index].Estado = 1;
            atualizaFicheiroRegistos();
            if (respostaApagarRegisto != null)
            {
                respostaApagarRegisto();
            }
        }
        //Criar Registo
        public void guardarRegisto(string idRegisto, string idUtilizador, string tiposE, DateTime inicio, DateTime fim, List <FrameRegisto> f, string fra)
        {
            Registo R = new Registo(Convert.ToInt32(idRegisto), Convert.ToInt32(idUtilizador), tiposE, inicio, fim, f, fra, 0);

            listaRegistos.Add(R);

            atualizaFicheiroRegistos();

            if (respostaCriarRegisto != null)
            {
                respostaCriarRegisto();
            }
        }
        public void resetOrdem()
        {
            Registo temp = new Registo();

            for (int n = 1; n < listaRegistos.Count; n++)
            {
                for (int j = 0; j < listaRegistos.Count - n; j++)
                {
                    if (listaRegistos[j].Id_Registo > listaRegistos[j + 1].Id_Registo)
                    {
                        temp                 = listaRegistos[j];
                        listaRegistos[j]     = listaRegistos[j + 1];
                        listaRegistos[j + 1] = temp;
                    }
                }
            }
        }
        //ordenar registos
        public void OrdenarLista(int i)
        {
            if (i == 0)
            {
                Registo temp = new Registo();

                for (int n = 1; n < listaRegistos.Count; n++)
                {
                    for (int j = 0; j < listaRegistos.Count - n; j++)
                    {
                        if (listaRegistos[j].Id_Registo > listaRegistos[j + 1].Id_Registo)
                        {
                            temp                 = listaRegistos[j];
                            listaRegistos[j]     = listaRegistos[j + 1];
                            listaRegistos[j + 1] = temp;
                        }
                    }
                }
                if (flagID == false)
                {
                    flagID = true;
                }
                else
                {
                    listaRegistos.Reverse();
                    flagID = false;
                }
            }


            if (i == 1)
            {
                Registo temp = new Registo();

                for (int n = 1; n < listaRegistos.Count; n++)
                {
                    for (int j = 0; j < listaRegistos.Count - n; j++)
                    {
                        if (listaRegistos[j].tiposExame.CompareTo(listaRegistos[j + 1].tiposExame) > 0)
                        {
                            temp                 = listaRegistos[j];
                            listaRegistos[j]     = listaRegistos[j + 1];
                            listaRegistos[j + 1] = temp;
                        }
                    }
                }
                if (flagTipo == false)
                {
                    flagTipo = true;
                }
                else
                {
                    listaRegistos.Reverse();
                    flagTipo = false;
                }
            }


            if (i == 2)
            {
                Registo temp = new Registo();

                for (int n = 1; n < listaRegistos.Count; n++)
                {
                    for (int j = 0; j < listaRegistos.Count - n; j++)
                    {
                        if (listaRegistos[j].dataInicio > listaRegistos[j + 1].dataInicio)
                        {
                            temp                 = listaRegistos[j];
                            listaRegistos[j]     = listaRegistos[j + 1];
                            listaRegistos[j + 1] = temp;
                        }
                    }
                }
                if (flagDI == false)
                {
                    flagDI = true;
                }
                else
                {
                    listaRegistos.Reverse();
                    flagDI = false;
                }
            }


            if (i == 3)
            {
                Registo temp = new Registo();

                for (int n = 1; n < listaRegistos.Count; n++)
                {
                    for (int j = 0; j < listaRegistos.Count - n; j++)
                    {
                        if (listaRegistos[j].dataFim > listaRegistos[j + 1].dataFim)
                        {
                            temp                 = listaRegistos[j];
                            listaRegistos[j]     = listaRegistos[j + 1];
                            listaRegistos[j + 1] = temp;
                        }
                    }
                }
                if (flagDF == false)
                {
                    flagDF = true;
                }
                else
                {
                    listaRegistos.Reverse();
                    flagDF = false;
                }
            }

            if (AtualizarDataRegistos != null)
            {
                AtualizarDataRegistos();
            }
        }
 //adicionar registos lista. Controller chama este metodo n vezes
 public void AdicionarNovoRegistoLista(Registo novo) //ler do ficheiro
 {
     listaRegistos.Add(novo);                        //adicionar à lista
 }