Пример #1
0
        private void btn_guardarPaciente_Click(object sender, EventArgs e)
        {
            bool resultado = false;

            if (validarDadosPaciente())
            {
                if (isNovoPaciente)
                {
                    pacienteNovo.nome     = txt_nome_paciente.Text;
                    pacienteNovo.cc       = txt_cc_paciente.Text;
                    pacienteNovo.telefone = txt_telefone_paciente.Text;
                    pacienteNovo.dataNasc = getDataString(dt_dataNasc_paciente.Value);
                    pacienteNovo.morada   = rich_morada_paciente.Text;

                    if (radioM_paciente.Checked)
                    {
                        pacienteNovo.sexo = "H";
                    }
                    else
                    {
                        pacienteNovo.sexo = "M";
                    }



                    resultado = servico.addPacienteClienteAdmin(token, pacienteNovo);

                    if (resultado)
                    {
                        MessageBox.Show("O paciente foi adicionado com sucesso!", "Alterar Paciente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Não foi possível adicionar o paciente, a reverter alterações!", "Alterar Paciente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    limparCamposPaciente();
                    preenchePacientes();
                    unblockPanelGestaoPaciente();
                    isNovoPaciente = false;
                    pacienteNovo   = null;
                }


                else if (isEditarPaciente)
                {
                    if (p != null)
                    {
                        p.nome     = txt_nome_paciente.Text;
                        p.cc       = txt_cc_paciente.Text;
                        p.telefone = txt_telefone_paciente.Text;
                        p.dataNasc = getDataString(dt_dataNasc_paciente.Value);
                        p.morada   = rich_morada_paciente.Text;

                        if (radioM_paciente.Checked)
                        {
                            p.sexo = "H";
                        }
                        else
                        {
                            p.sexo = "M";
                        }



                        resultado = servico.editPacienteClienteAdmin(token, p);

                        if (resultado)
                        {
                            MessageBox.Show("O paciente foi alterado com sucesso!", "Alterar Paciente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Não foi possível alterar o paciente, a reverter alterações!", "Alterar Paciente", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        limparCamposPaciente();
                        preenchePacientes();
                        unblockPanelGestaoPaciente();
                        isEditarPaciente = false;
                        p = null;
                    }
                }
            }
        }