/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EditGrade_Click(object sender, RoutedEventArgs e) { bool exitCancel = false; bool normalExit = true; Window window = new Window() { Title = "Create grade", ResizeMode = ResizeMode.NoResize, WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.Loaded += delegate(object o, RoutedEventArgs args) { if (_selectedEducationalLevel != null) { EducationalLevelType type = (_contentManager.GetComponent(_educationalLevelDictionary[_selectedEducationalLevel.Name]) as EducationalLevel).Level; GradeSelection grade = new GradeSelection(type) { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, }; window.Width = grade.Width + 35; window.Height = grade.Height + 40; window.Content = grade; grade.button.Click += delegate(object obj, RoutedEventArgs Args) { GradeSelection control = window.Content as GradeSelection; long id = _gradesDictionary[_selectedGrade.Name]; string icon = control.GetSelectedIcon(); GradeType gradeType = control.GetSelectedGrade(); if (icon != "") { if (_selectedEducationalLevel != null) { if (!ExistingGrade(_selectedGrade.Name)) { _contentManager.EditGrade(id, icon, gradeType); _selectedGrade.Source = new BitmapImage(new Uri(icon)); exitCancel = false; normalExit = false; window.Close(); } else { MessageBox.Show("Grade already exists!"); exitCancel = true; normalExit = true; } } } }; } else { window.Close(); } }; window.Closing += delegate(object o, CancelEventArgs args) { if (!normalExit) { if (exitCancel) { args.Cancel = true; } } }; window.ShowDialog(); }
/// <summary> /// Add new Grade /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonAddGrade_Click(object sender, RoutedEventArgs e) { Window window = new Window() { Title = "Create grade", ResizeMode = ResizeMode.NoResize, WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.Loaded += delegate(object o, RoutedEventArgs args) { if (_selectedEducationalLevel != null) { long value = _educationalLevelDictionary[_selectedEducationalLevel.Name]; Component component = _contentManager.GetComponent(value); EducationalLevelType type = (component as EducationalLevel).Level; GradeSelection grade = new GradeSelection(type) { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, }; window.Width = grade.Width + 35; window.Height = grade.Height + 40; window.Content = grade; grade.button.Click += delegate(object obj, RoutedEventArgs Args) { GradeSelection control = window.Content as GradeSelection; string icon = control.GetSelectedIcon(); GradeType gradeType = control.GetSelectedGrade(); if (icon != "") { if (_selectedEducationalLevel != null) { long id = _contentManager.AddGrade(_educationalLevelDictionary[_selectedEducationalLevel.Name], icon, gradeType); if (id > 0) //new edu level created { Image image = new Image() { Source = new BitmapImage(new Uri(icon)), RenderSize = new Size(100, 100), MaxHeight = 100, MaxWidth = 100, Margin = new Thickness(15), Opacity = 0.5, Name = "Image_" + id }; image.MouseUp += delegate(object senderImage, MouseButtonEventArgs eventArgs) { ImageGrade_Click(senderImage as Image); }; if (!_gradesDictionary.ContainsKey(image.Name)) { _gradesDictionary[image.Name] = id; WrapPanelGrades.Children.Add(image); ImageGrade_Click(image); } else { image = null; } }// -1 - error; 0 - already exists } } window.Close(); }; } else { window.Close(); } }; window.ShowDialog(); }