public TerapeutaWEB devolveTerapeuta(int terapeutaId) { TerapeutaWEB t = null; foreach (TerapeutaWEB item in listaTerapeutas) { if (item.id == terapeutaId) { t = item; } } return(t); }
private void listViewTerapeuta_SelectedIndexChanged(object sender, EventArgs e) { if (listViewTerapeuta.Items.Count > 0) { if (listViewTerapeuta.SelectedItems.Count == 1) { int terapeutaId = Convert.ToInt32(listViewTerapeuta.SelectedItems[0].SubItems[0].Text); TerapeutaWEB aux = devolveTerapeuta(terapeutaId); if (aux != null) { t = aux; ContaWEB contaTerapeuta = devolveConta(t.contaID, tipoT); if (contaTerapeuta != null) { txt_username_terapeuta.Text = contaTerapeuta.username; txt_password_terapeuta.Text = contaTerapeuta.password; txt_nome_terapeuta.Text = t.nome; txt_cc_terapeuta.Text = t.cc; txt_telefone_terapeuta.Text = t.telefone; string dtNasc = t.dataNasc; string[] dataPartes = dtNasc.Split('/'); string dia = dataPartes[0]; string mes = dataPartes[1]; string ano = dataPartes[2]; if (dia.Length == 1) { dia = "0" + dia; } if (mes.Length == 1) { mes = "0" + mes; } dtNasc = dia + "/" + mes + "/" + ano; DateTime data = getData(dtNasc); dt_dataNasc_terapeuta.Value = data; } } } } }
private void btn_guardar_terapeuta_Click(object sender, EventArgs e) { if (validarDadosTerapeuta()) { if (isNovoTerapeuta) { ContaWEB conta = new ContaWEB(); conta.username = txt_username_terapeuta.Text; conta.password = txt_password_terapeuta.Text; conta.isAdmin = false; TerapeutaWEB t = new TerapeutaWEB(); t.nome = txt_nome_terapeuta.Text; t.cc = txt_cc_terapeuta.Text; t.dataNasc = dt_dataNasc_terapeuta.Value.ToString("dd/MM/yyyy"); t.telefone = txt_telefone_terapeuta.Text; bool res = servico.addTerapeuta(token, t, conta); if (res) { MessageBox.Show("Terapeuta adicionado com sucesso!"); isNovoTerapeuta = false; unblockButtonsTerapeuta(); limparCamposTerapeuta(); preencheTerapeutas(); } else { MessageBox.Show("Não foi possível adicionar o terapeuta!"); isNovoTerapeuta = false; unblockButtonsTerapeuta(); limparCamposTerapeuta(); } } else if (isEditarTerapeuta) { ContaWEB contaT = devolveConta(t.contaID, tipoT); contaT.username = txt_username_terapeuta.Text; contaT.password = txt_password_terapeuta.Text; t.nome = txt_nome_terapeuta.Text; t.cc = txt_cc_terapeuta.Text; t.telefone = txt_telefone_terapeuta.Text; t.dataNasc = getDataString(dt_dataNasc_terapeuta.Value); bool resultado = servico.editTerapeuta(token, t, contaT); if (resultado) { MessageBox.Show("Terapeuta adicionado com sucesso!"); isEditarTerapeuta = false; unblockButtonsTerapeuta(); limparCamposTerapeuta(); preencheTerapeutas(); } else { isEditarTerapeuta = false; unblockButtonsTerapeuta(); limparCamposTerapeuta(); preencheTerapeutas(); MessageBox.Show("Não foi possível alterar o terapeuta, revertendo alterações!"); } MessageBox.Show(listaTerapeutas[0].dataNasc.ToString()); } } else { MessageBox.Show("Preencha os campos em falta!", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information); } }