private void registerButton_Click(object sender, RoutedEventArgs e)
 {
     if (loginBox.Text != "" && passwordBox.Password != "" && nickBox.Text != "")
     {
         MySqlConnection Connection = MySQLOptions.ReturnConnection();
         Connection.Open();
         MySqlCommand    Check  = new MySqlCommand("SELECT account_id FROM ACCOUNTS WHERE login = '******' AND nick = '" + nickBox.Text + "'", Connection);
         MySqlDataReader reader = Check.ExecuteReader();
         if (reader.HasRows)
         {
             MessageBox.Show(ProgramOptions.TranslatedLabels[10]);
             reader.Close();
         }
         else
         {
             reader.Close();
             MySqlCommand Insert = new MySqlCommand("INSERT INTO ACCOUNTS VALUES(default, '" + loginBox.Text + "', '" + passwordBox.Password + "', '" + nickBox.Text + "', 'user');", Connection);
             Insert.ExecuteNonQuery();
             Insert.CommandText = "INSERT INTO ONLINE_USERS VALUES(default, '" + nickBox.Text + "','Offline');";
             Insert.ExecuteNonQuery();
             MessageBox.Show(ProgramOptions.TranslatedLabels[11]);
             this.Close();
         }
     }
 }
Esempio n. 2
0
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            if (loginBox.Text != "" && passwordBox.Password != "")
            {
                MySqlConnection Connection = MySQLOptions.ReturnConnection();
                Connection.Open();
                MySqlCommand    Check  = new MySqlCommand("SELECT login,nick,privileges FROM ACCOUNTS WHERE login = '******' AND password = '******'", Connection);
                MySqlDataReader reader = Check.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        switch (reader.GetString(2))
                        {
                        case "administrator":
                            ProgramOptions.LoggedInUser = new Administrator(reader.GetString(0), "Online", reader.GetString(1));
                            break;

                        case "moderator":
                            ProgramOptions.LoggedInUser = new Moderator(reader.GetString(0), "Online", reader.GetString(1));
                            break;

                        default:
                            ProgramOptions.LoggedInUser = new User(reader.GetString(0), "Online", reader.GetString(1));
                            break;
                        }
                    }
                    reader.Close();
                    Check.CommandText = "SELECT TIMEDIFF(NOW(),(SELECT finish_date FROM BANLIST WHERE target = '" + ProgramOptions.LoggedInUser.Nick + "' ORDER BY finish_date DESC LIMIT 1));";
                    reader            = Check.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            try
                            {
                                if (reader.GetTimeSpan(0) != null && reader.GetTimeSpan(0).TotalMilliseconds >= 0)
                                {
                                    Chat newWindow = new Chat();
                                    this.Hide();
                                    reader.Close();
                                    newWindow.ShowDialog();
                                    this.Show();
                                    break;
                                }
                                else
                                {
                                    MessageBox.Show(ProgramOptions.TranslatedLabels[19]);
                                    reader.Close();
                                }
                            }
                            catch (Exception exception)
                            {
                                if (exception is System.Data.SqlTypes.SqlNullValueException)
                                {
                                    Chat newWindow = new Chat();
                                    this.Hide();
                                    reader.Close();
                                    newWindow.ShowDialog();
                                    this.Show();
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        if (exception is MySql.Data.MySqlClient.MySqlException)
                        {
                            reader.Close();
                        }
                    }
                }
                else
                {
                    reader.Close();
                    MessageBox.Show(ProgramOptions.TranslatedLabels[12]);
                }
            }
        }