Beispiel #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            STUDENT  student = new STUDENT();
            int      Id      = Convert.ToInt32(textBoxId.Text);
            string   fname   = textBoxFName.Text;
            string   lname   = textBoxLName.Text;
            DateTime bdate   = dateTimePicker1.Value;
            string   phone   = textBoxPhone.Text;
            string   adrs    = textBoxAddress.Text;
            string   gender  = "Male";

            if (radioButton2.Checked)
            {
                gender = "Female";
            }
            MemoryStream pic       = new MemoryStream();
            int          born_year = dateTimePicker1.Value.Year;
            int          this_year = DateTime.Now.Year;

            if ((this_year - born_year < 10) || ((this_year - born_year) > 100))
            {
                MessageBox.Show("The Student Age Must Be Between 10 and 100 year", "Invalid Birth Date",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (verif())
            {
                pictureBox1.Image.Save(pic, pictureBox1.Image.RawFormat);
                if (student.insertStudent(Id, fname, lname, bdate, gender, phone, adrs, 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);
            }
        }