Exemplo n.º 1
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            //añadir nuevo estudiante
            STUDENT  student = new STUDENT();
            string   fname   = textBoxFname.Text;
            string   lname   = textBoxLname.Text;
            DateTime bdate   = dateTimePicker1.Value;
            string   phone   = maskedTextBoxPhone.Text;
            string   address = textBoxAddress.Text;
            string   gender  = "Male";

            if (radioButtonFemale.Checked)
            {
                gender = "Female";
            }

            MemoryStream pic = new MemoryStream();

            //la edad del estudiante debe ser entre 10 y 100
            int born_year = dateTimePicker1.Value.Year;
            int this_year = DateTime.Now.Year;

            if ((this_year - born_year) < 10)
            {
                MessageBox.Show("The student age most be over 10", "Invalid birthdate", MessageBoxButtons.OK);
            }
            else if ((this_year - born_year) >= 100)
            {
                MessageBox.Show("The student age most be below 100", "Invalid birthdate", MessageBoxButtons.OK);
            }
            else if (verifyData())
            {
                pictureBoxStudent.Image.Save(pic, pictureBoxStudent.Image.RawFormat);

                if (student.insertStudent(fname, lname, bdate, phone, gender, address, pic))
                {
                    MessageBox.Show("New Student Added", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty Fields", "Add Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        private void StaticsForm_Load(object sender, EventArgs e)
        {
            //colores del panel
            panTotalColor  = panelTotal.BackColor;
            panMaleColor   = panelMale.BackColor;
            panFemaleColor = panelFemale.BackColor;

            //desplegar los valores
            STUDENT student            = new STUDENT();
            double  totalStudents      = Convert.ToDouble(student.TotalStudents());
            double  totalMaleStudent   = Convert.ToDouble(student.TotalMaleStudents());
            double  totalFemaleStudent = Convert.ToDouble(student.TotalFemaleStudents());

            //contar % de estudiantes
            double malePercentage   = totalMaleStudent * 100 / totalStudents;
            double femalePercentage = totalFemaleStudent * 100 / totalStudents;

            labelTotal.Text  = "Total Students: " + totalStudents.ToString();
            labelMale.Text   = "Male: " + malePercentage.ToString("0.00") + "%";
            labelFemale.Text = "Female:" + femalePercentage.ToString("0.00") + "%";
        }