示例#1
0
        private async void listTeachers(TeacherQueryParameters filters)
        {
            try
            {
                var apiPath = RestService.For <ApiService>(Routes.baseUrl);
                if (filters == null)
                {
                    var dataResponse = await apiPath.GetTeachersAsync();

                    teachers = JsonConvert.DeserializeObject <TeachersApiResponse[]>(dataResponse.ToString());
                }
                else
                {
                    var dataResponse = await apiPath.GetTeachersFilteredAsync(filters);

                    teachers = JsonConvert.DeserializeObject <TeachersApiResponse[]>(dataResponse.ToString());
                }

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

                if (teachers.Length == 0)
                {
                    Label noTeachers = new Label();
                    noTeachers.Name     = "noTeachers";
                    noTeachers.Text     = "Não há professores cadastrados!";
                    noTeachers.Font     = new Font(Styles.defaultFont.FontFamily, Convert.ToInt32(Styles.defaultFont.SizeInPoints));
                    noTeachers.AutoSize = true;
                    noTeachers.Location = new Point(20, 20);
                    centralPanel.Controls.Add(noTeachers);
                }
                else
                {
                    int i;
                    for (i = 0; i < teachers.Length; i++)
                    {
                        TeachersApiResponse teachersData = teachers[i];

                        Teachers serie = new Teachers(teachersData.Nome, teachersData.Telefone, teachersData.Email, teachersData.RG, teachersData.Foto, 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("Um erro occoreu: " + ex.ToString());
            }
        }
示例#2
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 == "noTeachers")
                {
                    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;

            TeacherQueryParameters filters = new TeacherQueryParameters();

            if (textBox1_Nome.Text.Trim() != "")
            {
                filters.Nome = textBox1_Nome.Text.Trim();
            }
            if (textBox2_Telefone.Text.Trim() != "")
            {
                filters.Telefone = textBox2_Telefone.Text.Trim();
            }
            if (textBox3_Email.Text.Trim() != "")
            {
                filters.Email = textBox3_Email.Text.Trim();
            }
            if (textBox4_RG.Text.Trim() != "")
            {
                filters.RG = textBox4_RG.Text.Trim();
            }

            listTeachers(filters);
        }
示例#3
0
        private async void finishTeacherCreation_Click(object sender, EventArgs e)
        {
            TeacherQueryParameters data = new TeacherQueryParameters();

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

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

            for (int i = 0; i < creationPanel.Controls.Count; i++)
            {
                if (creationPanel.Controls[i].Name.Contains("textBox"))
                {
                    if (creationPanel.Controls[i].Name.Contains("Nome"))
                    {
                        if (creationPanel.Controls[i].Text.Trim() == "")
                        {
                            MessageBox.Show("O nome é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.Nome = creationPanel.Controls[i].Text.Trim();
                        }
                    }

                    else if (creationPanel.Controls[i].Name.Contains("Telefone"))
                    {
                        if (creationPanel.Controls[i].Text.Trim() == "")
                        {
                            MessageBox.Show("O telefone é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.Telefone = creationPanel.Controls[i].Text.Trim();
                        }
                    }

                    else if (creationPanel.Controls[i].Name.Contains("RG"))
                    {
                        if (creationPanel.Controls[i].Text.Trim() == "")
                        {
                            MessageBox.Show("O RG é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.RG = creationPanel.Controls[i].Text.Trim();
                        }
                    }

                    else if (creationPanel.Controls[i].Name.Contains("Email"))
                    {
                        if (creationPanel.Controls[i].Text.Trim() == "")
                        {
                            MessageBox.Show("O email é obrigatório!");
                            return;
                        }
                        else
                        {
                            data.Email = creationPanel.Controls[i].Text.Trim();
                        }
                    }
                }
            }
            if (!imageUrl.Trim().Equals(""))
            {
                data.Foto = imageUrl;
            }
            else
            {
                MessageBox.Show("A imagem não pode ser vazia!");
                return;
            }

            var apiPath = RestService.For <ApiService>(Routes.baseUrl);

            try
            {
                bool isOk = true;

                for (int i = 0; i < teachers.Length; i++)
                {
                    if (teachers[i].RG == data.RG)
                    {
                        isOk = false;
                        MessageBox.Show("O RG já existe no banco de dados!");
                        break;
                    }
                    if (teachers[i].Email == data.Email)
                    {
                        isOk = false;
                        MessageBox.Show("O Email já existe no banco de dados!");
                        break;
                    }
                    if (teachers[i].Telefone == data.Telefone)
                    {
                        isOk = false;
                        MessageBox.Show("O Telefone já existe no banco de dados!");
                        break;
                    }
                }

                if (isOk)
                {
                    Panel  p = new Panel();
                    Button b = new Button();
                    for (int i = 0; i < parentForm.Controls.Count; i++)
                    {
                        if (parentForm.Controls[i].Name == "creationTeacherPanel")
                        {
                            p = (Panel)parentForm.Controls[i];
                            break;
                        }
                    }
                    for (int i = 0; i < p.Controls.Count; i++)
                    {
                        if (p.Controls[i].Name == "finishTeacherCreation")
                        {
                            b = (Button)p.Controls[i];
                            break;
                        }
                    }

                    b.Text    = "Aguarde...";
                    b.Enabled = false;

                    var dataResponse = await apiPath.InsertTeachersAsync(data);

                    var response = JsonConvert.DeserializeObject <ApiMessageResponse>(dataResponse.ToString());
                    MessageBox.Show(response.Message);
                    for (int i = 0; i < parentForm.Controls.Count; i++)
                    {
                        if (parentForm.Controls[i].Name == "creationTeacherPanel")
                        {
                            parentForm.Controls.Remove(parentForm.Controls[i]);
                            filterButton.PerformClick();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }