Exemple #1
0
        public static void CreateUser(User user, string password)
        {
            password = MD5.Create().GetHash(password);

            if (OpenConnection() == true)
            {
                // Create command and assign the query and connection from the constructor
                try
                {
                    using (var command = new MySqlCommand("CreateUser", connection) { CommandType = CommandType.StoredProcedure })
                    {
                        command.Parameters.AddWithValue("@user", user);
                        command.Parameters.AddWithValue("@hash", password);
                        if (command.ExecuteNonQuery() > 0)
                        {
                            Debug.Log("User " + user + " created");
                        }
                    }
                }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
            }
        }
Exemple #2
0
 private void LoginButon_Click(object sender, EventArgs e)
 {
     if (DAL.ValidateUser(usernameBox.Text, passBox.Text))
     {
         User currentUser = new User(usernameBox.Text, DAL.GetID(usernameBox.Text));
         PersistentData.user = currentUser;
         previousState = currentState;
         currentState = AppState.UserPanel;
         GetNextScreen();
     }
     else
     {
         createAccountLabel.Text = "Numele de utilizator si/sau parola au fost introduse gresit.";
         createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
         noPicture.Left = createAccountLabel.Left - 36;
         createAccountLabel.Visible = true;
         noPicture.Visible = true;
     }
 }
Exemple #3
0
        private void createAccountButton_Click(object sender, EventArgs e)
        {
            createAccountLabel.Visible = false;
            okPicture.Visible = false;
            noPicture.Visible = false;

            if (usernameBox.Text.Length < 4)
            {
                createAccountLabel.Text = "Numele de utilizator trebuie sa aiba minim 4 caractere.";
                createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                noPicture.Left = createAccountLabel.Left - 36;
                createAccountLabel.Visible = true;
                noPicture.Visible = true;
            }
            else if (passBox.Text.Length < 4)
            {
                createAccountLabel.Text = "Parola trebuie sa aiba minim 4 caractere.";
                createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                noPicture.Left = createAccountLabel.Left - 36;
                createAccountLabel.Visible = true;
                noPicture.Visible = true;
            }
            else if (passBox.Text != passConfBox.Text)
            {
                createAccountLabel.Text = "Parola nu a fost confirmata.";
                createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                noPicture.Left = createAccountLabel.Left - 36;
                createAccountLabel.Visible = true;
                noPicture.Visible = true;
            }
            else
            {

                if (DAL.SearchUser(usernameBox.Text) == false)
                {
                    User newUser = new User(usernameBox.Text);
                    DAL.CreateUser(newUser, passBox.Text);
                    if (DAL.ValidateUser(usernameBox.Text, passBox.Text))
                    {
                        previousState = currentState;
                        currentState = AppState.Start;
                        GetNextScreen();
                        createAccountLabel.Text = "Utilizator creat cu succes!";
                        createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                        okPicture.Left = createAccountLabel.Left - 36;
                        createAccountLabel.Visible = true;
                        okPicture.Visible = true;
                        passBox.Text = "";
                    }
                    else
                    {
                        createAccountLabel.Text = "Am intampinat o eroare la crearea utilizatorului.";
                        createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                        noPicture.Left = createAccountLabel.Left - 36;
                        createAccountLabel.Visible = true;
                        noPicture.Visible = true;
                    }
                }
                else
                {
                    createAccountLabel.Text = "Numele de utilizator deja exista in baza de date.";
                    createAccountLabel.Left = (this.Width - createAccountLabel.Width) / 2;
                    noPicture.Left = createAccountLabel.Left - 36;
                    createAccountLabel.Visible = true;
                    noPicture.Visible = true;
                }
            }
        }
Exemple #4
0
        public static void MarkQueried(User user, Question question)
        {
            if (OpenConnection() == true)
            {
                // Create command and assign the query and connection from the constructor
                try
                {
                    using (var command = new MySqlCommand("MarkQueried", connection) { CommandType = CommandType.StoredProcedure })
                    {
                        command.Parameters.AddWithValue("@user", user);
                        command.Parameters.AddWithValue("@idQ", question.Id);
                        if (command.ExecuteNonQuery() > 0)
                        {
                            Debug.Log("Question " + question.Id + " marked as queried");
                        }
                    }
                }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
            }
        }
Exemple #5
0
        // Statistics get
        public static Statistics GetStatistics(User user)
        {
            int total=0, correct=0, percent=0, adminpercent=0, hidropercent=0, relpercent=0, respercent=0;

            // Open connection
            if (OpenConnection() == true)
            {
                // Create command and assign the query and connection from the constructor
                try
                {
                    using (var command = new MySqlCommand("GetStatistics", connection) { CommandType = CommandType.StoredProcedure })
                    {
                        command.Parameters.AddWithValue("@user",user.ToString());

                        MySqlDataReader myReader = command.ExecuteReader();
                        if (myReader.Read())
                        {
                            total = myReader.GetInt32(0);
                            correct = myReader.GetInt32(1);
                            percent = correct / (total>0?total:1);
                            relpercent = myReader.GetInt32(2);
                            hidropercent = myReader.GetInt32(3);
                            adminpercent = myReader.GetInt32(4);
                            respercent = myReader.GetInt32(5);

                            Debug.Log(total + " " + correct + " " + percent + " " + relpercent + " " + adminpercent + " " + hidropercent + " " + respercent);
                        }
                        else Debug.Log("are probleme!");
                    }
                }
                catch (MySqlException ex)
                {
                    Debug.ExitWithErrorMessage(ex.Message, ex.Number);
                }

                // Close connection
                CloseConnection();
                return new Statistics(total, correct, relpercent, hidropercent, adminpercent, respercent);
            }
            else Debug.ExitWithErrorMessage("Connection failed to open using DAL method.");
            return null;
        }