public CadastroJogadorView(JogadoresListView owner, string ID = "")
        {
            InitializeComponent();
            this._owner = owner;
            DataNascimentoDateTimePicker.Format       = DateTimePickerFormat.Custom;
            DataNascimentoDateTimePicker.CustomFormat = "dd/MM/yyyy";

            DB.Posicoes.Load();
            PosicaoComboBox.ValueMember   = "ID";
            PosicaoComboBox.DisplayMember = "Nome";
            PosicaoComboBox.DataSource    = DB.Posicoes.Local.ToBindingList();

            DB.Times.Load();
            TimeComboBox.ValueMember   = "ID";
            TimeComboBox.DisplayMember = "Nome";
            TimeComboBox.DataSource    = DB.Times.Local.ToBindingList();

            if (ID != string.Empty)
            {
                DB.Jogadores.Load();
                var jogadorID = int.Parse(ID);
                var jogador   = DB.Jogadores.First(x => x.ID == jogadorID);
                NomeTextBox.Text    = jogador.Nome;
                ApelidoTextBox.Text = jogador.Apelido;
                DataNascimentoDateTimePicker.Text = jogador.DataNascimento.ToString();
                PosicaoComboBox.SelectedValue     = jogador.Posicao.ID;
                TimeComboBox.SelectedValue        = jogador.Time.ID;
            }

            this.FormClosing += new FormClosingEventHandler(this.OwnerFormPerformRefresh);
        }
Exemple #2
0
        private void TimesDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;


            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var currentRow = TimesDataGridView.Rows.SharedRow(e.RowIndex);
                var timeID     = currentRow.Cells["columnID"].Value.ToString();

                if (timeID != string.Empty)
                {
                    var cellValue = TimesDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    if (cellValue.Equals("Jogadores"))
                    {
                        int.TryParse(timeID, out int ID);
                        var jogadoresListView = new JogadoresListView(ID);
                        jogadoresListView.Show();
                    }
                    else if (cellValue.Equals("Editar"))
                    {
                        var editarView = new EditarTimeView(this, timeID);
                        editarView.Show();
                    }
                    else if (cellValue.Equals("Excluir"))
                    {
                        var nomeTime     = currentRow.Cells["columnNome"].Value.ToString();
                        var dialogResult = MessageBox.Show("Deseja realmente excluir o time " + nomeTime + "?", "Atenção", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            var time = DB.Times.Single(t => t.ID.ToString() == timeID);

                            var timeEmUso = DB.Jogadores.Any(j => j.Time.ID == time.ID);
                            if (timeEmUso)
                            {
                                MessageBox.Show(String.Format("Não é possível excluir o time {0} porque existem jogadores associados a ele.", nomeTime));
                            }
                            else
                            {
                                var jogadoresApagados = DB.Jogadores.Where(j => j.TimeID == time.ID).ToList();
                                foreach (var j in jogadoresApagados)
                                {
                                    DB.Entry <Jogador>(j).State = EntityState.Deleted;                                    //Necessário atualizar pois o instância DB atual não enxerga a alteração na instância do JogadoresListView
                                }
                                DB.Times.Remove(time);
                                DB.SaveChanges();
                                PerformRefresh();
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void JogadoresButton_Click(object sender, EventArgs e)
        {
            var jogadoresListView = new JogadoresListView();

            jogadoresListView.Show();
        }