コード例 #1
0
ファイル: MenuViewModel.cs プロジェクト: UkaszK95/AddressBook
        /// <summary> Uruchomienie nowego okna w celu edycji istniejącego elementu i odświeżenie listy elementów </summary>
        public void EditEntry()
        {
            try
            {
                this.idOfEditedItem = getIdOfSelectedItem();

                if (this.currentTableName.Equals("Addresses"))
                {
                    using (var ctx = new molkomEntities())
                    {
                        var address = ctx.Addresses.FirstOrDefault(x => x.id.Equals(idOfEditedItem));

                        if (address != null)
                        {
                            Thread newWindowThread = new Thread(new ThreadStart(() =>
                            {
                                SynchronizationContext.SetSynchronizationContext(
                                    new DispatcherSynchronizationContext(
                                        Dispatcher.CurrentDispatcher));

                                Window tempWindow = new AddressEditWindow(address, this.connectionString);

                                tempWindow.Closed += (s, e) =>
                                                     Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                                tempWindow.Show();
                                System.Windows.Threading.Dispatcher.Run();
                            }));

                            newWindowThread.SetApartmentState(ApartmentState.STA);
                            newWindowThread.IsBackground = true;
                            newWindowThread.Start();

                            while (true)
                            {
                                if (GlobalVariables.refreshMainWindowFlag == 1)
                                {
                                    LoadAdressBookDisplayWindow();
                                    break;
                                }
                                else if (GlobalVariables.refreshMainWindowFlag == 2)
                                {
                                    break;
                                }
                            }
                            OnPropertyChanged("DisplaySource");

                            GlobalVariables.refreshMainWindowFlag = 0;
                        }
                    }
                }
                else if (this.currentTableName.Equals("Cities"))
                {
                    using (var ctx = new molkomEntities())
                    {
                        var city = ctx.Cities.FirstOrDefault(x => x.id.Equals(idOfEditedItem));

                        if (city != null)
                        {
                            Thread newWindowThread = new Thread(new ThreadStart(() =>
                            {
                                SynchronizationContext.SetSynchronizationContext(
                                    new DispatcherSynchronizationContext(
                                        Dispatcher.CurrentDispatcher));

                                Window tempWindow = new CityEditWindow(city, this.connectionString);

                                tempWindow.Closed += (s, e) =>
                                                     Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                                tempWindow.Show();
                                System.Windows.Threading.Dispatcher.Run();
                            }));

                            newWindowThread.SetApartmentState(ApartmentState.STA);
                            newWindowThread.IsBackground = true;
                            newWindowThread.Start();

                            while (true)
                            {
                                if (GlobalVariables.refreshMainWindowFlag == 1)
                                {
                                    LoadCitiesDisplayWindow();
                                    break;
                                }
                                else if (GlobalVariables.refreshMainWindowFlag == 2)
                                {
                                    break;
                                }
                            }
                            OnPropertyChanged("DisplaySource");

                            GlobalVariables.refreshMainWindowFlag = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
ファイル: MenuViewModel.cs プロジェクト: UkaszK95/AddressBook
        /// <summary> Uruchomienie nowego okna w celu dodania nowego elementu do bazy danych i listy </summary>
        public void AddEntry()
        {
            try
            {
                if (this.currentTableName.Equals("Addresses"))
                {
                    this.IndexBind            = -1;
                    this.SelectedListViewItem = null;

                    Thread newWindowThread = new Thread(new ThreadStart(() =>
                    {
                        SynchronizationContext.SetSynchronizationContext(
                            new DispatcherSynchronizationContext(
                                Dispatcher.CurrentDispatcher));

                        Window tempWindow = new AddressEditWindow(this.connectionString);

                        tempWindow.Closed += (s, e) =>
                                             Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                        tempWindow.Show();
                        System.Windows.Threading.Dispatcher.Run();
                    }));

                    newWindowThread.SetApartmentState(ApartmentState.STA);
                    newWindowThread.IsBackground = true;
                    newWindowThread.Start();

                    while (true)
                    {
                        if (GlobalVariables.refreshMainWindowFlag == 1)
                        {
                            LoadAdressBookDisplayWindow();
                            break;
                        }
                        else if (GlobalVariables.refreshMainWindowFlag == 2)
                        {
                            break;
                        }
                        OnPropertyChanged("DisplaySource");
                    }
                    LoadAdressBookDisplayWindow();
                    OnPropertyChanged("DisplaySource");

                    GlobalVariables.refreshMainWindowFlag = 0;
                }
                else if (currentTableName.Equals("Cities"))
                {
                    this.IndexBind            = -1;
                    this.SelectedListViewItem = null;

                    Thread newWindowThread = new Thread(new ThreadStart(() =>
                    {
                        SynchronizationContext.SetSynchronizationContext(
                            new DispatcherSynchronizationContext(
                                Dispatcher.CurrentDispatcher));

                        Window tempWindow = new CityEditWindow(this.connectionString);

                        tempWindow.Closed += (s, e) =>
                                             Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                        tempWindow.Show();
                        System.Windows.Threading.Dispatcher.Run();
                    }));

                    newWindowThread.SetApartmentState(ApartmentState.STA);
                    newWindowThread.IsBackground = true;
                    newWindowThread.Start();

                    while (true)
                    {
                        if (GlobalVariables.refreshMainWindowFlag == 1)
                        {
                            LoadCitiesDisplayWindow();
                            break;
                        }
                        else if (GlobalVariables.refreshMainWindowFlag == 2)
                        {
                            break;
                        }
                        OnPropertyChanged("DisplaySource");
                    }
                    LoadCitiesDisplayWindow();
                    OnPropertyChanged("DisplaySource");

                    GlobalVariables.refreshMainWindowFlag = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }