예제 #1
0
        private void btnAddParent_Click(object sender, EventArgs e)
        {
            int parentID = int.Parse(comboParents.SelectedItem.ToString().Split(' ')[0]);

            try
            {
                StudentDAL.AddParent(this.StudentID, parentID);
                MessageBox.Show("Parent successfully added!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        private void btnAddNewParent_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtLastName.Text.Length == 0 || txtFirstName.Text.Length == 0 || txtPatronymic.Text.Length == 0)
                {
                    throw new ArgumentException("FIO fields can't be null!");
                }
                if (txtEmail.Text.Length == 0)
                {
                    throw new ArgumentException("Email is required!");
                }
                if (txtPassword.Text.Length == 0)
                {
                    throw new ArgumentException("Password is required!");
                }
                if (!Util.IsValidEmail(txtEmail.Text))
                {
                    throw new ArgumentException("Email is not valid!");
                }
                User basicUserInfo = new User
                {
                    LastName    = txtLastName.Text,
                    FirstName   = txtFirstName.Text,
                    Patronymic  = txtPatronymic.Text,
                    DateOfBirth = dateTimePickerBirth.Value.Year == 9998 ? null : new DateTime?(dateTimePickerBirth.Value),
                    Email       = txtEmail.Text,
                    Password    = txtPassword.Text,
                    Phone       = txtPhone.Text
                };

                Parent p = new Parent
                {
                    user = basicUserInfo,
                    Job  = txtJob.Text
                };

                ParentDAL.AddNewParent(p);
                StudentDAL.AddParent(this.StudentID, p.ParentID);
                MessageBox.Show("Parent successfully added!", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }