Exemple #1
0
        /// <summary>
        /// Edit existing Course
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditCourse_Click(object sender, RoutedEventArgs e)
        {
            bool   exitCancel = false;
            bool   normalExit = true;
            Window window     = new Window()
            {
                Title                 = "Create course",
                ResizeMode            = ResizeMode.NoResize,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.Loaded += delegate(object o, RoutedEventArgs args)
            {
                LanguageSelection language = new LanguageSelection()
                {
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                };
                window.Width           = language.Width + 15;
                window.Height          = language.Height + 40;
                window.Content         = language;
                language.button.Click += delegate(object obj, RoutedEventArgs Args)
                {
                    LanguageSelection control = (LanguageSelection)window.Content;
                    long   id               = _courseImagesCache[_selectedLanguage.Name];
                    string nation           = control.GetSelectedNation();
                    string selectedLanguage = _languages.GetLanguageName(nation);
                    if (selectedLanguage != null)
                    {
                        if (!ExistingCourse(control.GetSelectedLanguageIcon()))
                        {
                            _courseImagesCache.Remove(_selectedLanguage.Name);
                            _courseImagesCache[control.GetSelectedLanguageIcon()] = id;
                            _contentManager.EditCourse(id, selectedLanguage, control.GetSelectedLanguageIcon());
                            _selectedLanguage.Source = new BitmapImage(new Uri(control.GetSelectedLanguageIcon()));
                            exitCancel = false;
                            normalExit = false;
                            window.Close();
                        }
                        else
                        {
                            MessageBox.Show("Course already exists!");
                            exitCancel = true;
                            normalExit = true;
                        }
                    }
                };
            };
            window.Closing += delegate(object o, CancelEventArgs args)
            {
                if (!normalExit)
                {
                    if (exitCancel)
                    {
                        args.Cancel = true;
                    }
                }
            };
            window.ShowDialog();
        }
Exemple #2
0
        /// <summary>
        /// Add new Course
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonAddCourse_OnClick(object sender, RoutedEventArgs e)
        {
            Window window = new Window()
            {
                Title                 = "Create course",
                ResizeMode            = ResizeMode.NoResize,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.Loaded += delegate(object o, RoutedEventArgs args)
            {
                LanguageSelection language = new LanguageSelection()
                {
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                };
                window.Width           = language.Width + 15;
                window.Height          = language.Height + 40;
                window.Content         = language;
                language.button.Click += delegate(object obj, RoutedEventArgs Args)
                {
                    LanguageSelection control          = (LanguageSelection)window.Content;
                    string            nation           = control.GetSelectedNation();
                    string            selectedLanguage = _languages.GetLanguageName(nation);
                    if (selectedLanguage != null)
                    {
                        long id = _contentManager.AddCourse(selectedLanguage, control.GetSelectedLanguageIcon());
                        if (id > 0) //new course created
                        {
                            string uri   = control.GetSelectedLanguageIcon();
                            Image  image = new Image()
                            {
                                Source     = new BitmapImage(new Uri(uri)),
                                RenderSize = new Size(100, 100),
                                MaxHeight  = 100,
                                MaxWidth   = 100,
                                Margin     = new Thickness(10),
                                Opacity    = 0.5,
                                Name       = "Image_" + id
                            };
                            image.MouseUp += delegate(object senderImage, MouseButtonEventArgs eventArgs)
                            {
                                ImageCourse_Click(senderImage as Image);
                            };
                            if (!_courseImagesCache.ContainsKey(image.Name))
                            {
                                _courseImagesCache[image.Name] = id;
                                Courses.Children.Add(image);
                                ImageCourse_Click(image);
                                AddEducationalLevel.IsEnabled = true;
                                EditCourse.IsEnabled          = true;
                                DeleteCourse.IsEnabled        = true;
                            }
                            else
                            {
                                image = null;
                            }
                        }// -1 - error; 0 - already exists
                        window.Close();
                    }
                };
            };
            window.ShowDialog();
        }