Esempio n. 1
0
        private void filterButton_Click(object sender, EventArgs e)
        {
            int itemsCount = centralPanel.Controls.Count;

            for (int i = itemsCount - 1; i > 0; i--)
            {
                if (centralPanel.Controls[i].Name == "noSeries")
                {
                    centralPanel.Controls.Remove(centralPanel.Controls[i]);
                    continue;
                }

                Type objectType = centralPanel.Controls[i].GetType();

                if (objectType == typeof(Panel))
                {
                    centralPanel.Controls.Remove(centralPanel.Controls[i]);
                    itemsCount--;
                }
            }

            loadingText.Visible    = true;
            loadingCircle1.Visible = true;

            SerieQueryParameters filters = new SerieQueryParameters();

            filters.curso   = filterCurso;
            filters.ano     = filterAno;
            filters.periodo = filterPeriodo;
            filters.tipo    = filterTipo;

            listSeries(filters);
        }
Esempio n. 2
0
        private async void listSeries(SerieQueryParameters filters)
        {
            try
            {
                var apiPath = RestService.For <ApiService>(Routes.baseUrl);
                if (filters == null)
                {
                    var dataResponse = await apiPath.GetSeriesAsync();

                    series = JsonConvert.DeserializeObject <SeriesApiResponse[]>(dataResponse.ToString());
                }
                else
                {
                    var dataResponse = await apiPath.GetSeriesFilteredAsync(filters);

                    series = JsonConvert.DeserializeObject <SeriesApiResponse[]>(dataResponse.ToString());
                }

                loadingText.Visible    = false;
                loadingCircle1.Visible = false;


                if (series.Length == 0)
                {
                    Label noSeries = new Label();
                    noSeries.Name     = "noSeries";
                    noSeries.Text     = "Não há séries cadastradas!";
                    noSeries.Font     = new Font(Styles.defaultFont.FontFamily, Convert.ToInt32(Styles.defaultFont.SizeInPoints));
                    noSeries.AutoSize = true;
                    noSeries.Location = new Point(20, 20);
                    centralPanel.Controls.Add(noSeries);
                }
                else
                {
                    int i;
                    for (i = 0; i < series.Length; i++)
                    {
                        SeriesApiResponse serieData = series[i];

                        Series serie = new Series(serieData.Id, serieData.Curso, serieData.Tipo, serieData.Ano, serieData.Periodo, serieData.Sigla, serieData._count.Turmas, i);
                        centralPanel.Controls.Add(serie.getSeriePanel());
                    }
                    Panel panel = new Panel();
                    panel.Size     = new Size(1, 20);
                    panel.Location = new Point(20, (20 + Styles.seriesSize.Height) * (i));
                    centralPanel.Controls.Add(panel);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocorreu um erro durante a conexão com a base de dados. " + ex.Message);
            }
        }
Esempio n. 3
0
        private async void finishSerieCreation_Click(object sender, EventArgs e)
        {
            SerieQueryParameters data = new SerieQueryParameters();

            int   itemsCount    = parentForm.Controls.Count;
            Panel creationPanel = new Panel();

            for (int i = itemsCount - 1; i >= 0; i--)
            {
                if (parentForm.Controls[i].Name == "creationSeriePanel")
                {
                    creationPanel = (Panel)parentForm.Controls[i];
                    break;
                }
            }

            int selectedSerie = -1, selectedCurso = -1, selectedTipo = -1, selectedPeriodo = -1;

            for (int i = 0; i < creationPanel.Controls.Count; i++)
            {
                if (creationPanel.Controls[i].Name.Contains("comboBox"))
                {
                    if (creationPanel.Controls[i].Name.Contains("Ano"))
                    {
                        selectedSerie = ((ComboBox)creationPanel.Controls[i]).SelectedIndex;
                        if (selectedSerie == -1)
                        {
                            MessageBox.Show("O ano é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.ano = serie[selectedSerie];
                        }
                    }
                    else if (creationPanel.Controls[i].Name.Contains("Curso"))
                    {
                        selectedCurso = ((ComboBox)creationPanel.Controls[i]).SelectedIndex;
                        if (selectedCurso == -1)
                        {
                            MessageBox.Show("O curso é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.curso = courses[selectedCurso];
                        }
                    }
                    else if (creationPanel.Controls[i].Name.Contains("Tipo"))
                    {
                        selectedTipo = ((ComboBox)creationPanel.Controls[i]).SelectedIndex;
                        if (selectedTipo == -1)
                        {
                            MessageBox.Show("O tipo é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.tipo = type[selectedTipo];
                        }
                    }
                    else if (creationPanel.Controls[i].Name.Contains("Periodo"))
                    {
                        selectedPeriodo = ((ComboBox)creationPanel.Controls[i]).SelectedIndex;
                        if (selectedPeriodo == -1)
                        {
                            MessageBox.Show("O período é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.periodo = period[selectedPeriodo];
                        }
                    }
                }
            }
            var apiPath = RestService.For <ApiService>(Routes.baseUrl);

            var dataResponse = await apiPath.InsertSeriesAsync(data);

            for (int i = 0; i < parentForm.Controls.Count; i++)
            {
                if (parentForm.Controls[i].Name == "creationSeriePanel")
                {
                    parentForm.Controls.Remove(parentForm.Controls[i]);
                    filterButton.PerformClick();
                    break;
                }
            }

            var response = JsonConvert.DeserializeObject <ApiMessageResponse>(dataResponse.ToString());

            MessageBox.Show(response.Message);
        }