private void Log_in_button_Click(object sender, RoutedEventArgs e) { if (Models_Combobox.SelectedIndex < 0) { MessageBox.Show("Выберите модель из списка"); return; } string model = Models_Combobox.SelectedItem.ToString(); string Cur_dir = Directory.GetCurrentDirectory(); string model_dir = Cur_dir + "\\" + model; if (!Directory.Exists(model_dir)) { MessageBox.Show("Модель не существует!"); Models.Remove(model); return; } if (!Is_Model_Valid(model_dir)) { if (MessageBox.Show("Модель повреждена! Удалить каталог?", "Ошибка модели", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Directory.Delete(model_dir, true); Models.Remove(model); } else { Models.Remove(model); } return; } string login = Login_textbox.Text; List <Model_Subject> subjects = JsonConvert.DeserializeObject <List <Model_Subject> > (File.ReadAllText(model_dir + "\\Subject_list.json")); Model_Subject subject = subjects.Find(s => s.Login == login); if (subject == null || Model_Subject.Get_Hash(Passwordbox.Password) != subject.Password_hash) { MessageBox.Show("Неверный логин или пароль!"); return; } Passwordbox.Clear(); this.Visibility = Visibility.Hidden; if (subject.Security_Level == 0) { Administrator_Window administrator_Window = new Administrator_Window(subject, model); administrator_Window.ShowDialog(); } else { User_Window user_Window = new User_Window(subject, model); user_Window.ShowDialog(); } this.Visibility = Visibility.Visible; Login_textbox.Clear(); }
private void Remove_subject_button_Click(object sender, RoutedEventArgs e) { int index = Subject_combobox.SelectedIndex; if (index < 0) { MessageBox.Show("Выберите пользователя"); return; } Model_Subject subject = Subjects[index]; if (subject.Security_Level == 0 && Subjects.Count(s => s.Security_Level == 0) == 1) { MessageBox.Show("Невозможно удалить всех администраторов!"); return; } Subjects.RemoveAt(index); }
private void Create_model_button_Click(object sender, RoutedEventArgs e) { string login = Login_textbox.Text; string model_name = Model_name_textbox.Text; if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(Passwordbox.Password) || string.IsNullOrEmpty(model_name)) { MessageBox.Show("Заполните все поля"); return; } string directory = Directory.GetCurrentDirectory(); string model_directory = directory + "\\" + model_name; if (Directory.GetDirectories(directory).Contains(model_directory)) { MessageBoxResult result = MessageBox.Show("Директория с таким названием уже существует. Удалить и записать заново?", "Неверное имя", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { return; } Directory.Delete(model_directory, true); } Directory.CreateDirectory(model_directory); using (StreamWriter sw = new StreamWriter(model_directory + "\\Object_list.json")) sw.Write(""); Model_Subject model_Subject = new Model_Subject(login, 0, Passwordbox.Password, false); string serialized_subjects = JsonConvert.SerializeObject(new ObservableCollection <Model_Subject>() { model_Subject }); using (StreamWriter sw = new StreamWriter((model_directory + "\\Subject_list.json"))) sw.Write(serialized_subjects); this.Close(); }
public static void Create_Object(string name, string sec_lvl, ObservableCollection<Model_Object> objects, string model, Model_Subject current_subject) { if (string.IsNullOrWhiteSpace(name) || objects.Any(s => s.Name == name) || !int.TryParse(sec_lvl, out int Security_Level) || Security_Level < 0) { MessageBox.Show("Данные введены неверно. Избегайте дублей имен. Уровень доступа должен быть целым неотрицательным числом"); return; } if (current_subject.Security_Level < Security_Level) { MessageBox.Show("Данный пользователь не может создать заметку с таким уровнем доступа"); return; } objects.Add(new Model_Object(name, model, Security_Level, current_subject.Login)); File.Create($"{Directory.GetCurrentDirectory()}\\{model}\\{name}.txt").Close(); Open_Object(objects, objects.Count - 1, current_subject.Security_Level, true); }
private void Create_button_Click(object sender, RoutedEventArgs e) { Name_textbox.Focus(); if (Subject_radiobutton.IsChecked == true) { Model.Create_Subject(Name_textbox.Text, Security_level_textbox.Text, Subjects, Model_Subject.Get_Hash(Passwordbox.Password)); Passwordbox.Clear(); } else { Model.Create_Object(Name_textbox.Text, Security_level_textbox.Text, Objects, Model_Name, Current_User); } Name_textbox.Clear(); Security_level_textbox.Clear(); }
public Administrator_Window(Model_Subject subject, string model) { InitializeComponent(); Current_User = subject; Model_Name = model; }
public User_Window(Model_Subject subject, string model) { InitializeComponent(); Current_User = subject; this.Model_Name = model; }