Пример #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");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Home form constructor
        /// </summary>
        /// <param name="userInfos">Inherit user informations to display from parent form</param>
        /// <param name="inheritStorage">Inherit json informations to use from parent form</param>
        public FrmHome(PublicUser userInfos, JsonData inheritStorage)
        {
            InitializeComponent();

            cmdPay.Enabled     = false;
            txtPayIban.Enabled = true;

            userInformations   = userInfos;
            inheritJsonStorage = inheritStorage;

            cboPayList.SelectedIndex = 0;
        }
Пример #3
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();
        }
Пример #4
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);
            }
        }
Пример #5
0
        /// <summary>
        /// Get all user's informations and transactions from his email
        /// </summary>
        /// <param name="email">User's email</param>
        /// <returns>Return user's informations</returns>
        public User GetUser(string email)
        {
            MySqlCommand query;

            #region Account type management

            // Create a command object
            query             = connection.CreateCommand();
            query.CommandText = "select iban, type+0 as type, email, money from USERS where email = (@email)";

            //Add parameters to query
            query.Parameters.AddWithValue("@email", email);

            //Get user's money from the database
            DbDataReader reader = query.ExecuteReader();
            reader.Read();

            User user;
            if ((User.AccountType)reader.GetInt32(1) == User.AccountType.Enterprise)
            {
                user = new EnterpriseUser(reader.GetString(0), reader.GetString(2), reader.GetDouble(3));
            }
            else if ((User.AccountType)reader.GetInt32(1) == User.AccountType.Admin)
            {
                user = new AdminUser(reader.GetString(0), reader.GetString(2));
            }
            else
            {
                user = new PublicUser(reader.GetString(0), reader.GetString(2), reader.GetDouble(3));
            }

            reader.Close();
            #endregion


            #region Transactions management

            // Create a command object
            query = connection.CreateCommand();
            if (user.GetType() == typeof(AdminUser))
            {
                query.CommandText = @"select TRANSACTIONS.date, TRANSACTIONS.amount, TRANSACTIONS.reason, 
                                    USER_RECEIVER.email, USER_RECEIVER.iban, USER_SENDER.email, USER_SENDER.iban from TRANSACTIONS
                                    left join USERS as USER_RECEIVER on USER_RECEIVER.id = TRANSACTIONS.idReceiver
                                    left join USERS as USER_SENDER on USER_SENDER.id = TRANSACTIONS.idSender
                                    order by TRANSACTIONS.date desc";
            }
            else
            {
                query.CommandText = @"select TRANSACTIONS.date, TRANSACTIONS.amount, TRANSACTIONS.reason, 
                                    USER_RECEIVER.email, USER_RECEIVER.iban, USER_SENDER.email, USER_SENDER.iban from TRANSACTIONS
                                    left join USERS as USER_RECEIVER on USER_RECEIVER.id = TRANSACTIONS.idReceiver
                                    left join USERS as USER_SENDER on USER_SENDER.id = TRANSACTIONS.idSender
                                    where USER_RECEIVER.email = (@concerned1) OR USER_SENDER.email  = (@concerned2)
                                    order by TRANSACTIONS.date desc";

                //Add parameters to query
                query.Parameters.AddWithValue("@concerned1", email);
                query.Parameters.AddWithValue("@concerned2", email);
            }

            //Get user's money from the database
            reader = query.ExecuteReader();

            if (reader.HasRows)
            {
                //Add each transactions linked to the user
                while (reader.Read())
                {
                    Transaction newTransaction = new Transaction(
                        reader.GetDateTime(0).ToString(),
                        reader.GetDouble(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetString(4),
                        reader.GetString(5),
                        reader.GetString(6));
                    ((PublicUser)user).Transactions.Add(newTransaction);
                }
            }
            reader.Close();
            #endregion


            #region Lists management (only enterprise and admin users)

            if (user.GetType() == typeof(EnterpriseUser) || user.GetType() == typeof(AdminUser))
            {
                // Create a command object
                query = connection.CreateCommand();
                if (user.GetType() == typeof(AdminUser))
                {
                    query.CommandText = @"select lists.name, COALESCE(USER_INSIDE.iban,''), COALESCE(USER_INSIDE.email,''), LIST_OWNER.email from lists
                                        left join users_lists on users_lists.idList = lists.id
                                        left join users as LIST_OWNER on lists.idUser = LIST_OWNER.id
                                        left join users as USER_INSIDE on users_lists.idUser = USER_INSIDE.id
                                        order by lists.name asc";
                }
                else
                {
                    query.CommandText = @"select lists.name, COALESCE(USER_INSIDE.iban,''), COALESCE(USER_INSIDE.email,'') from lists
                                        left join users_lists on users_lists.idList = lists.id
                                        left join users as LIST_OWNER on lists.idUser = LIST_OWNER.id
                                        left join users as USER_INSIDE on users_lists.idUser = USER_INSIDE.id
                                        where LIST_OWNER.email = (@owner)
                                        order by lists.name asc";

                    //Add parameters to query
                    query.Parameters.AddWithValue("@owner", email);
                }

                //Get user's money from the database
                reader = query.ExecuteReader();

                bool endFlag = false;
                if (reader.HasRows)
                {
                    reader.Read();

                    while (!endFlag)
                    {
                        UsersList usersList = new UsersList(reader.GetString(0));

                        if (user.GetType() == typeof(AdminUser))
                        {
                            usersList = new AdminUsersList(reader.GetString(0), reader.GetString(3));
                        }
                        else
                        {
                            usersList = new UsersList(reader.GetString(0));
                        }

                        if (reader.GetString(1) != "" && reader.GetString(2) != "")
                        {
                            usersList.Users.Add(new User(reader.GetString(1), reader.GetString(2)));

                            while (true)
                            {
                                if (!reader.Read())
                                {
                                    endFlag = true;
                                    break;
                                }

                                if (reader.GetString(0) == usersList.Name)
                                {
                                    usersList.Users.Add(new User(reader.GetString(1), reader.GetString(2)));
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (!reader.Read())
                            {
                                endFlag = true;
                            }
                        }
                        ((EnterpriseUser)user).Lists.Add(usersList);
                    }
                }
                reader.Close();
            }
            #endregion


            #region Users management (only admin users)

            if (user.GetType() == typeof(AdminUser))
            {
                // Create a command object
                query             = connection.CreateCommand();
                query.CommandText = "select iban, email, money, active, type+0 as type from USERS order by iban asc";

                //Get user's money from the database
                reader = query.ExecuteReader();

                if (reader.HasRows)
                {
                    //Add each transactions linked to the user
                    while (reader.Read())
                    {
                        BankUserInfos newBankUser = new BankUserInfos(
                            reader.GetString(0),
                            reader.GetString(1),
                            reader.GetDouble(2),
                            reader.GetBoolean(3),
                            (User.AccountType)reader.GetInt32(4));
                        ((AdminUser)user).Users.Add(newBankUser);
                    }
                }
                reader.Close();
            }
            #endregion

            return(user);
        }