protected void addBtn_Click(object sender, EventArgs e)
 {
     if (Page.IsValid) //Check if form is valid
     {
         try
         {
             if (userTypeDD.SelectedValue == "Child")
             {
                 childDAO.addChild(new Child(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                             surnameTxt.Text,
                                             birthDateTxt.Text, genderRadioBtnList.SelectedValue, "", new List <Grade>(),
                                             int.Parse(parentsDropdownList.SelectedValue))); //Add child to DB
             }
             if (userTypeDD.SelectedValue == "Parent")
             {
                 parentDAO.addParent(new Parent(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                                surnameTxt.Text, postcodeTxt.Text, telephoneTxt.Text, emailTxt.Text, "", new List <Child>())); //Add parent to DB
             }
             if (userTypeDD.SelectedValue == "Administrator")
             {
                 administratorDAO.addAdministrator(new Administrator(usernameTxt.Text, passwordTxt.Text)); //Add admin to DB
             }
             Session["SuccessAdd"] = true;                                                                 //If no exceptions set the session to successful - true
         }
         catch (Exception ex)
         {
             Session["SuccessAdd"] = false;
         }
         Session["Administrator"] = administrator;                 //Refresh the session for user
         Response.Redirect("~/AdministratorTools/AddAUser", true); //Refresh the form (clears the input fields and does !postback again)
     }
 }
Esempio n. 2
0
        protected void registerBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    Parent parent = new Parent(usernameTxt.Text, passwordTxt.Text, firstNameTxt.Text,
                                               surnameTxt.Text, postcodeTxt.Text, telephoneTxt.Text, emailTxt.Text, "", new List <Child>());
                    parentDAO.addParent(parent);

                    Session["SuccessRegister"] = true;
                    Session["Parent"]          = parentDAO.getParent(parent.Username, parent.Password); //Pass newly created parent
                }
                catch (Exception ex)
                {
                    Session["SuccessRegister"] = false;
                    Response.Redirect("~/Register.aspx", true);
                }
                Response.Redirect("~/RegisterChildren.aspx");
            }
        }
Esempio n. 3
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);
            }
        }