예제 #1
0
 public AddNewPhoto(Entities.EFContext db)
 {
     InitializeComponent();
     Topmost     = true;
     _idCategory = 0;
     _db         = db;
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string      path   = null;
            BitmapImage bitmap = null;

            try
            {
                path   = Environment.CurrentDirectory + "\\connecting.png";
                bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(path);
                bitmap.EndInit();
                conIcon.Source = bitmap;
            }
            catch (Exception)
            {
                MessageBox.Show("Something wrong!");
            }

            try
            {
                ConnectionProvider connection = new ConnectionProvider();
                connection.ConectedEvent += (Entities.EFContext db) =>
                {
                    _db = db;
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        lblStatus.Content = "Status: Connected!";

                        var categories = db.Categories.AsQueryable();
                        comboBox.Items.Add("All photos");
                        foreach (var item in categories)
                        {
                            comboBox.Items.Add(item.NameOfCategory);
                        }

                        Photos.Db = _db;
                        comboBox.SelectedIndex = 0;
                        path   = Environment.CurrentDirectory + "\\complete.png";
                        bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource = new Uri(path);
                        bitmap.EndInit();
                        conIcon.Source = bitmap;
                    }));
                };
                connection.ConnectRun();
            }
            catch (Exception)
            {
                MessageBox.Show("Something wrong!");
            }
        }