Example #1
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");
                }
            }
        }
        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");
            }
        }
Example #3
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();
        }
Example #4
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();
        }
        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;
        }
        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;
        }
        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 = "";
        }
Example #8
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);
            }
        }