Exemple #1
0
 public MainWindow(User user)
 {
     
     db = new db();
     this.user = user;
     InitializeComponent();
     cbFilters.SelectedIndex = 0;
     MessageBox.Show($"{helper.WelcomeTime(DateTime.Now)}, {helper.WelcomeText(user.getsex())} {user.getname()}!");
     lWelcome.Content = $"Привет, {user.getname()}";
     MySqlConnection conn = db.newConnection();
     MySqlCommand cmd = new MySqlCommand("SELECT * FROM Event LIMIT 1", conn);
     try
     {
         MySqlDataReader reader = cmd.ExecuteReader();
         if (reader.HasRows)
         {
             while (reader.Read())
             {
                 @event = new Event(reader.GetValue(0).ToString(), reader.GetValue(1).ToString(), reader.GetDateTime(2));
             }
         }
         lAdHeader.Content = @event.getname();
         lAdBody.Text = "Мероприятие: " + @event.getdescription();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     timer.Tick += new EventHandler(timerTick);
     timer.Interval = new TimeSpan(0, 0, 1);
     timer.Start();
 }
Exemple #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            closeMenuBar();
            BueydAdsCanvas.Visibility = Visibility.Hidden;
            AdCanvas.Visibility = Visibility.Hidden;
            VacanciesCanvas.Visibility = Visibility.Hidden;
            SummaryCanvas.Visibility = Visibility.Hidden;
            MapCanvas.Visibility = Visibility.Hidden;
            TPassword.Text = "";
            TPassword1.Text = "";
            TName.Text = "";
            TSurname.Text = "";
            TPatronymic.Text = "";
            EditProfileCanvas.Visibility = Visibility.Visible;
            cbSex.Items.Clear();
            cbCountry.Items.Clear();

            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += (o, ea) =>
            {
                Dispatcher.Invoke((Action)(() => BusyIndicator.Visibility = Visibility.Visible));
                MySqlConnection conn = db.newConnection();
                MySqlCommand cmd = new MySqlCommand("SELECT Sex FROM Sexes", conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Dispatcher.Invoke((Action)(() => cbSex.Items.Add(reader.GetValue(0))));
                }
                conn.Close();
                conn = db.newConnection();
                cmd = new MySqlCommand("SELECT Country FROM Countries", conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Dispatcher.Invoke((Action)(() => cbCountry.Items.Add(reader.GetValue(0))));
                }
            };
            worker.RunWorkerCompleted += (o, ea) =>
            {
                Dispatcher.Invoke((Action)(() => BusyIndicator.Visibility = Visibility.Hidden));
            };
            worker.RunWorkerAsync();

            
            cbSex.SelectedIndex = user.getsex() - 1;
            cbCountry.SelectedItem = user.getcountry();
            lEmail.Content = user.getunhashedEmail();
            dtBirth.SelectedDate = user.getdateOfBirth();
        }
Exemple #3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (captchaText.Text == code)
     {
         if (TPassword.Visibility == Visibility.Hidden)
         {
             TPassword.Password = TLogin_Copy.Text;
         }
         if (TLogin.Text.Length > 0 && TPassword.Password.Length > 0)
         {
             MySqlConnection conn = db.newConnection();
             MySqlCommand    cmd  = new MySqlCommand("SELECT Users.id, Users.login, Users.password, Users.admin, Users.name, Users.lastname, Users.patronymic, Users.sex, Users.dateOfBirth, Countries.Country " +
                                                     "FROM Users, Countries " +
                                                     "WHERE Users.login = @login " +
                                                     "AND Countries.id = Users.country LIMIT 1", conn);
             cmd.Parameters.AddWithValue("@login", hash.hashString(TLogin.Text));
             try
             {
                 MySqlDataReader reader = cmd.ExecuteReader();
                 if (reader.HasRows)
                 {
                     while (reader.Read())
                     {
                         if (reader.GetValue(2) != null && reader.GetValue(2).ToString() == hash.hashString(TPassword.Password))
                         {
                             bool admin = Convert.ToInt32(reader.GetValue(3)) == 1 ? true : false;
                             User user  = new User(Convert.ToInt32(reader.GetValue(0)), reader.GetValue(1).ToString(), TLogin.Text, reader.GetValue(2).ToString(), admin, reader.GetValue(4).ToString(), reader.GetValue(5).ToString(), reader.GetValue(6).ToString(), Convert.ToInt32(reader.GetValue(7)), reader.GetDateTime(8), reader.GetValue(9).ToString());
                             if (!admin)
                             {
                                 //user form
                                 new MainWindow(user).Show();
                                 this.Close();
                             }
                             else
                             {
                                 //admin form
                                 new AdminMenu(user).Show();
                                 this.Close();
                             }
                         }
                     }
                 }
                 else
                 {
                     MessageBox.Show($"Пользователя {TLogin.Text} не существует!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                     code = SetRndCode();
                     SetCaptcha();
                     captchaText.Text = "";
                     unsuccessLogins++;
                     if (unsuccessLogins == 3)
                     {
                         MessageBox.Show("Слишком много неудачных попыток входа!");
                         Environment.Exit(0);
                     }
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.Source);
             }
         }
         else
         {
             MessageBox.Show("Заполните все поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show("Капча введена неверно!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         code = SetRndCode();
         SetCaptcha();
     }
 }