Exemplo n.º 1
0
        private void Log(object sender, RoutedEventArgs e)
        {
            using (CinemaContext db = new CinemaContext())
            {
                SqlParameter login    = new("@login", LoginBox.Text);
                SqlParameter password = new("@password", Password.Password);
                var          users    = db.UsersNames.FromSqlRaw("LogIN @login, @password", login, password).ToList();
                foreach (UsersName user in users)
                {
                    switch (user.IdRole)
                    {
                    case 1:
                        MainWindow main = new MainWindow(user.NameClient + " " + user.Surname);
                        main.Show();
                        Manager.window.Close();
                        Manager.Email = user.Email;
                        break;

                    case 2:
                        AdminWindow window = new AdminWindow();
                        window.Show();
                        Manager.window.Close();
                        break;
                    }
                }
                if (users.Count == 0)
                {
                    MessageBox.Show("Такого пользователя не существует");
                }
            }
        }
        public void checkUser()
        {
            currentEmployee = new Employee();
            try
            {
                using (OracleConnection oracleConnection = new OracleConnection(OracleDatabaseConnection.connection))
                {
                    oracleConnection.Open();

                    OracleParameter login = new OracleParameter
                    {
                        ParameterName = "in_login",
                        Direction     = ParameterDirection.Input,
                        OracleDbType  = OracleDbType.Varchar2,
                        Value         = loginText.Text
                    };
                    OracleParameter password = new OracleParameter
                    {
                        ParameterName = "in_password",
                        Direction     = ParameterDirection.Input,
                        OracleDbType  = OracleDbType.Varchar2,
                        Value         = passwordText.Password
                    };
                    OracleParameter user = new OracleParameter
                    {
                        ParameterName = "user_cur",
                        Direction     = ParameterDirection.Output,
                        OracleDbType  = OracleDbType.RefCursor
                    };

                    using (OracleCommand command = new OracleCommand("findUser"))
                    {
                        command.Connection  = oracleConnection;
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddRange(new OracleParameter[] { login, password, user });
                        var       reader = command.ExecuteReader();
                        DataTable dt     = new DataTable();
                        dt.Load(reader);

                        foreach (DataRow row in dt.Rows)
                        {
                            currentEmployee.Login      = row["Login"].ToString();
                            currentEmployee.Password   = row["Password"].ToString();
                            currentEmployee.IDEmployee = Convert.ToInt32(row["e_ID"]);
                            currentEmployee.Name       = row["Name"].ToString();
                            currentEmployee.Secondname = row["SecondName"].ToString();
                            currentEmployee.Surname    = row["Surname"].ToString();
                            currentEmployee.FIO        = currentEmployee.Surname + " " + currentEmployee.Name.Substring(0, 1) + ". " + currentEmployee.Secondname.Substring(0, 1) + ".";
                        }
                    }

                    oracleConnection.Close();
                    currUserPos = loginText.Text;
                    if (currUserPos == currentEmployee.Login)
                    {
                        if (currUserPos == "Администратор")
                        {
                            AdminWindow adminWindow = new AdminWindow(currentEmployee.IDEmployee, currentEmployee.FIO);
                            adminWindow.Show();
                            this.Close();
                        }
                        else
                        {
                            BookingWindow bookingWindow = new BookingWindow(currentEmployee.IDEmployee, currentEmployee.FIO);
                            bookingWindow.Show();
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Пользователя не существует");
                        loginText.Text        = "";
                        passwordText.Password = "";
                        passwordText2.Text    = "";
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }