internal void AdicionarYoutuber(Youtuber youtuber) { youtuber.SetCodigo(++Youtuber.UltimoCodigo); youtubers.Add(youtuber); EscreverNoArquivoDosYoutubers(); }
private void SalvarYoutube() { youtuber = new Youtuber(); try { youtuber.SetNome(txtNome.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtNome.Focus(); return; } try { youtuber.SetSobrenome(txtSobrenome.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtSobrenome.Focus(); return; } try { youtuber.SetApelido(txtApelido.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtApelido.Focus(); return; } if (cbNacionalidade.SelectedIndex < 0) { MessageBox.Show("Selecione uma nacionalidade."); cbNacionalidade.DroppedDown = true; return; } try { youtuber.SetNacionalidade(cbNacionalidade.SelectedItem.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); cbNacionalidade.DroppedDown = true; return; } try { youtuber.SetRenda(Convert.ToDouble(txtRenda.Text)); } catch { MessageBox.Show("Preencha a renda com valores corretos."); txtRenda.Focus(); return; } try { youtuber.SetNomeCanal(txtNomeCanal.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtNomeCanal.Focus(); return; } if (cbCategoria.SelectedIndex < 0) { MessageBox.Show("Selecione uma categoria."); cbCategoria.DroppedDown = true; return; } try { youtuber.SetCategoria(cbCategoria.SelectedItem.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); cbCategoria.DroppedDown = true; return; } try { youtuber.SetLinkCanal(txtLinkCanal.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtLinkCanal.Focus(); return; } if (cbPlataforma.SelectedIndex < 0) { MessageBox.Show("Selecione uma plataforma."); cbPlataforma.DroppedDown = true; return; } try { youtuber.SetPlataforma(cbPlataforma.SelectedItem.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); cbPlataforma.DroppedDown = true; return; } try { youtuber.SetQuantidadeVideos(Convert.ToInt32(nudQuantidadeVideos.Value)); } catch (Exception ex) { MessageBox.Show(ex.Message); nudQuantidadeVideos.Focus(); return; } try { youtuber.SetQuantidadeVisualizacoes(Convert.ToInt64(txtQuantidadeVisualizacoes.Text.Replace(".", "").Replace(",", ""))); } catch { MessageBox.Show("Preencha a quantidade de visualizações com as informações corretar."); txtQuantidadeVisualizacoes.Focus(); return; } try { youtuber.SetQuantidadeInscritos(Convert.ToInt64(txtQuantidadeInscritos.Text.Replace(".", "").Replace(",", ""))); } catch { MessageBox.Show("Preencha a quantidade de inscritos com as informações corretar."); txtQuantidadeInscritos.Focus(); return; } try { youtuber.SetQuantidadeStrikes(Convert.ToInt32(nudQuantidadeStrikes.Value)); } catch (Exception ex) { MessageBox.Show(ex.Message); nudQuantidadeStrikes.Focus(); return; } try { youtuber.SetQuantidadeLikes(Convert.ToInt64(txtQuantidadeLikes.Text.Replace(".", "").Replace(",", ""))); } catch { MessageBox.Show("Preencha a quantidade de likes com as informações corretar."); txtQuantidadeLikes.Focus(); return; } youtuber.SetTemAnuncios(chkAnuncio.Checked); try { youtuber.SetDescricao(txtDescricao.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); txtDescricao.Focus(); return; } if (chkPatrocinio.Checked) { youtuber.SetTemPatrocinador(true); } else { youtuber.SetTemPatrocinador(false); } if (chkStreamer.Checked) { youtuber.SetStreamer(true); } else { youtuber.SetStreamer(false); } YoutuberRepository tudo = new YoutuberRepository(); if (codigoRegistro == -1) { tudo.AdicionarYoutuber(youtuber); MessageBox.Show("Youtuber cadastrado com sucesso"); } else { youtuber.SetCodigo(codigoRegistro); tudo.EditarYoutuber(youtuber, codigoRegistro); MessageBox.Show("Youtuber alterado com sucesso"); Dispose(); } LimparCampos(); }