示例#1
0
        private void Login(object sender, RoutedEventArgs e)
        {
            string          email = Email.Text;
            string          pass  = MainWindow.crypto(Password.Password);
            MySqlConnection conn  = new MySqlConnection(MainWindow.db);
            MySqlCommand    cmd   = new MySqlCommand("select email, password from runners where email = @email and password = @password", conn);

            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@password", pass);
            conn.Open();
            MySqlDataReader r = cmd.ExecuteReader();

            if (r.Read())
            {
                window.auth    = true;
                window.email   = r["email"].ToString();
                window.parents = new Stack <Page>();
                AccountPage page = new AccountPage(window);
                window.Content = page;
            }
            else
            {
                MessageBox.Show("Неверный логин или пароль", "Ошибка");
            }
            conn.Close();
        }
示例#2
0
        private void Register(object sender, RoutedEventArgs e)
        {
            Regex re = new Regex(@"\d+");

            if (!(bool)this.Full.IsChecked && !(bool)this.Half.IsChecked && !(bool)this.Short.IsChecked)
            {
                MessageBox.Show("Выберите вид марафона", "Ошибка");
            }
            else if (this.CheckedOption == -1)
            {
                MessageBox.Show("Выберите варианты комплектов", "Ошибка");
            }
            else if (!re.IsMatch(CostFund.Text))
            {
                if (fund != "")
                {
                    MessageBox.Show("Введите сумму", "Ошибка");
                }
            }
            else
            {
                string msg;
                if (fund == "")
                {
                    msg = String.Format("Вы уверены? Общая сумма: {0}$ (из них 0$ на счёт фондов)", this.cost);
                }
                else
                {
                    msg = String.Format("Вы уверены? Общая сумма: {0}$ (из них {1}$ на счёт фонда: {2})", this.cost + this.fundcost, this.fundcost, this.fund);
                }
                MessageBoxResult result = MessageBox.Show(msg, "Подтверждение", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    MySqlConnection conn = new MySqlConnection(MainWindow.db);
                    MySqlCommand    cmd  = new MySqlCommand("insert into marathon(email, full, half, short, fund, sfund, option) values(@email, @full, @half, @short, @fund, @sfund, @option)", conn);
                    cmd.Parameters.AddWithValue("@email", window.email);
                    cmd.Parameters.AddWithValue("@full", (bool)this.Full.IsChecked);
                    cmd.Parameters.AddWithValue("@half", (bool)this.Half.IsChecked);
                    cmd.Parameters.AddWithValue("@short", (bool)this.Short.IsChecked);
                    cmd.Parameters.AddWithValue("@fund", this.fund);
                    cmd.Parameters.AddWithValue("@sfund", this.fundcost);
                    cmd.Parameters.AddWithValue("@option", this.CheckedOption);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    MessageBox.Show("Вы успешно зарегистрированы на марафон", "Успех");

                    try {
                        AccountPage page = (AccountPage)window.parents.Pop();
                        page.Update();
                        window.Content = page;
                    }
                    catch (Exception exc) {
                        MessageBox.Show(exc.Message);
                    }
                }
            }
        }