Beispiel #1
0
        protected void editBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) //Check if form is valid
            {
                try
                {
                    if (childEdit != null)
                    {
                        if (userTypeDD.SelectedValue == "Child")
                        {
                            childEdit.Username  = usernameTxt.Text;
                            childEdit.Password  = passwordTxt.Text;
                            childEdit.FirstName = firstNameTxt.Text;
                            childEdit.Surname   = surnameTxt.Text;
                            childEdit.BirthDate = birthDateTxt.Text;
                            childEdit.Gender    = genderRadioBtnList.SelectedValue;
                            childDAO.updateChild(childEdit);
                        }
                        if (userTypeDD.SelectedValue == "Parent")
                        {
                            childDAO.deleteChild(childEdit.ID);

                            parentDAO = new ParentDAOImpl();
                            parentDAO.addParent(new Parent(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                                           surnameTxt.Text, postcodeTxt.Text, telephoneTxt.Text, emailTxt.Text, "",
                                                           new List <Child>()));
                        }
                        if (userTypeDD.SelectedValue == "Administrator")
                        {
                            childDAO.deleteChild(childEdit.ID);

                            administratorDAO = new AdministratorDAOImpl();
                            administratorDAO.addAdministrator(new Administrator(usernameTxt.Text, passwordTxt.Text));
                        }
                    }

                    if (parentEdit != null)
                    {
                        if (userTypeDD.SelectedValue == "Child")
                        {
                            parentDAO.deleteParent(parentEdit.ID);
                            childDAO = new ChildDAOImpl();
                            childDAO.addChild(new Child(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                                        surnameTxt.Text,
                                                        birthDateTxt.Text, genderRadioBtnList.SelectedValue, "", new List <Grade>(),
                                                        int.Parse(parentsDropdownList.SelectedValue)));
                        }
                        if (userTypeDD.SelectedValue == "Parent")
                        {
                            parentEdit.Username  = usernameTxt.Text;
                            parentEdit.Password  = passwordTxt.Text;
                            parentEdit.FirstName = firstNameTxt.Text;
                            parentEdit.Surname   = surnameTxt.Text;
                            parentEdit.Postcode  = postcodeTxt.Text;
                            parentEdit.Telephone = telephoneTxt.Text;
                            parentEdit.Email     = emailTxt.Text;
                            parentDAO.updateParent(parentEdit);
                        }
                        if (userTypeDD.SelectedValue == "Administrator")
                        {
                            parentDAO.deleteParent(parentEdit.ID);
                            administratorDAO = new AdministratorDAOImpl();
                            administratorDAO.addAdministrator(new Administrator(usernameTxt.Text, passwordTxt.Text));
                        }
                    }
                    if (administratorEdit != null)
                    {
                        if (userTypeDD.SelectedValue == "Child")
                        {
                            administratorDAO.deleteAdministrator(administratorEdit.ID);

                            childDAO = new ChildDAOImpl();
                            childDAO.addChild(new Child(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                                        surnameTxt.Text,
                                                        birthDateTxt.Text, genderRadioBtnList.SelectedValue, "", new List <Grade>(),
                                                        int.Parse(parentsDropdownList.SelectedValue)));
                        }
                        if (userTypeDD.SelectedValue == "Parent")
                        {
                            administratorDAO.deleteAdministrator(administratorEdit.ID);

                            parentDAO = new ParentDAOImpl();
                            parentDAO.addParent(new Parent(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                                           surnameTxt.Text, postcodeTxt.Text, telephoneTxt.Text, emailTxt.Text, "",
                                                           new List <Child>()));
                        }
                        if (userTypeDD.SelectedValue == "Administrator")
                        {
                            administratorEdit.Username = usernameTxt.Text;
                            administratorEdit.Password = passwordTxt.Text;
                            administratorDAO.updateAdministrator(administratorEdit);
                        }
                    }
                    Session["SuccessEdit"] = true;
                }
                catch (Exception ex)
                {
                    Session["SuccessEdit"] = false;
                }
                Response.Redirect("~/AdministratorTools/EditAUser", true);
            }
        }