123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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 SkladProject
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=praktika;Integrated Security=True");
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
- private void Exit_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- private void WinMin_Click(object sender, RoutedEventArgs e)
- {
- this.WindowState = WindowState.Minimized;
- }
- private void logintxt_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (sender is TextBox textBox)
- {
- textBox.Text = new string
- (textBox.Text.Where(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')).ToArray());
- }
- }
- private void passwordtxt_PasswordChanged(object sender, RoutedEventArgs e)
- {
- if (sender is TextBox textBox)
- {
- textBox.Text = new string
- (textBox.Text.Where(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')).ToArray());
- }
- }
- private void Vhod_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (logintxt.Text == "" || passwordtxt.Password == "")
- {
- MessageBox.Show("Поля не могут быть пустыми!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- else
- {
- con.Open();
- SqlCommand cmd = new SqlCommand("Select * from Users where Login ='" + logintxt.Text + "' and Password ='" + passwordtxt.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)
- {
- string idrole = dataSet.Tables[0].Rows[0]["ID_RoleUser"].ToString();
- string username = dataSet.Tables[0].Rows[0]["ID_User"].ToString();
- if (idrole.ToString() == "1")
- {
- con.Close();
- WindowAdmin windowAdmin = new WindowAdmin();
- windowAdmin.Show();
- this.Close();
- }
- else
- {
- WorkerWindow workerWindow = new WorkerWindow();
- workerWindow.idusertxt.Text = username;
- con.Close();
- workerWindow.Show();
- this.Close();
- }
- }
- else
- {
- con.Close();
- MessageBox.Show("Неправильный логин/пароль!", "Вход", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- }
- }
- catch (Exception ex)
- {
- con.Close();
- MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
- }
-
- }
- }
- }
|