Beispiel #1
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (RegValidate())
            {
                try
                {
                    UserSystem usrsys = new UserSystem();
                    var        usr    = usrsys.Register(txtLoginReg.Text, txtPassReg.Text, txtEmail.Text);
                    usr.Name     = txtName.Text;
                    usr.Surname  = txtSurname.Text;
                    usr.SchoolId = ddlSchools.SelectedIndex;
                    usrsys.Update(usr.UserName, usr);
                    if (!String.IsNullOrEmpty(txtPolecacz.Text))
                    {
                        usrsys.addPolecacz(usr.UserName, txtPolecacz.Text);
                    }
                    clearForms();
                    lblSuccess.Text     = "Zarejestrowano pomyślnie.";
                    lblErrorReg.Visible = false;
                    lblSuccess.Visible  = true;
                }
                catch (System.Data.SqlClient.SqlException sqle)
                {
                    lblErrorReg.Text    = "Wystąpił nieoczekiwany błąd. (SQL)";
                    lblErrorReg.Visible = true;
                }
                catch (UserException ue)
                {
                    string ErrorMssg = "";
                    switch (ue.Type)
                    {
                    case UserException.UserExceptionType.Unknown:
                        ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                        break;

                    case UserException.UserExceptionType.UserAlreadyExists:
                        ErrorMssg = "Użytkownik o takim loginie już istnieje.";
                        break;

                    case UserException.UserExceptionType.EmailAlreadyTaken:
                        ErrorMssg = "Podany e-mail jest już zajęty.";
                        break;

                    default:
                        ErrorMssg = "Wystąpił nieoczekiwany błąd.";
                        break;
                    }
                    lblErrorReg.Text    = ErrorMssg;
                    lblErrorReg.Visible = true;
                }
            }
        }