Example #1
0
        public UsersViewModel()
        {
            addRoleUserCommand    = new AddRoleUserCommand(this);
            updateRoleUserCommand = new UpdateRoleUserCommand(this);

            // atrybuty uzytkowników.
            UsersAttributes allowedAttributes = UsersAttributes.Administrator | UsersAttributes.Recepcjonista | UsersAttributes.Terapeuta;
            int             tempTypeUser      = 5;

            //allowedAttributes = allowedAttributes | tempTypeUser;
            //UsersAttributes usersAttributesInstance = (UsersAttributes)tempTypeUser;
            //Console.WriteLine("Attibutes - " + usersAttributesInstance);
            // sprawdzenie czy użytkownik ma prawa Administratora - (UsersAttributes)1 sprawdza czy jest w prawach Administrator (1)
            //if (UsersAttributes.Administrator == (UsersAttributes)1)
            //{
            //    Console.WriteLine("User - " + UsersAttributes.Administrator);
            //    string ua = UsersAttributes.Administrator.ToString();
            //    Console.WriteLine("User string - " + ua);
            //}

            usersList = new ObservableCollection <UserModel>
            {
                new UserModel {
                    IDUser = "******", NameUser = "******", PasswordUser = "******", TypeUser = "******", FirstNameUser = "******", LastNameUser = "******"
                },
                new UserModel {
                    IDUser = "******", NameUser = "******", PasswordUser = "******", TypeUser = "******", FirstNameUser = "******", LastNameUser = "******"
                }
            };
            DataGrid_Loaded();
        }
Example #2
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxEmail.Text.Length == 0)
            {
                errormessage.Text = "Wpisz email";
                textBoxEmail.Focus();
            }
            else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                errormessage.Text = "Wpisz właściwy email";
                textBoxEmail.Select(0, textBoxEmail.Text.Length);
                textBoxEmail.Focus();
            }
            else
            {
                string email    = textBoxEmail.Text;
                string password = passwordBox1.Password;

                DBClass.openConnection();
                DBClass.sql             = "Select typeUser from users where nameUser='******'  and passwordUser='******'";
                DBClass.cmd.CommandType = CommandType.Text;
                DBClass.cmd.CommandText = DBClass.sql;

                DBClass.da = new SqlDataAdapter(DBClass.cmd);
                DBClass.dt = new DataTable();
                DBClass.da.Fill(DBClass.dt);

                // wyciągamy dane
                int i = 0;
                int j = 0;
                //Console.WriteLine("Przy bazie" + data[3]);
                using (SqlDataReader reader = DBClass.cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.FieldCount > 0)
                        {
                            data[0] = reader.GetValue(0).ToString();
                            Console.WriteLine("Taki typeUser - " + data[0]);
                            userLoginName.setUserLoginName(email);
                            UsersAttributes allowedAttributes = UsersAttributes.Administrator | UsersAttributes.Recepcjonist | UsersAttributes.Therapist;
                            Console.WriteLine("Allowed 1 " + allowedAttributes + "intek " + (UsersAttributes)(int.Parse(data[0])));
                            allowedAttributes = UsersAttributes.Administrator & (UsersAttributes)(int.Parse(data[0]));
                            Console.WriteLine("Allowed 2" + allowedAttributes);
                            if (allowedAttributes > 0)
                            {
                                Console.WriteLine("Jestem adminkiem");
                                setPermission("1");
                            }
                            allowedAttributes = UsersAttributes.Therapist & (UsersAttributes)(int.Parse(data[0]));
                            if (allowedAttributes > 0)
                            {
                                Console.WriteLine("Jestem tera");
                                setPermission("2");
                                //visibilityByRoles.VisibilityDisablerTherapist = "Collapsed";
                                //visibilityByRoles.SetUserIsAdministrator(false);
                            }
                            allowedAttributes = UsersAttributes.Recepcjonist & (UsersAttributes)(int.Parse(data[0]));
                            if (allowedAttributes > 0)
                            {
                                Console.WriteLine("Jestem receptą");
                                setPermission("4");
                            }
                            mainWindow.Show();
                            Close();
                        }
                        else
                        {
                            errormessage.Text = "Przepraszamy. Wpisz właściwego użytkownika / hasło";
                        }
                    }
                    errormessage.Text = "Wpisz właściwego użytkownika / hasło";
                }
                DBClass.closeConnection();
            }
        }