void InsertData() { //string cardNumber = @"[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}"; //if ((!Regex.IsMatch(tbKartNumber.Text, cardNumber)) || // (tbSponsorName.Text == "") || // (tbKartOwner.Text == "") || // (tbSumma.Text == "") || // (cmbRunner.SelectedIndex == -1) || // (tbKartValid.Text =="")|| // (tbCVC.Text =="")) string er = CheckInputData(); if (er != "") { MessageBox.Show(er, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (Marathon2020Entities1 db = new Marathon2020Entities1()) { if (RegId == -1) { return; } Sponsorship sponsorship = new Sponsorship { SponsorName = tbSponsorName.Text, RegistrationId = RegId, Amount = Convert.ToDecimal(tbSumma.Text) }; db.Sponsorship.Add(sponsorship); db.SaveChanges(); MessageBox.Show("Спасибо, Ваши деньги" + " успешно переведены на счёт бегуна", "Информация", MessageBoxButton.OK, MessageBoxImage.Information); } // using (SqlConnection sqlConnection = new SqlConnection(connectionString)) //{ // sqlConnection.Open(); // if (RegId == -1) return; // SqlCommand insertData = new SqlCommand("INSERT INTO Sponsorship" + // " VALUES(@SponsorName,@RegistrationId,@Amount)", sqlConnection); // insertData.Parameters.AddWithValue("@SponsorName", tbSponsorName.Text); // insertData.Parameters.AddWithValue("@RegistrationId", RegId); // insertData.Parameters.AddWithValue("@Amount", Convert.ToDouble(tbSumma.Text)); // insertData.ExecuteNonQuery(); // MessageBox.Show("Спасибо, Ваши деньги" + // " успешно переведены на счёт бегуна", // "Информация", // MessageBoxButton.OK, // MessageBoxImage.Information); // // // //PAge Thank you Gonna be here //} }
void LoadDataAboutRunners() { using (Marathon2020Entities1 db = new Marathon2020Entities1()) { var runnerList = (from runner in db.Runner join user in db.User on runner.Email equals user.Email join country in db.Country on runner.CountryCode equals country.CountryCode select new { IdRunner = runner.RunnerId, RunnerName = user.FirstName + " " + user.LastName + " <" + runner.RunnerId + "> " + country.CountryCode }).ToList(); cmbRunner.ItemsSource = runnerList.ToList(); } }
void GetRunnerCharityOrganization(int idRunner) { // lblCharityName.Content = ""; // using (SqlConnection sqlConnection = new SqlConnection(connectionString)) // { // sqlConnection.Open(); // SqlCommand sqlGetId = new SqlCommand("SELECT " + // "[Registration].CharityId " + // "FROM Registration WHERE RunnerID= " + idRunner, sqlConnection); // int charityId = Convert.ToInt32(sqlGetId.ExecuteScalar()); // SqlCommand sqlRegId = new SqlCommand("SELECT " + // "[Registration].RegistrationId " + // "FROM Registration WHERE RunnerID= " + idRunner, // sqlConnection); // RegId = -1; // if (sqlRegId.ExecuteScalar() != DBNull.Value) // RegId = Convert.ToInt32(sqlRegId.ExecuteScalar()); // SqlCommand sqlGetCharity = new SqlCommand("SELECT " + // " * " + // "FROM Charity WHERE CharityID= " + charityId, sqlConnection); // SqlDataReader reader = sqlGetCharity.ExecuteReader(); // charity = null; // if (reader.HasRows) // { // while (reader.Read()) // { // int id = reader.GetInt32(0); // string name = reader.GetString(1); // string description = reader.GetString(2); // string logo = reader.GetString(3); // charity = new Charity() // { // IdCharity = id, // CharityName = name, // CharityLogo = logo, // CharityDescription = description // }; // lblCharityName.Content = name; // } // } // reader.Close(); // } charity = null; lblCharityName.Content = ""; RegId = -1; using (Marathon2020Entities1 db = new Marathon2020Entities1()) { var charityId = db.Registration.FirstOrDefault(p => p.RunnerId == idRunner); if (charityId != null) { RegId = charityId.RegistrationId; charity = db.Charity.Find(charityId.CharityId); lblCharityName.Content = charity.CharityName; } } }
private void BtnLogin_Click(object sender, RoutedEventArgs e) { using (Marathon2020Entities1 db = new Marathon2020Entities1()) { User user = db.User.FirstOrDefault(u => u.Email == tbEmail.Text); if (user != null) { if (user.Password == tbPassword.Password) { char roleId = Convert.ToChar(user.RoleId); switch (roleId) { case 'R': { NavigationService.Navigate(new Uri("Pages/RunnerMenuPage.xaml", UriKind.Relative)); break; } case 'A': { NavigationService.Navigate(new Uri("Pages/AdministratorMenuPage.xaml", UriKind.Relative)); break; } case 'C': { NavigationService.Navigate(new Uri("Pages/CoordinatorMenuPage.xaml", UriKind.Relative)); break; } } } else { MessageBox.Show("Не верный пароль"); } } else { MessageBox.Show("Не верный логин или пароль"); } } // using (SqlConnection sqlConnection = new SqlConnection(connectionString)) // { // sqlConnection.Open(); // SqlCommand sqlGetUser = new SqlCommand("Select * FROM [user] where email ='" + tbEmail.Text + "'", sqlConnection); // SqlDataReader reader = sqlGetUser.ExecuteReader(); // if (reader.HasRows) // { // reader.Read(); // string password = reader.GetString(1); // if (password == tbPassword.Password) // { // char roleId = Convert.ToChar(reader.GetValue(4)); // switch (roleId) // { // case 'R': // { // NavigationService.Navigate(new Uri("Pages/RunnerMenuPage.xaml", UriKind.Relative)); // break; // } // case 'A': // { // NavigationService.Navigate(new Uri("Pages/AdministratorMenuPage.xaml", UriKind.Relative)); // break; // } // case 'C': // { // NavigationService.Navigate(new Uri("Pages/CoordinatorMenuPage.xaml", UriKind.Relative)); // break; // } // } // } // else // MessageBox.Show("Не верный логин или пароль"); // } // else // MessageBox.Show("Не верный логин или пароль"); //} }