protected void btnRegister_Click(object sender, EventArgs e)
    {
        Usermodel mdl = new Usermodel();

        mdl.first_name = txtFName.Text;
        mdl.last_name  = txtLName.Text;
        mdl.Password   = txtPassword.Text;
        mdl.Email      = txtEmail.Text;
        mdl.Address    = txtAddress.Text;

        int result = UserBLO.CreateUser(mdl);

        if (result == 1)
        {
            if (!ClientScript.IsStartupScriptRegistered("alert"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
                                                        "alert", "alertMe();", true);
            }
        }
    }
Exemple #2
0
        private void txtCreate_Click(object sender, EventArgs e)
        {
            try
            {
                checkForm();
                txtUsername.Focus();

                if (txtPassword != txtConfirmPassword &&
                    string.IsNullOrEmpty(txtUsername.Text) &&
                    string.IsNullOrEmpty(txtPassword.Text) &&
                    string.IsNullOrEmpty(txtConfirmPassword.Text))
                {
                    MessageBox.Show
                    (
                        "- Please Confirm password !" +
                        "- field can't empty",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                    );
                }
                else
                {
                    User newUser = new User
                                   (
                        txtUsername.Text.ToUpper(),
                        txtPassword.Text,
                        txtConfirmPassword.Text
                                   );

                    UserBLO userBLO = new UserBLO(ConfigurationManager.AppSettings["DbFolder"]);

                    if (this.oldUser == null)
                    {
                        userBLO.CreateUser(newUser);
                    }
                    else
                    {
                        userBLO.EditUser(oldUser, newUser);
                    }

                    MessageBox.Show
                    (
                        "Compte creer",
                        "Confirmation",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                    );

                    if (callBack != null)
                    {
                        callBack();
                    }

                    if (oldUser != null)
                    {
                        Close();
                    }
                    txtUsername.Clear();
                    txtPassword.Clear();
                    txtConfirmPassword.Clear();
                    Form f = new FrmParent();
                    f.Show();
                    this.Hide();
                }
            }
            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (DuplicateNameException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Duplicate error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    "An error occurred! Please try again later.",
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }