예제 #1
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (var user in UserDAO.users)
                {
                    if (user.Username.Equals(txtUsername.Text, StringComparison.OrdinalIgnoreCase) && user.Password.Equals(txtPassword.Text))
                    {
                        txtUsername.Clear();
                        txtPassword.Clear();
                        txtUsername.Focus();

                        Form f = new FrmParent();
                        f.Show();

                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show
                        (
                            "Please Create your account",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );

                        Form f = new FrmAccount();
                        f.Show();
                    }
                }
            }
            catch
            {
                MessageBox.Show
                (
                    "Account not exist",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }
예제 #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
                );
            }
        }