Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Messaging;
- using MVVMFirma.Helpers;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Data;
- using System.Windows.Input;
- namespace MVVMFirma.ViewModel
- {
- public class MainWindowViewModel : BaseViewModel
- {
- #region Fields
- // to jest kolekcja przechowujaca listę komend, które pojawiaja sie z lewej strony
- ReadOnlyCollection<CommandViewModel> _Commands;
- // to jest kolekcja przechowujaca liste zakładek z prawej strony
- ObservableCollection<WorkspaceViewModel> _Workspaces;
- // przekazuje se komendoo z mejnuindo
- public RelayCommand<string> SendByCommand { get; private set; }
- #endregion Fields
- #region Constructor
- public MainWindowViewModel()
- {
- Messenger.Default.Register<string>(this, createObject);
- SendByCommand = new RelayCommand<string>(param => createObject(param));
- }
- #endregion Constructor
- #region Commands
- //to jest properties do kolekcji linkow
- public ReadOnlyCollection<CommandViewModel> Commands
- {
- get
- {
- if (_Commands == null)
- {
- //Jezeli zbior komend jest pusty
- //tworze chwilowa liste, tylko po to by ja wypelnic
- List<CommandViewModel> cmds = this.CreateCommands();
- //i zrobic z niej kolekcje tylko do odczytu
- _Commands = new ReadOnlyCollection<CommandViewModel>(cmds);
- }
- return _Commands;
- }
- }
- // to jest funkcja, która tworzy komendy z lewej strony
- public List<CommandViewModel> CreateCommands()
- {
- return new List<CommandViewModel>
- {
- new CommandViewModel("Wszystkie Samochody",
- new BaseCommand(()=>this.showAllObjects<WszystkieSamochodyViewModel>())),
- new CommandViewModel("Nowy Samochod",
- new BaseCommand(()=>this.createObject<NowySamochodViewModel>())),
- new CommandViewModel("Wszyscy Klienci",
- new BaseCommand(()=>this.showAllObjects<WszyscyKlienciViewModel>())),
- new CommandViewModel("Kolory",
- new BaseCommand(()=>this.showAllObjects<WszystkieKoloryViewModel>())),
- new CommandViewModel("Nowy Kolor",
- new BaseCommand(()=>this.createObject<NowyKolorViewModel>())),
- new CommandViewModel("Rodzaje Napędów",
- new BaseCommand(()=>this.showAllObjects<WszystkieRodzajeNapedowViewModel>())),
- new CommandViewModel ("Nowy Rodzaj Napedow",
- new BaseCommand (()=>this.createObject<NowyRodzajeNapedowViewModel>())),
- new CommandViewModel("Nowy status",
- new BaseCommand (()=>this.createObject<NowyStatusViewModel>())),
- new CommandViewModel("Statusy",
- new BaseCommand(()=>this.showAllObjects<WszystkieStatusyViewModel>())),
- new CommandViewModel("Nowy rodzaj skrzynii biegow",
- new BaseCommand(()=>this.createObject<NowyRodzajSkrzyniiBiegowViewModel>())),
- new CommandViewModel("Rodzaje skrzyni biegów",
- new BaseCommand(()=>this.showAllObjects<WszystkieRodzajeSkrzyniiBiegowViewModel>())),
- new CommandViewModel("Typy Transakcji",
- new BaseCommand(()=>this.showAllObjects<WszystkieTypyTransakcjiViewModel>())),
- new CommandViewModel("Nowy Typ Transakcji",
- new BaseCommand(()=>this.createObject<NowyTypTransakcjiViewModel>())),
- new CommandViewModel("Rodzaje Płatności",
- new BaseCommand(()=>this.showAllObjects<WszystkieRodzajePlatnosciViewModel>())),
- new CommandViewModel("Nowy Rodzaj Płatności",
- new BaseCommand(()=>this.createObject<NowyRodzajPlatnosciViewModel>())),
- new CommandViewModel("Faktury",
- new BaseCommand(()=>this.showAllObjects<WszystkieFakturyViewModel>())),
- new CommandViewModel("Nowa Faktura",
- new BaseCommand(()=>this.createObject<NowaFakturaViewModel>())),
- new CommandViewModel("Umowy",
- new BaseCommand(()=>this.showAllObjects<WszystkieUmowyViewModel>())),
- new CommandViewModel("Nowa Umowa",
- new BaseCommand(()=>this.createObject<NowaUmowaViewModel>())),
- new CommandViewModel("Nowy typ nadwozia",
- new BaseCommand(()=>this.createObject<NowyTypNadwoziaViewModel>())),
- new CommandViewModel("Wszystkie typy nadwozia",
- new BaseCommand(()=>this.showAllObjects<WszystkieTypyNadwoziaViewModel>())),
- new CommandViewModel("Nowy Rodzaj Wyposażenia",
- new BaseCommand(()=>this.createObject<NoweWyposazenieViewModel>())),
- new CommandViewModel("Wszystkie typy wyposażenia",
- new BaseCommand(()=>this.showAllObjects<WszystkieWyposazeniaViewModel>())),
- new CommandViewModel("Nowy klient",
- new BaseCommand(()=>this.createObject<NowyKlientViewModel>())),
- new CommandViewModel("Nowa Transakcja",
- new BaseCommand(()=>this.createObject<NowaTransakcjaViewModel>())),
- new CommandViewModel("Nowa Marka",
- new BaseCommand(()=>this.createObject<NowaMarkaViewModel>())),
- new CommandViewModel("Wszystkie marki",
- new BaseCommand(()=>this.createObject<WszystkieMarkiViewModel>())),
- new CommandViewModel("Nowy Stan",
- new BaseCommand(()=>this.createObject<NowyStanViewModel>())),
- new CommandViewModel("Wszystkie stany",
- new BaseCommand(()=>this.createObject<WszystkieStanyViewModel>())) ,
- new CommandViewModel("Nowy model",
- new BaseCommand(()=>this.createObject<NowyModelViewModel>())),
- new CommandViewModel("Wszystkie modele",
- new BaseCommand(()=>this.ShowAllModele())),
- new CommandViewModel("Nowe Zdjecia",
- new BaseCommand(()=>this.createObject<NoweZdjeciaViewModel>())),
- new CommandViewModel("Wszystkie zdjecia",
- new BaseCommand(()=>this.createObject<WszystkieZdjeciaViewModel>())),
- new CommandViewModel("Nowy Rodzaj Koloru",
- new BaseCommand(()=>this.createObject<NowyRodzajKoloruViewModel>())),
- new CommandViewModel("Wszystkie Adresy",
- new BaseCommand(()=>this.showAllObjects<WszystkieAdresyViewModel>())),
- new CommandViewModel("Wszystkie Kraje",
- new BaseCommand(()=>this.showAllObjects<WszystkieKrajeViewModel>())),
- new CommandViewModel("Wszystkie Wersje",
- new BaseCommand(()=>this.showAllObjects<WszystkieWersjeViewModel>())),
- new CommandViewModel("Nowa Wersja",
- new BaseCommand(()=>this.createObject<NowaWersjaViewModel>())),
- new CommandViewModel("Wersje Dla Samochodu",
- new BaseCommand(()=>this.createObject<WersjeDlaSamochoduViewModel>())),
- new CommandViewModel("Klienci w miastach",
- new BaseCommand(()=>this.createObject<KlienciWMiastachViewModel>())),
- new CommandViewModel("Wszystkie Rodzaje Koloru",
- new BaseCommand(()=>this.createObject<WszystkieRodzajeKolorowViewModel>())),
- new CommandViewModel("Wszyscy pracownicy",
- new BaseCommand(()=>this.createObject<WszyscyPracownicyViewModel>())),
- //Raporty
- new CommandViewModel("Raport wydatków klienta",
- new BaseCommand(()=>this.showAllObjects<RaportWydatkowKlientaViewModel>())),
- new CommandViewModel("Raport ilości kolorów wybranego modelu",
- new BaseCommand(()=>this.showAllObjects<RaportIloscKolorowDanegoModeluViewModel>())),
- new CommandViewModel("Raport ilości transakcji wybranego pracownika",
- new BaseCommand(()=>this.showAllObjects<RaportIlosciTransakcjiPracownikaViewModel>())),
- new CommandViewModel("Raport sumy transakcji wybranego pracownika wg daty",
- new BaseCommand(()=>this.showAllObjects<RaportSumyTransakcjiPracownikaViewModel>())),
- new CommandViewModel("Raport umów wybranego pracownika",
- new BaseCommand(()=>this.showAllObjects<RaportUmowPracownikaViewModel>())),
- new CommandViewModel("Raport wartości transakcji w wybranym okresie dla danego modelu",
- new BaseCommand(()=>this.showAllObjects<RaportSamochodyViewModel>())),
- new CommandViewModel("Raport wartości sprzedazy wg marki",
- new BaseCommand(()=>this.showAllObjects<RaportSprzedazyWgMarkiViewModel>())),
- new CommandViewModel("Raport klienci wg miejscowosci",
- new BaseCommand(()=>this.showAllObjects<RaportKlienciMiejscowoscViewModel>())),
- new CommandViewModel("Raport VAT",
- new BaseCommand(()=>this.showAllObjects<RaportFakturViewModel>())),
- new CommandViewModel("Raport Umow",
- new BaseCommand(()=>this.showAllObjects<RaportUmowViewModel>())),
- new CommandViewModel("Raport zdjec",
- new BaseCommand(()=>this.showAllObjects<RaportIlosciZdjecViewModel>())),
- new CommandViewModel("Sprzedaz Procentowa po modelach",
- new BaseCommand(()=>this.showAllObjects<RaportSprzedazyProcentowejPoModelachViewModel>())),
- new CommandViewModel("Wartosc Sprzedazy po typach nadwozia",
- new BaseCommand(()=>this.showAllObjects<RaportSprzedazyPoTypachNadwoziaViewModel>())),
- new CommandViewModel("Raport wyposazen",
- new BaseCommand(()=>this.showAllObjects<RaportIlosciWyposazenSamochodu>()))
- };
- }
- #endregion Commands
- #region Workspaces
- public ObservableCollection<WorkspaceViewModel> Workspaces
- {
- get
- {
- if (_Workspaces == null)
- {
- _Workspaces = new ObservableCollection<WorkspaceViewModel>();
- _Workspaces.CollectionChanged += this.OnWorkspacesChanged;
- }
- return _Workspaces;
- }
- }
- void OnWorkspacesChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- if (e.NewItems != null && e.NewItems.Count != 0)
- {
- foreach (WorkspaceViewModel workspace in e.NewItems)
- {
- workspace.RequestClose += this.OnWorkspaceRequestClose;
- }
- }
- if (e.OldItems != null && e.OldItems.Count != 0)
- {
- foreach (WorkspaceViewModel workspace in e.OldItems)
- {
- workspace.RequestClose -= this.OnWorkspaceRequestClose;
- }
- }
- }
- void OnWorkspaceRequestClose(object sender, EventArgs e)
- {
- WorkspaceViewModel workspace = sender as WorkspaceViewModel;
- this.Workspaces.Remove(workspace);
- }
- #endregion Workspaces
- #region PrivateHelpers
- //
- // tutaj modyfikacja kodu
- //
- //
- private void ShowAllModele()
- {
- WszystkieModeleViewModel workspace =
- this.Workspaces.FirstOrDefault(vm => vm is WszystkieModeleViewModel)
- as WszystkieModeleViewModel;
- if (workspace == null)
- {
- workspace = new WszystkieModeleViewModel();
- this.Workspaces.Add(workspace);
- }
- this.setActiveWorkspace(workspace);
- }
- private void createObject<T>() where T : WorkspaceViewModel, new()
- {
- T workspace = new T();
- Workspaces.Add(workspace);
- setActiveWorkspace(workspace);
- }
- private void showAllObjects<T>() where T : WorkspaceViewModel, new()
- {
- T workspace =
- Workspaces.FirstOrDefault
- (vm => vm is T)
- as T;
- if (workspace == null)
- {
- workspace = new T();
- Workspaces.Add(workspace);
- }
- setActiveWorkspace(workspace);
- }
- private void createObject(string typeName)
- {
- if (typeName == "NowaFaktura") createObject<NowaFakturaViewModel>();
- if (typeName == "NowaUmowa") createObject<NowaUmowaViewModel>();
- if (typeName == "NoweWyposazenie") createObject<NoweWyposazenieViewModel>();
- if (typeName == "NowyKolor") createObject<NowyKolorViewModel>();
- if (typeName == "NowyRodzajNapedu") createObject<NowyRodzajeNapedowViewModel>();
- if (typeName == "NowyRodzajPlatnosci") createObject<NowyRodzajPlatnosciViewModel>();
- if (typeName == "NowyRodzajSkrzynii") createObject<NowyRodzajSkrzyniiBiegowViewModel>();
- if (typeName == "NowyStatus") createObject<NowyStatusViewModel>();
- if (typeName == "NowyTypNadwozia") createObject<NowyTypNadwoziaViewModel>();
- if (typeName == "NowyTypTransakcji") createObject<NowyTypTransakcjiViewModel>();
- if (typeName == "NowyKlient") createObject<NowyKlientViewModel>();
- if (typeName == "NowaTransakcja") createObject<NowaTransakcjaViewModel>();
- if (typeName == "NowaMarka") createObject<NowaMarkaViewModel>();
- if (typeName == "NowyStan") createObject<NowyStanViewModel>();
- if (typeName == "NowySamochod") createObject<NowySamochodViewModel>();
- //stworzone na potrzeby menu!
- if (typeName == "NowyModel") createObject<NowyModelViewModel>();
- if (typeName == "NowaWersja") createObject<NowaWersjaViewModel>();
- if (typeName == "NowyRodzajKoloru") createObject<NowyRodzajKoloruViewModel>();
- if (typeName == "NoweZdjecia") createObject<NoweZdjeciaViewModel>();
- //if (typeName == "NowyKraj") createObject<NowyKrajViewModel>();
- //if (typeName == "NowyAdres") createObject<NowyAdresViewModel>();
- //wszystkie
- if (typeName == "KlientShow") showAllObjects<WszyscyKlienciViewModel>();
- if (typeName == "StatusyShow") createObject<WszystkieStatusyViewModel>();
- if (typeName == "TypyTransakcjiShow") createObject<WszystkieTypyTransakcjiViewModel>();
- if (typeName == "RodzajePlatnosciShow") createObject<WszystkieRodzajePlatnosciViewModel>();
- if (typeName == "FakturyShow") createObject<WszystkieFakturyViewModel>();
- if (typeName == "UmowyShow") createObject<WszystkieUmowyViewModel>();
- if (typeName == "SamochodyShow") createObject<WszystkieSamochodyViewModel>();
- if (typeName == "MarkiShow") createObject<WszystkieMarkiViewModel>();
- if (typeName == "KoloryShow") createObject<WszystkieKoloryViewModel>();
- if (typeName == "RodzajeKolorowShow") createObject<WszystkieRodzajeKolorowViewModel>();
- if (typeName == "RodzajeNapedowShow") createObject<WszystkieRodzajeNapedowViewModel>();
- if (typeName == "RodzajeSkrzyniiShow") createObject<WszystkieRodzajeSkrzyniiBiegowViewModel>();
- if (typeName == "TypyNadwoziaShow") createObject<WszystkieTypyNadwoziaViewModel>();
- if (typeName == "WyposazeniaShow") createObject<WszystkieWyposazeniaViewModel>();
- if (typeName == "StanyShow") createObject<WszystkieStanyViewModel>();
- if (typeName == "ZjeciaShow") createObject<WszystkieZdjeciaViewModel>();
- if (typeName == "WersjeShow") createObject<WszystkieWersjeViewModel>();
- if (typeName == "ModeleShow") createObject<WszystkieModeleViewModel>();
- if (typeName == "KrajeShow") createObject<WszystkieKrajeViewModel>();
- if (typeName == "AdresyShow") createObject<WszystkieAdresyViewModel>();
- //zamykanie apki
- if (typeName == "ZamknijProgram") System.Environment.Exit(1);
- //pomoc
- if (typeName == "PomocProgramu") MessageBox.Show("Autorzy: WSB-NLU Informatyka niestacjonarne 2013 - 2017." + Environment.NewLine + "Kontakt: pz.wsb-nlu.gr1@outlook.com", "Pomoc: Komis samochodowy 2017");
- //ustawienia
- if (typeName == "UstawieniaProgramu") MessageBox.Show("Ustawienia programu.", "Ustawienia");
- if (typeName == "NowaWersja") createObject<NowaWersjaViewModel>();
- }
- private void setActiveWorkspace(WorkspaceViewModel workspace)
- {
- Debug.Assert(this.Workspaces.Contains(workspace));
- ICollectionView collectionView = CollectionViewSource.GetDefaultView(this.Workspaces);
- if (collectionView != null)
- {
- collectionView.MoveCurrentTo(workspace);
- }
- }
- #endregion PrivateHelpers
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement