예제 #1
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            bool work = true;

            Login view = new Login();



            ViweModel.Viwe_Model_Login viewModel = new ViweModel.Viwe_Model_Login();
            view.DataContext = viewModel;

            if (viewModel._Visibility_off == null)
            {
                viewModel._Visibility_off = new Action(view.Visibility_off);
            }


            if (viewModel._Visibility_on == null)
            {
                viewModel._Visibility_on = new Action(view.Visibility_on);
            }

            if (viewModel._NO == null)
            {
                viewModel._NO = new Action(view.No);
            }

            if (viewModel._OK == null)
            {
                viewModel._OK = new Action(view.Ok);
            }

            if (viewModel._NONE_USER == null)
            {
                viewModel._NONE_USER = new Action(view.None_user);
            }


            //view.Closing += viewModel.OnWindowClosing;

            //do
            //{
            view.ShowDialog();
        }
예제 #2
0
        private void Execute_edit(object o)
        {
            try
            {
                Messege            messege            = new Messege();
                View_Model_Messege messege_view_Model = new View_Model_Messege(System.Windows.Visibility.Visible, System.Windows.Visibility.Visible, System.Windows.Visibility.Hidden);

                if (messege_view_Model._OK == null)
                {
                    messege_view_Model._OK = new Action(messege.Close);
                }
                if (messege_view_Model._NO == null)
                {
                    messege_view_Model._NO = new Action(messege.Close);
                }


                messege.DataContext             = messege_view_Model;
                messege_view_Model.Messege      = "Are you sure you want to change the settings?";
                messege_view_Model.Messeg_Titel = "Сhange";
                messege.ShowDialog();

                if (messege_view_Model.is_ok)
                {
                    bool is_str;
                    if (new_name != null && new_name.Length > 0)
                    {
                        is_str = regex_str.IsMatch(new_name);
                        if (!is_str)
                        {
                            OpenMessege("The name can only be Latin letters.", "Error");
                        }
                        else
                        {
                            Name = new_name;
                        }
                    }
                    if (new_surname != null && new_surname.Length > 0)
                    {
                        is_str = regex_str.IsMatch(new_surname);
                        if (!is_str)
                        {
                            OpenMessege("The surname can only be Latin letters.", "Error");
                        }
                        else
                        {
                            Surname = new_surname;
                        }
                    }


                    if (new_patronymic != null && new_patronymic.Length > 0)
                    {
                        is_str = regex_str.IsMatch(new_patronymic);
                        if (!is_str)
                        {
                            OpenMessege("In the patronymic there can be only Latin letters.", "Error");
                        }
                        else
                        {
                            Patronymic = new_patronymic;
                        }
                    }



                    if (password != null && password2 != null &&
                        password != password2 || password != null && password.Length < 1)
                    {
                        OpenMessege("The password must be at least one digit, one letter (English), a large letter and any character that is not a digit and not a letter, the maximum password length is 16 characters.", "Error");
                    }
                    else if (password != null && password2 != null)
                    {
                        bool is_ok = regex_password.IsMatch(password);

                        if (is_ok)
                        {
                            my_profile.Password = password;
                        }
                        else
                        {
                            OpenMessege("The password must be at least one digit, one letter (English), a large letter and any character that is not a digit and not a letter, the maximum password length is 16 characters.", "Error");
                        }
                    }

                    if (New_login != null)
                    {
                        bool is_oks_log = regex_login.IsMatch(New_login);

                        if (is_oks_log)
                        {
                            if (New_login != null && New_login.Length > 0)
                            {
                                bool iso = true;
                                foreach (var i in myDB.People)
                                {
                                    if (i.Login == New_login)
                                    {
                                        OpenMessege("This login is already in use.", "Error");
                                        iso = false;
                                    }
                                }
                                if (iso)
                                {
                                    my_profile.Login = Login = New_login;
                                }
                            }
                        }
                        else
                        {
                            OpenMessege("The user must have from 2 to 20 characters, which can be letters and numbers, the first character is necessarily a letter.", "Error");
                        }
                    }

                    if (select_item_family != null && select_item_right != null)
                    {
                        bool is_oke = true;

                        foreach (var i in myDB.People)
                        {
                            if (i.Right.Level < select_item_right.Level &&
                                i.Family == select_item_family)
                            {
                                is_oke = false;
                                Login            window = new Login();
                                Viwe_Model_Login view   = new Viwe_Model_Login(Visibility.Hidden, select_item_right.Level, select_item_family);

                                if (view._OK == null)
                                {
                                    view._OK = new Action(window.Ok);
                                }

                                view._Close = new Action(window.Close);

                                window.DataContext = view;
                                window.ShowDialog();

                                if (view.is_ok == true)
                                {
                                    my_profile.Family = select_item_family;
                                    Family_str        = select_item_family.Name;

                                    my_profile.FamilyID = select_item_family.ID;
                                    my_profile.RightsID = select_item_right.ID;
                                    my_profile.Right    = select_item_right;
                                }
                            }
                        }

                        if (is_oke)
                        {
                            my_profile.Family = select_item_family;
                            Family_str        = select_item_family.Name;

                            my_profile.FamilyID = select_item_family.ID;
                            my_profile.RightsID = select_item_right.ID;
                            my_profile.Right    = select_item_right;
                        }
                    }
                    else if (select_item_family != null && select_item_right == null ||
                             select_item_family == null && select_item_right != null)
                    {
                        OpenMessege("You did not select all the parameters in the family.", "Error");
                    }


                    if (new_secret_word != null && new_secret_word.Length > 0)
                    {
                        my_profile.Secret_word = new_secret_word;
                    }


                    var temp = myDB.People.ToList().Find(x => x.ID == my_profile.ID);
                    temp = my_profile;
                    myDB.SaveChanges();
                }
            }catch (Exception e) { OpenMessege(e.Message, "Error"); }
        }
        private void Execute_ok(object o)
        {
            try
            {
                bool is_oks     = regex_password.IsMatch(password);
                bool is_oks_log = regex_login.IsMatch(login);


                if (password != password2 || !is_oks)
                {
                    OpenMessege("The password must be at least one digit, one letter (English), a large letter and any character that is not a digit and not a letter, the maximum password length is 16 characters.", "Error");
                    return;
                }

                if (is_oks_log)
                {
                    foreach (var i in myDB.People)
                    {
                        if (i.Login == login)
                        {
                            OpenMessege("This login is already in use.", "Error");
                            return;
                        }
                    }
                }
                else
                {
                    OpenMessege("The user must have from 2 to 20 characters, which can be letters and numbers, the first character is necessarily a letter.", "Error");
                    return;
                }


                foreach (var i in myDB.People)
                {
                    if (select_item_right.Level != 3 &&
                        i.Right.Level == select_item_right.Level &&
                        i.Family == select_item_family)
                    {
                        OpenMessege("Confirm the account with more rights.", "Registration");


                        Login            window = new Login();
                        Viwe_Model_Login view   = new Viwe_Model_Login(Visibility.Hidden, select_item_right.Level, select_item_family);

                        if (view._OK == null)
                        {
                            view._OK = new Action(window.Ok);
                        }

                        view._Close = new Action(window.Close);

                        window.DataContext = view;
                        window.ShowDialog();

                        if (view.is_ok == false)
                        {
                            return;
                        }
                    }
                }


                bool is_str;

                is_str = regex_str.IsMatch(name);
                if (!is_str)
                {
                    OpenMessege("In the name, surname, patronymic can only be Latin letters.", "Error");
                    return;
                }


                is_str = regex_str.IsMatch(surname);
                if (!is_str)
                {
                    OpenMessege("In the name, surname, patronymic can only be Latin letters.", "Error");
                    return;
                }


                is_str = regex_str.IsMatch(patronymic);
                if (!is_str)
                {
                    OpenMessege("In the name, surname, patronymic can only be Latin letters.", "Error");
                    return;
                }


                Person temp = new Person();
                temp.Name       = name;
                temp.Surname    = surname;
                temp.Patronymic = patronymic;

                temp.Login       = login;
                temp.Password    = password;
                temp.Family      = select_item_family;
                temp.FamilyID    = select_item_family.ID;
                temp.RightsID    = select_item_right.ID;
                temp.Right       = select_item_right;
                temp.Secret_word = secret_word;
                myDB.People.Add(temp);
                myDB.SaveChanges();

                is_ok = true;

                OpenMessege("You are registered.", "Success");
                _OK();
            }catch (Exception e) { OpenMessege(e.Message, "Error"); }
        }