コード例 #1
0
ファイル: Form1.cs プロジェクト: arturmekler/Bookstore
        private void queryLog()
        {
            // Checks if the login and password are correct
            // If they are correct then it opens a new window with Store

            using (MySqlConnection sqlCon = new MySqlConnection(MySQLConnectionString))
            {
                try
                {
                    sqlCon.Open();
                }
                catch (MySqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }


                string login    = loginTextBox.Text;
                string password = passwordTextBox.Text;
                string query    = "SELECT * FROM users WHERE login='******' AND haslo='" + password + "'";

                MySqlCommand commandDatabase = new MySqlCommand(query, sqlCon);

                try
                {
                    MySqlDataReader myReader = commandDatabase.ExecuteReader();
                    if (myReader.HasRows)
                    {
                        MessageBox.Show("Dziala");

                        // creating a new Form (Store)
                        StoreForm store = new StoreForm(login, password, MySQLConnectionString);
                        store.Show();

                        // closing LoginForm
                        this.Hide();
                        store.Closed += (s, args) => this.Close();
                        store.Show();
                    }
                    else
                    {
                        MessageBox.Show("Nie poprawny login lub hasło", "Błąd logowania");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Query error: " + e.Message);
                }
            }
        }
コード例 #2
0
        private void queryRegister(string MySQLConnectionStringValue)
        {
            // writes values to variables and checks whether the values are
            // well entered and whether the entered login already exists.
            // If it is ok, it adds a new user to the data phase and logs in to the "store" panel


            string login    = loginRegTextBox.Text;
            string password = passwordRegTextBox.Text;
            string vorname  = vornameRegTextBox.Text;
            string name     = nameRegTextBox.Text;
            string locality = localityRegTextBox.Text;

            // checking if the values have been entered correctly or if the login already exists.
            // Returns true if functions TextBoxCheck = True AND LoginCheck is true
            // Returns false, otherwise

            if (TextBoxCheck(MySQLConnectionStringValue, login, password, vorname, name, locality) &&
                LoginCheck(MySQLConnectionStringValue, login))
            {
                using (MySqlConnection sqlCon = new MySqlConnection(MySQLConnectionStringValue))
                {
                    sqlCon.Open();

                    string queryRegist = "INSERT INTO users (login, haslo, imie, nazwisko, miejscowosc) VALUES("
                                         + "'" + login + "'" + "," + "'" + password + "'" + "," + "'" + vorname + "'" + ","
                                         + "'" + name + "'" + "," + "'" + locality + "'" + ")";

                    MySqlCommand commandDatabase = new MySqlCommand(queryRegist, sqlCon);
                    try
                    {
                        MySqlDataReader myReader = commandDatabase.ExecuteReader();

                        // creating a new Form (Store)
                        StoreForm store = new StoreForm(login, password, MySQLConnectionStringValue);
                        store.Show();

                        // closing RegisterForm
                        this.Hide();
                        store.Closed += (s, args) => this.Close();
                        store.Show();
                    }

                    catch (Exception e)
                    {
                        MessageBox.Show("Query error: " + e.Message);
                    }
                }
            }
        }