Ejemplo n.º 1
0
        private void listViewClubes__DoubleClick(object sender, EventArgs e)
        {
            if (listViewClubes_.SelectedIndices.Count <= 0)
            {
                return;
            }

            int _ID = Convert.ToInt32(listViewClubes_.GetSelectedItem().Tag);

            //Se for para abrir
            if (!_FormInicio.VerificarEditarInstrucao())
            {
                return;
            }

            foreach (Clube clb in listaCLubes)
            {
                if (clb.ID == _ID)
                {
                    FormEditarClube PopupEditar = new FormEditarClube(clb);
                    DialogResult    resultado   = PopupEditar.ShowDialog();

                    if (resultado == DialogResult.OK)
                    {
                        string NovoNome = PopupEditar.NomeEditado;
                        string NovaFoto = PopupEditar.FotoEditada;

                        //Verificar se os dados foram editados
                        if (NovoNome == "nop" && NovaFoto == "nop")
                        {
                            return;
                        }

                        string[] parts = NovaFoto.Split('\\');
                        if (clb.Nome == NovoNome && clb.NomeFoto == parts[parts.Count() - 1])
                        {
                            return;
                        }

                        //Editar
                        if ((NovoNome != "nop" && NovoNome != clb.Nome) || (clb.NomeFoto != parts[parts.Count() - 1] && NovaFoto != "nop"))
                        {
                            Funcionalidades.EditarClube(NovoNome, NovaFoto, clb);
                            _FormInicio.EscreverNaConsola(NovoNome + " editado!");
                            CarregarListaClubes();
                        }
                    }
                    else if (resultado == DialogResult.Ignore)
                    {
                        //Apagar
                        FormPopUp    PopupConfirmation = new FormPopUp("Tem a certeza que pertende continuar?");
                        DialogResult resultadoPopup    = PopupConfirmation.ShowDialog();

                        if (resultadoPopup == DialogResult.Yes)
                        {
                            try
                            {
                                Funcionalidades.EliminarClube(clb);
                                _FormInicio.EscreverNaConsola(clb.Nome + " eliminado!");
                                CarregarListaClubes();
                            }
                            catch
                            {
                                _FormInicio.EscreverNaConsola("Erro ao eliminar o clube...");
                            }
                        }
                    }

                    break;
                }
            }
        }