private void UpdateStudentDropdown()
 {
     cmbStudents.Items.Clear();
     foreach (var stu in P110.GetStudents())
     {
         cmbStudents.Items.Add(stu.Id + " - " + stu.Fullname);
     }
 }
        private void cmbStudents_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedStudentId = cmbStudents.Text.Substring(0, 4);

            StudentToUpdate = P110.GetStudentById(selectedStudentId);

            if (StudentToUpdate != null)
            {
                txtFirstname.Text = StudentToUpdate.Firstname;
                txtLastname.Text  = StudentToUpdate.Lastname;
                txtEmail.Text     = StudentToUpdate.Email;
                dtBirthdate.Value = StudentToUpdate.Birthdate;

                pnlEdit.Visible = true;
            }
        }
Esempio n. 3
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string   firstname = txtFirstname.Text.Trim();
            string   lastname  = txtLastname.Text.Trim();
            string   email     = txtEmail.Text.Trim();
            DateTime birthdate = dtBirthdate.Value;

            //Firstname and lastname validation
            if (firstname == string.Empty)
            {
                MessageBox.Show("Firstname is empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lastname == string.Empty)
            {
                MessageBox.Show("Lastname is empty", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Email validation
            try
            {
                MailAddress mail = new MailAddress(email);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Email is not valid", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Validation is OK, Create Student and Add student
            Student student = new Student
            {
                Firstname = firstname,
                Lastname  = lastname,
                Email     = email,
                Birthdate = birthdate
            };

            P110.AddStudent(student);
            ResetAddStudentControls();

            //update DataGridView to show new Student
            dgwStudents.DataSource = null;
            dgwStudents.DataSource = P110.GetStudents();
        }
Esempio n. 4
0
        private void Dashboard_Load(object sender, EventArgs e)
        {
            #region Update Maximum Date of birthdate
            var today = DateTime.Now.AddDays(1);
            dtBirthdate.MaxDate = today;
            #endregion

            #region Filling listBoxControl with Students
            //foreach (var stu in P110.GetStudents())
            //{
            //    lbStudent2.Items.Add(stu);
            //}
            //lbStudent2.DataSource = P110.GetStudents();
            //lbStudent2.DisplayMember = "Email";
            #endregion

            dgwStudents.DataSource = P110.GetStudents();
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are You sure to delete student?", "Confirmation!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                string selectedStudentId = cmbStudents.Text.Substring(0, 4);

                if (P110.DeleteStudentById(selectedStudentId))
                {
                    UpdateStudentDropdown();
                }
                else
                {
                    MessageBox.Show("Not found");
                }
            }
        }
Esempio n. 6
0
 private void UpdateDatagridWhenFormClosed(object sender, EventArgs e)
 {
     dgwStudents.DataSource = null;
     dgwStudents.DataSource = P110.GetStudents();
 }