Ejemplo n.º 1
0
        private async void RegLogButton_Click(object sender, RoutedEventArgs e) //Кнопка входа/регистрации
        {
            if (RegGrid.Visibility == Visibility.Visible)                       //Действия для регистрации
            {
                if (RegTextBox.Text != "")
                {
                    if (RegPasswordbx.Password != "")
                    {
                        string passw = Cypher.GetMd5Hash(RegPasswordbx.Password);
                        if (RegNameBox.Text != "")
                        {
                            if (RegSurNameBox.Text != "")
                            {
                                if (RegTypeBox.SelectedIndex != -1)
                                {
                                    UserData us = new UserData(RegTextBox.Text, passw, RegNameBox.Text, RegSurNameBox.Text, RegTypeBox.SelectedIndex, RegTextBlock.Text);
                                    users.Add(us);
                                    De_Serialization.Serialization <List <UserData> >("UserData.xml", CreationCollisionOption.OpenIfExists, users);

                                    RegGrid.Visibility   = Visibility.Collapsed;
                                    LoginGrid.Visibility = Visibility.Visible;
                                    RegLogButton.Content = "Войти";
                                }
                            }
                        }
                    }
                }
                //Ошибки
                if (RegTextBox.Text == "" || RegPasswordbx.Password == "" || RegNameBox.Text == "" || RegSurNameBox.Text == "" || RegTypeBox.SelectedIndex == -1)
                {
                    ContentDialog prog = new ContentDialog()
                    {
                        Title             = "Ошибка",
                        Content           = "Одно или несколько полей пустые",
                        PrimaryButtonText = "OK"
                    };
                    await prog.ShowAsync();
                }
            }
            else //Действия для входа
            {
                if (users.Count != 0 && LoginTextBox.Text != "" && Passwordbx.Password != "")
                {
                    string passw     = Cypher.GetMd5Hash(Passwordbx.Password);
                    bool   confirmed = true;
                    for (int i = 0; i < users.Count; i++)
                    {
                        if (LoginTextBox.Text == users[i].Login && passw == users[i].Password)
                        {
                            List <string> us = new List <string>()
                            {
                                users[i].Login, passw, users[i].Name, users[i].Surname, users[i].AccountType.ToString(), users[i].DisciplineType
                            };
                            De_Serialization.Serialization <List <string> >("LoginData.xml", CreationCollisionOption.ReplaceExisting, us);

                            confirmed = true;

                            if (users[i].AccountType == 0)
                            {
                                this.Frame.Navigate(typeof(StudentPage));
                            }
                            if (users[i].AccountType == 1)
                            {
                                this.Frame.Navigate(typeof(TeacherPage));
                            }
                            if (users[i].AccountType == 2)
                            {
                                this.Frame.Navigate(typeof(AdminPage));
                            }

                            break;
                        }
                        else
                        {
                            confirmed = false;
                        }
                    }
                    if (!confirmed)
                    {
                        ContentDialog prog = new ContentDialog()
                        {
                            Title             = "Ошибка",
                            Content           = "Неверный логин или пароль",
                            PrimaryButtonText = "OK"
                        };
                        await prog.ShowAsync();
                    }
                }
            }
        }