Пример #1
0
        private void txtIban_TextChanged(object sender, EventArgs e)
        {
            if (txtIban.Text.Count() == 8 && cboList.SelectedIndex != -1)
            {
                DatabaseManagement database = new DatabaseManagement();
                database.OpenConnection();

                string destEmail = database.EmailFromIban(txtIban.Text.ToUpper());

                database.CloseConnection();
                if (destEmail != null && userInfo.Email != destEmail)
                {
                    lblNameUser.Text     = $"Vous allez ajouter :\n{destEmail}";
                    cmdAddToList.Enabled = true;
                }
                else
                {
                    lblNameUser.Text     = "";
                    cmdAddToList.Enabled = false;
                }
                if (txtIban.Text.ToUpper() == userInfo.Iban)
                {
                    lblNameUser.Text = "Vous ne pouvez vous ajouter à la liste";
                }
            }
            else
            {
                lblNameUser.Text     = "";
                cmdAddToList.Enabled = false;
            }
        }
Пример #2
0
        private void cmdPay_Click(object sender, EventArgs e)
        {
            if (cboPayList.SelectedIndex == 0 || cboPayList.SelectedIndex == -1)
            {
                if (userInformations.Money >= Convert.ToDouble(updPayAmount.Value))
                {
                    DatabaseManagement database = new DatabaseManagement();
                    database.OpenConnection();

                    bool success = database.Transact(Convert.ToDouble(updPayAmount.Value), txtPayReason.Text, userInformations.Iban, txtPayIban.Text);

                    if (success)
                    {
                        userInformations = (PublicUser)database.GetUser(userInformations.Email);
                    }

                    database.CloseConnection();

                    updateInfos();

                    txtPayIban.Text    = "";
                    updPayAmount.Value = 1;
                    txtPayReason.Text  = "";
                }
                else
                {
                    MessageBox.Show("Vous n'avez pas assez d'argent pour effectuer cette transaction", "Erreur");
                }
            }
            else
            {
                if (userInformations.Money >= Convert.ToDouble(((UsersList)cboPayList.SelectedItem).Users.Count() * updPayAmount.Value))
                {
                    foreach (User user in ((UsersList)cboPayList.SelectedItem).Users)
                    {
                        DatabaseManagement database = new DatabaseManagement();
                        database.OpenConnection();

                        bool success = database.Transact(Convert.ToDouble(updPayAmount.Value), txtPayReason.Text, userInformations.Iban, user.Iban);

                        if (success)
                        {
                            userInformations = (PublicUser)database.GetUser(userInformations.Email);
                        }

                        database.CloseConnection();

                        updateInfos();
                    }
                    updPayAmount.Value       = 1;
                    txtPayReason.Text        = "";
                    cboPayList.SelectedIndex = 0;
                    txtPayIban.Text          = "";
                }
                else
                {
                    MessageBox.Show("Vous n'avez pas assez d'argent pour effectuer cette transaction", "Erreur");
                }
            }
        }
Пример #3
0
        private void cmdAddToListMethod()
        {
            if (((UsersList)cboList.SelectedItem).Users.All(item => item.Iban != txtIban.Text.ToUpper()))
            {
                DatabaseManagement database = new DatabaseManagement();
                database.OpenConnection();


                database.AddUserList(((UsersList)cboList.SelectedItem).Name, txtIban.Text.Trim());
                userInfo = (EnterpriseUser)database.GetUser(userInfo.Email);

                database.CloseConnection();

                int selectedList = cboList.SelectedIndex;

                displayEnterpriseLists();
                cboList.SelectedIndex = selectedList;
                displayUsersLists();

                txtIban.Text         = "";
                lblNameUser.Text     = "L'utilisateur a bien été ajouté";
                cmdAddToList.Enabled = false;
            }
            else
            {
                MessageBox.Show("Cet utilisateur est déjà dans cette liste");
            }
        }
Пример #4
0
        private void cmdModifyMonney_Click(object sender, EventArgs e)
        {
            FrmAdminMoneyChanger form = new FrmAdminMoneyChanger(userInformations);

            form.ShowDialog();

            DatabaseManagement database = new DatabaseManagement();

            database.OpenConnection();

            userInformations = (AdminUser)database.GetUser(userInformations.Email);

            database.CloseConnection();

            updateInfos();
        }
Пример #5
0
        private void cmdModifyList_Click(object sender, EventArgs e)
        {
            FrmListManagement Listform = new FrmListManagement((EnterpriseUser)userInformations);

            Listform.ShowDialog();

            DatabaseManagement database = new DatabaseManagement();

            database.OpenConnection();

            userInformations = (EnterpriseUser)database.GetUser(userInformations.Email);

            database.CloseConnection();

            displayEnterpriseLists();
        }
Пример #6
0
        private void cmdChangeAmount_Click(object sender, EventArgs e)
        {
            int flag = 0;

            lblError.Text = "";

            txtUserEmail.BackColor = Color.FromArgb(255, 255, 255);

            if (txtUserEmail.Text.Trim() == "")
            {
                txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text          = "Champ(s) incomplet(s)";
                flag++;
            }
            if (flag == 0)
            {
                lblError.Text          = "";
                txtUserEmail.BackColor = Color.FromArgb(255, 255, 255);

                try
                {
                    DatabaseManagement database = new DatabaseManagement();

                    database.OpenConnection();

                    if (database.ChangeMoney(txtUserEmail.Text.Trim(), (double)updAmount.Value))
                    {
                        lblError.Text     = "Le solde a été changé";
                        txtUserEmail.Text = "";
                        updAmount.Value   = 0;
                    }
                    else
                    {
                        lblError.Text          = "Utilisateur introuvable";
                        txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                    }

                    database.CloseConnection();
                }
                catch (UnableToJoinDatabase)
                {
                    lblError.Text          = "La base de données est injoignable";
                    txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                }
            }
        }
Пример #7
0
        private void cmdDeleteAccount_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Êtes-vous sûr de vouloir effacer votre compte ?\nVotre argent ne sera plus accessible.",
                                                        "Effacer votre compte", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                DatabaseManagement database = new DatabaseManagement();
                database.OpenConnection();

                database.DisableAccount(userInfos.Email);

                database.CloseConnection();

                MessageBox.Show("Au revoir", "Merci");
                Application.Exit();
            }
        }
Пример #8
0
        private void cmdDeleteList_Click(object sender, EventArgs e)
        {
            DatabaseManagement database = new DatabaseManagement();

            database.OpenConnection();


            database.DeleteList(((UsersList)cboList.SelectedItem).Name);
            userInfo = (EnterpriseUser)database.GetUser(userInfo.Email);

            database.CloseConnection();

            displayEnterpriseLists();
            lstList.Items.Clear();
            cmdListToDelete.Enabled = false;
            cmdDeleteList.Enabled   = false;
            cmdAddToList.Enabled    = false;
            txtIban.Enabled         = false;
        }
Пример #9
0
        private void cmdListToDelete_Click(object sender, EventArgs e)
        {
            DatabaseManagement database = new DatabaseManagement();

            database.OpenConnection();

            database.DeleteUserList(((UsersList)cboList.SelectedItem).Name, ((User)lstList.SelectedItem).Iban);

            userInfo = (EnterpriseUser)database.GetUser(userInfo.Email);

            database.CloseConnection();

            int selectedList = cboList.SelectedIndex;

            displayEnterpriseLists();
            cboList.SelectedIndex = selectedList;
            displayUsersLists();

            cmdListToDelete.Enabled = false;
        }
Пример #10
0
        private void cmdAddList_Click(object sender, EventArgs e)
        {
            DatabaseManagement database = new DatabaseManagement();

            database.OpenConnection();

            try
            {
                database.CreateList(txtNameList.Text.Trim(), userInfo.Iban);
                userInfo = (EnterpriseUser)database.GetUser(userInfo.Email);

                database.CloseConnection();
            }
            catch (ListAlreadyExistsException)
            {
                MessageBox.Show("Ce nom de liste existe déjà");
            }

            displayEnterpriseLists();
            lstList.Items.Clear();
            txtNameList.Text = "";
        }
Пример #11
0
        private void txtPayIban_TextChanged(object sender, EventArgs e)
        {
            if (txtPayIban.Text.Count() == 8)
            {
                DatabaseManagement database = new DatabaseManagement();
                database.OpenConnection();

                string destEmail = database.EmailFromIban(txtPayIban.Text.ToUpper());

                database.CloseConnection();

                if (destEmail != null && userInformations.Email != destEmail)
                {
                    lblEmailReceiver.Text = $"Vous allez faire un payement a :\n{destEmail}";

                    cmdPay.Enabled = true;
                }
                else if (userInformations.Email == destEmail)
                {
                    lblEmailReceiver.Text = "Opération non possible";

                    cmdPay.Enabled = false;
                }
                else
                {
                    lblEmailReceiver.Text = "L'Iban que vous avez entré ne correspond à personne,\nveuillez vérifiez l'Iban";

                    cmdPay.Enabled = false;
                }
            }
            else
            {
                lblEmailReceiver.Text = "";

                cmdPay.Enabled = false;
            }
        }
        private void cmdChangePassword_Click(object sender, EventArgs e)
        {
            int flag = 0;

            lblError.Text = "";

            txtUserEmail.BackColor         = Color.FromArgb(255, 255, 255);
            txtNewPassword.BackColor       = Color.FromArgb(255, 255, 255);
            txtNewPasswordVerify.BackColor = Color.FromArgb(255, 255, 255);

            if (txtNewPassword.Text.Trim() != txtNewPasswordVerify.Text.Trim())
            {
                lblError.Text = "Les mots de passes sont différents";
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (txtNewPassword.Text.Count() < 8)
            {
                lblError.Text                  = "Votre mot de passe est trop court, 8 caractères minimum";
                txtNewPassword.BackColor       = Color.FromArgb(255, 128, 128);
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (txtUserEmail.Text.Trim() == "")
            {
                txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text          = "Champ(s) incomplet(s)";
                flag++;
            }
            if (txtNewPassword.Text.Trim() == "")
            {
                txtNewPassword.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text            = "Champ(s) incomplet(s)";
                flag++;
            }
            if (txtNewPasswordVerify.Text.Trim() == "")
            {
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text = "Champ(s) incomplet(s)";
                flag++;
            }
            if (flag == 0)
            {
                lblError.Text            = "";
                txtUserEmail.BackColor   = Color.FromArgb(255, 255, 255);
                txtNewPassword.BackColor = Color.FromArgb(255, 255, 255);

                try
                {
                    DatabaseManagement database = new DatabaseManagement();

                    database = new DatabaseManagement();

                    database.OpenConnection();

                    if (database.ChangePassword(txtUserEmail.Text.Trim(), txtNewPassword.Text.Trim()))
                    {
                        lblError.Text             = "Le mot de passe a été changé";
                        txtUserEmail.Text         = "";
                        txtNewPassword.Text       = "";
                        txtNewPasswordVerify.Text = "";
                    }
                    else
                    {
                        lblError.Text          = "Utilisateur introuvable";
                        txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                    }

                    database.CloseConnection();
                }
                catch (UnableToJoinDatabase)
                {
                    lblError.Text          = "La base de données est injoignable";
                    txtUserEmail.BackColor = Color.FromArgb(255, 128, 128);
                }
            }
        }
Пример #13
0
        private void cmdRegister_Click(object sender, EventArgs e)
        {
            int flag = 0;

            lblError.Text = "";

            txtEmail.BackColor          = Color.FromArgb(255, 255, 255);
            txtPassword.BackColor       = Color.FromArgb(255, 255, 255);
            txtPasswordVerify.BackColor = Color.FromArgb(255, 255, 255);

            if (password.Trim() != passwordVerify.Trim())
            {
                lblError.Text = "Les mots de passes sont différents";
                txtPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (password.Count() < 8)
            {
                lblError.Text               = "Votre mot de passe est trop court, 8 caractères minimum";
                txtPassword.BackColor       = Color.FromArgb(255, 128, 128);
                txtPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (txtEmail.Text.ToLower().Trim() == "")
            {
                txtEmail.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text      = "Champ(s) incomplet(s)";
                flag++;

                //lblError.Text = "Erreur lors de la création du compte";
            }
            if (password.Trim() == "")
            {
                txtPassword.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text         = "Champ(s) incomplet(s)";
                flag++;

                //lblError.Text = "Erreur lors de la création du compte";
            }
            if (passwordVerify.Trim() == "")
            {
                txtPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text = "Champ(s) incomplet(s)";
                flag++;

                //lblError.Text = "Erreur lors de la création du compte";
            }
            if (flag == 0)
            {
                try
                {
                    DatabaseManagement database = new DatabaseManagement();
                    database.OpenConnection();


                    bool successCreation;

                    if (chkEnterprise.Checked)
                    {
                        successCreation = database.AddUser(txtEmail.Text.ToLower().Trim(), password.Trim(), "Enterprise", 10000.5);
                    }
                    else
                    {
                        successCreation = database.AddUser(txtEmail.Text.ToLower().Trim(), password.Trim(), "Public", 10000.5);
                    }


                    database.CloseConnection();

                    if (successCreation)
                    {
                        FrmConfirmRegister formConfirm = new FrmConfirmRegister();

                        formConfirm.Email = $"{txtEmail.Text.ToLower().Trim()}, vous êtes bien incrit-e";

                        formConfirm.ShowDialog();

                        Close();
                    }


                    lblError.Text      = "Erreur lors de la création du compte";
                    txtEmail.BackColor = Color.FromArgb(255, 128, 128);
                }
                catch (UnableToJoinDatabase)
                {
                    lblError.Text         = "La base de données est injoignable";
                    txtEmail.BackColor    = Color.FromArgb(255, 128, 128);
                    txtPassword.BackColor = Color.FromArgb(255, 128, 128);
                }
                catch (UserAlreadyExistsException)
                {
                    //lblError.Text = "Oups.. Cette email est deja utilisée par une autre personne";
                    lblError.Text = "Erreur lors de la création du compte, cet email est deja utilisé";
                }
                catch (WrongEmailFormatException)
                {
                    lblError.Text      = "Format d'email invalide ex. exemple@exemple";
                    txtEmail.BackColor = Color.FromArgb(255, 128, 128);
                }
                catch (WrongAccountTypeException)
                {
                    lblError.Text = "Erreur lors de la création du compte";
                }
            }
        }
Пример #14
0
        private void tryLogin()
        {
            lblError.Text         = "";
            txtEmail.BackColor    = Color.FromArgb(255, 255, 255);
            txtPassword.BackColor = Color.FromArgb(255, 255, 255);

            try
            {
                DatabaseManagement database = new DatabaseManagement();
                database.OpenConnection();

                bool allowConnection = database.VerifyUser(txtEmail.Text.ToLower().Trim(), password.Trim());

                database.CloseConnection();

                if (allowConnection)
                {
                    database = new DatabaseManagement();
                    database.OpenConnection();

                    PublicUser loggedUserInfos = (PublicUser)database.GetUser(txtEmail.Text.ToLower().Trim());

                    database.CloseConnection();

                    Visible = false;

                    Form homeForm;
                    if (loggedUserInfos.GetType() == typeof(AdminUser))
                    {
                        homeForm = new FrmHomeAdmin((AdminUser)loggedUserInfos, jsonStorage);
                        homeForm.ShowDialog();
                    }
                    else
                    {
                        homeForm = new FrmHome(loggedUserInfos, jsonStorage);
                        homeForm.ShowDialog();
                    }

                    jsonStorage.HomeWindowLocation = homeForm.Location;
                    jsonStorage.HomeWindowSize     = homeForm.Size;
                    jsonFile.InsertData(jsonStorage);

                    Close();
                }
                else
                {
                    //User and password doesn't match case
                    lblError.Text         = "Login incorrect";
                    txtEmail.BackColor    = Color.FromArgb(255, 128, 128);
                    txtPassword.BackColor = Color.FromArgb(255, 128, 128);
                }
            }
            catch (UnableToJoinDatabase)
            {
                lblError.Text         = "La base de données est injoignable";
                txtEmail.BackColor    = Color.FromArgb(255, 128, 128);
                txtPassword.BackColor = Color.FromArgb(255, 128, 128);
            }
            catch (UserDoesNotExistsException)
            {
                lblError.Text         = "Login incorrect";
                txtEmail.BackColor    = Color.FromArgb(255, 128, 128);
                txtPassword.BackColor = Color.FromArgb(255, 128, 128);
            }
        }
Пример #15
0
        private void cmdChangePassword_Click(object sender, EventArgs e)
        {
            int flag = 0;

            lblError.Text = "";

            txtOldPassword.BackColor       = Color.FromArgb(255, 255, 255);
            txtNewPassword.BackColor       = Color.FromArgb(255, 255, 255);
            txtNewPasswordVerify.BackColor = Color.FromArgb(255, 255, 255);

            if (txtNewPassword.Text.Trim() != txtNewPasswordVerify.Text.Trim())
            {
                lblError.Text = "Les mots de passes sont différents";
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (txtNewPassword.Text.Count() < 8)
            {
                lblError.Text                  = "Votre mot de passe est trop court, 8 caractères minimum";
                txtNewPassword.BackColor       = Color.FromArgb(255, 128, 128);
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                flag++;
            }
            if (txtOldPassword.Text.Trim() == "")
            {
                txtOldPassword.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text            = "Champ(s) incomplet(s)";
                flag++;
            }
            if (txtNewPassword.Text.Trim() == "")
            {
                txtNewPassword.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text            = "Champ(s) incomplet(s)";
                flag++;
            }
            if (txtNewPasswordVerify.Text.Trim() == "")
            {
                txtNewPasswordVerify.BackColor = Color.FromArgb(255, 128, 128);
                lblError.Text = "Champ(s) incomplet(s)";
                flag++;
            }
            if (flag == 0)
            {
                lblError.Text            = "";
                txtOldPassword.BackColor = Color.FromArgb(255, 255, 255);
                txtNewPassword.BackColor = Color.FromArgb(255, 255, 255);

                try
                {
                    DatabaseManagement database = new DatabaseManagement();
                    database.OpenConnection();

                    bool allowConnection = database.VerifyUser(userInfos.Email, txtOldPassword.Text.Trim());

                    database.CloseConnection();

                    if (allowConnection)
                    {
                        database = new DatabaseManagement();
                        database.OpenConnection();

                        database.ChangePassword(userInfos.Email, txtNewPassword.Text.Trim());

                        database.CloseConnection();


                        lblError.Text             = "Votre mot de passe a été changé";
                        txtOldPassword.Text       = "";
                        txtNewPassword.Text       = "";
                        txtNewPasswordVerify.Text = "";
                    }
                    else
                    {
                        //User and password doesn't match case
                        lblError.Text            = "Login incorrect";
                        txtOldPassword.BackColor = Color.FromArgb(255, 128, 128);
                    }
                }
                catch (UnableToJoinDatabase)
                {
                    lblError.Text            = "La base de données est injoignable";
                    txtOldPassword.BackColor = Color.FromArgb(255, 128, 128);
                }
            }
        }