using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Data.SqlClient; using System.Data; namespace BorisProject { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=boris;Integrated Security=True"); TrenerWindow trenerwindow = new TrenerWindow(); //Авторизация private void Vhod_Click(object sender, RoutedEventArgs e) { if (logintxt.Text == "" || passwordpsw.Password == "") { MessageBox.Show("Ошибка! Пустые поля!"); } else if (logintxt.Text =="1") { TrenerWindow trenerWindow = new TrenerWindow(); this.Close(); trenerWindow.Show(); } else if (logintxt.Text == "admin" && passwordpsw.Password=="admin") { WindowAdmin admin = new WindowAdmin(); this.Close(); admin.Show(); } else { try { con.Open(); SqlCommand cmd = new SqlCommand("Select * from Trener where Login ='" + logintxt.Text + "' and Password ='" + passwordpsw.Password + "'", con); cmd.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd; DataSet dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count > 0) { MessageBox.Show("Добро пожаловать!"); string username = dataSet.Tables[0].Rows[0]["ID_trener"].ToString(); trenerwindow.txtidtrener.Text = username; trenerwindow.Show(); this.Close(); } else { con.Close(); MessageBox.Show("Такого пользователь нет!"); } } catch { con.Close(); MessageBox.Show("Ошибка"); } } } private void Exit_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } } }