// кнопка виходу з системи
        private void LogOutButton_Click(object sender, RoutedEventArgs e)
        {
            client.LogOut();
            LoginWindow lg = new LoginWindow();

            Close();
            lg.ShowDialog();
        }
示例#2
0
        // кнопка реєстрації, в залежності від обраного користувача відбувається реєстрація адміністратора або студента
        private void RegistrateButton_Click(object sender, RoutedEventArgs e)
        {
            string answer = null;

            if (!isAdmin)
            {
                if (NameBox.Text != "" && SurNameBox.Text != "" && LoginBox.Text != "" && PasswordBox.Password != "" && ConfirmPasswordBox.Password != "" && selectedName != null)
                {
                    if (PasswordBox.Password.Length > 4)
                    {
                        if (PasswordBox.Password == ConfirmPasswordBox.Password)
                        {
                            student = new DTOStudent {
                                Name = NameBox.Text, SurName = SurNameBox.Text, Login = LoginBox.Text, Password = PasswordBox.Password, GroupId = groups.FirstOrDefault(g => g.GroupName == selectedName).GroupId
                            };
                            answer = client.Registrate(student);
                            if (answer == "successfully")
                            {
                                client.LogOut();
                                Close();
                            }
                            else if (answer == "login already exists")
                            {
                                MessageBox.Show("Already exist user with this login!!!");
                                LoginBox.Text = "";
                            }
                            else if (answer == "password already exists")
                            {
                                MessageBox.Show("Already exist user with this password!!!");
                                PasswordBox.Password = "";
                            }
                            else
                            {
                                MessageBox.Show("Something wrong!!!");
                                client.Disconnect();
                                Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Error in password or confirm password!!!");
                            PasswordBox.Foreground        = Brushes.Red;
                            ConfirmPasswordBox.Foreground = Brushes.Red;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error in password or confirm password!!!");
                        PasswordBox.Foreground        = Brushes.Red;
                        ConfirmPasswordBox.Foreground = Brushes.Red;
                    }
                }
                else
                {
                    MessageBox.Show("Fill all the gaps!!!");
                }
            }
            else
            {
                if (NameBox.Text != "" && LoginBox.Text != "" && PasswordBox.Password != "" && ConfirmPasswordBox.Password != "")
                {
                    if (PasswordBox.Password.Length > 4)
                    {
                        if (PasswordBox.Password == ConfirmPasswordBox.Password)
                        {
                            admin = new DTOAdministrator {
                                Name = NameBox.Text, Login = LoginBox.Text, Password = PasswordBox.Password
                            };
                            answer = client.Registrate(admin);
                        }
                        else
                        {
                            MessageBox.Show("Error in password or confirm password!!!");
                            PasswordBox.Foreground        = Brushes.Red;
                            ConfirmPasswordBox.Foreground = Brushes.Red;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error in password or confirm password!!!");
                        PasswordBox.Foreground        = Brushes.Red;
                        ConfirmPasswordBox.Foreground = Brushes.Red;
                    }
                }
                else
                {
                    MessageBox.Show("Fill all the gaps!!!");
                }
            }
        }