Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- 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.Shapes;
- namespace TERAPIST
- {
- /// <summary>
- /// Логика взаимодействия для LoginScreen.xaml
- /// </summary>
- public partial class LoginScreen : Window
- {
- public static LoginScreen Instance { get; private set; } // тут будет форма
- public LoginScreen()
- {
- InitializeComponent();
- Instance = this; // инициализируем статическую переменную
- }
- public void btnSubmit_Click(object sender, RoutedEventArgs e)
- {
- SqlConnection sqlCon = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersBadass NicksourcereposTERAPISTTERAPISTTERAPISTdb.mdf;Integrated Security=True");
- try
- {
- if (sqlCon.State == ConnectionState.Closed)
- sqlCon.Open();
- string query = "SELECT COUNT(1) FROM Users WHERE UserName=@UserName AND Password=@Password";
- SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
- sqlCmd.CommandType = CommandType.Text;
- sqlCmd.Parameters.AddWithValue("@Username", txtUserName.Text);
- sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password);
- // public static string user = txtUserName.Text;
- int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
- if (count == 1)
- {
- GlobalWindow dashboard = new GlobalWindow();
- dashboard.Show();
- this.Close();
- }
- else
- {
- MessageBox.Show("Не верное имя пользователя или пороль.");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- sqlCon.Close();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment