Ejemplo n.º 1
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(txtFirstName.Text))
            {
                errors.Add("First Name is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtLastName.Text))
            {
                errors.Add("Last Name is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtDepartmentName.Text))
            {
                errors.Add("Please select an DepartmentName.");
            }

            if (errors.Count > 0)
            {
                foreach (var error in errors)
                {
                    txtbErrors.Text = txtbErrors.Text + error + "\n";
                }

                return;
            }
            var op = StudentBLL.Update(new Student()
            {
                Id             = Guid.NewGuid(),
                FirstName      = txtFirstName.Text,
                LastName       = txtLastName.Text,
                DepartmentName = txtDepartmentName.Text
            });

            if (op.Code != "200")
            {
                MessageBox.Show("Error : " + op.Message);
            }
            else
            {
                MessageBox.Show("Employee is successfully updated");
            }

            myParentWindow.showData();
            this.Close();
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(txtFirstName.Text))
            {
                errors.Add("First Name is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtLastName.Text))
            {
                errors.Add("Last Name is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtLastName.Text))
            {
                errors.Add("Email Address is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtDepartmentName.Text))
            {
                errors.Add("Department Name is required.");
            }
            ;

            if (string.IsNullOrEmpty(txtContactNumber.Text))
            {
                errors.Add("Contact Number is required.");
            }
            ;
            if (cboGender.SelectedValue == null)
            {
                errors.Add("Please select a Gender.");
            }

            if (errors.Count > 0)
            {
                foreach (var error in errors)
                {
                    txtbErrors.Text = txtbErrors.Text + error + "\n";
                }

                return;
            }
            Gender gender = Gender.Male;

            if (cboGender.SelectedValue.ToString().ToLower() == "Female")
            {
                gender = Gender.Female;
            }

            var op = StudentBLL.Add(new Student()
            {
                Id             = Guid.NewGuid(),
                FirstName      = txtFirstName.Text,
                LastName       = txtLastName.Text,
                EmailAddress   = txtEmailAddress.Text,
                DepartmentName = txtDepartmentName.Text,
                ContactNumber  = txtContactNumber.Text,
                Gender         = gender
            });

            if (op.Code != "200")
            {
                MessageBox.Show("Error : " + op.Message);
            }
            else
            {
                MessageBox.Show("Employee is successfully added to table");
            }

            myParentWindow.showData();
            this.Close();
        }