Exemple #1
0
        private async void GetPorCodigo()
        {
            try
            {
                URI = txtURI.Text;


                if (String.IsNullOrEmpty(URI))
                {
                    MessageBox.Show("Preencha o campo URI!");
                }
                else
                {
                    BindingSource bsDados = new BindingSource();
                    URI      = txtURI.Text + "?codigo=" + txtConsultarPorCodigo.Text;
                    response = await cliente.GetAsync(URI);

                    if (response.IsSuccessStatusCode)
                    {
                        var projetoJSONString = await response.Content.ReadAsStringAsync();

                        AlunoEProfessor alEProf = JsonConvert.DeserializeObject <AlunoEProfessor>(projetoJSONString);
                        gvConsultaProjetos.Columns.Clear();
                        gvConsultaProjetos.DataSource = null;

                        gvConsultaProjetos.RowCount    = 1;
                        gvConsultaProjetos.ColumnCount = 0;

                        int i;

                        for (i = 0; i < alEProf.QtosAlunos; i++)
                        {
                            gvConsultaProjetos.ColumnCount++;
                            gvConsultaProjetos.Columns[i].HeaderText  = "Aluno " + (i + 1);
                            gvConsultaProjetos.Rows[0].Cells[i].Value = "RA: " + alEProf.Alunos[i].Ra;
                        }

                        for (int j = 0; j < alEProf.QtosProfs; j++, i++)
                        {
                            gvConsultaProjetos.ColumnCount++;
                            gvConsultaProjetos.Columns[i].HeaderText  = "Prof. " + (j + 1);
                            gvConsultaProjetos.Rows[0].Cells[i].Value = "Código: " + alEProf.Professores[j].Codigo.ToString();
                        }
                    }
                    else
                    {
                        throw new Exception(response.ReasonPhrase);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemple #2
0
        private async void SelecionarProjetoParaAlterar()
        {
            try
            {
                URI = txtURI.Text;


                if (String.IsNullOrEmpty(URI))
                {
                    MessageBox.Show("Preencha o campo URI!");
                }
                else
                {
                    URI      = txtURI.Text + "?codigoProjetoParaSelecionarDados=" + txtAlterarCodigoProjeto.Text;
                    response = await cliente.GetAsync(URI);

                    if (response.IsSuccessStatusCode)
                    {
                        string projetoJSONString = await response.Content.ReadAsStringAsync();

                        Projeto proj = JsonConvert.DeserializeObject <Projeto>(projetoJSONString);

                        txtAlterarNome.Text      = proj.Nome;
                        txtAlterarAno.Text       = proj.Ano;
                        txtAlterarDescricao.Text = proj.Descricao;
                    }
                    else
                    {
                        throw new Exception("Houve um erro na ação! Verifique se existe um curso com tal código!");
                    }

                    BindingSource bsDados = new BindingSource();
                    URI      = txtURI.Text + "?codigo=" + txtAlterarCodigoProjeto.Text;
                    response = await cliente.GetAsync(URI);

                    if (response.IsSuccessStatusCode)
                    {
                        var projetoJSONString = await response.Content.ReadAsStringAsync();

                        AlunoEProfessor alEProf = JsonConvert.DeserializeObject <AlunoEProfessor>(projetoJSONString);

                        gvAlterarAlunosEProfessores.Columns.Clear();
                        gvAlterarAlunosEProfessores.DataSource = null;

                        gvAlterarAlunosEProfessores.RowCount    = 1;
                        gvAlterarAlunosEProfessores.ColumnCount = 0;

                        int i;

                        for (i = 0; i < alEProf.QtosAlunos; i++)
                        {
                            gvAlterarAlunosEProfessores.ColumnCount++;
                            gvAlterarAlunosEProfessores.Columns[i].HeaderText  = "Aluno " + (i + 1);
                            gvAlterarAlunosEProfessores.Rows[0].Cells[i].Value = "RA: " + alEProf.Alunos[i].Ra;
                        }

                        for (int j = 0; j < alEProf.QtosProfs; j++, i++)
                        {
                            gvAlterarAlunosEProfessores.ColumnCount++;
                            gvAlterarAlunosEProfessores.Columns[i].HeaderText  = "Prof. " + (j + 1);
                            gvAlterarAlunosEProfessores.Rows[0].Cells[i].Value = "Código: " + alEProf.Professores[j].Codigo.ToString();
                        }
                    }
                    else
                    {
                        throw new Exception("Houve um erro! Verifique se existe um curso com esse código!");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }