Guest User

Untitled

a guest
Jun 17th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Shapes;
  18.  
  19. namespace TERAPIST
  20. {
  21. /// <summary>
  22. /// Логика взаимодействия для LoginScreen.xaml
  23. /// </summary>
  24. public partial class LoginScreen : Window
  25. {
  26. public static LoginScreen Instance { get; private set; } // тут будет форма
  27. public LoginScreen()
  28. {
  29. InitializeComponent();
  30. Instance = this; // инициализируем статическую переменную
  31.  
  32. }
  33.  
  34.  
  35.  
  36.  
  37. public void btnSubmit_Click(object sender, RoutedEventArgs e)
  38. {
  39.  
  40. SqlConnection sqlCon = new SqlConnection(@"Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=C:UsersBadass NicksourcereposTERAPISTTERAPISTTERAPISTdb.mdf;Integrated Security=True");
  41. try
  42. {
  43. if (sqlCon.State == ConnectionState.Closed)
  44. sqlCon.Open();
  45. string query = "SELECT COUNT(1) FROM Users WHERE UserName=@UserName AND Password=@Password";
  46. SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
  47. sqlCmd.CommandType = CommandType.Text;
  48. sqlCmd.Parameters.AddWithValue("@Username", txtUserName.Text);
  49. sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Password);
  50. // public static string user = txtUserName.Text;
  51. int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
  52. if (count == 1)
  53. {
  54.  
  55. GlobalWindow dashboard = new GlobalWindow();
  56. dashboard.Show();
  57. this.Close();
  58.  
  59. }
  60. else
  61. {
  62. MessageBox.Show("Не верное имя пользователя или пороль.");
  63. }
  64. }
  65. catch (Exception ex)
  66. {
  67. MessageBox.Show(ex.Message);
  68. }
  69. finally
  70. {
  71. sqlCon.Close();
  72. }
  73.  
  74. }
  75. }
  76. }
Add Comment
Please, Sign In to add comment