public MainWindow()
        {
            InitializeComponent();
            SetNotifyIcon();
            Context   = new GTContext();
            Occasions = new GTRepository <Occasion>(Context).GetAll();
            Occasions.CollectionChanged  += Occasions_CollectionChanged;
            occasionsDataGrid.ItemsSource = Occasions;

            peopleDataGrid.ItemsSource = new GTRepository <Person>(Context).GetAll();

            var gifts = new GTRepository <Gift>(Context).GetAll();

            //a way to filter an observable collection
            ICollectionView giftsView = CollectionViewSource.GetDefaultView(gifts);

            giftsView.Filter = (o) =>
            {
                Gift gift = (Gift)o;
                return(gift.Owner == null && gift.Occasion == null);
            };

            giftsDataGrid.ItemsSource = giftsView;

            notificationsComboBox.ItemsSource = new List <string>()
            {
                "day", "week", "month"
            };

            peopleDataGrid.MouseLeftButtonUp    += DataGrid_MouseLeftButtonUp <Person>;
            occasionsDataGrid.MouseLeftButtonUp += DataGrid_MouseLeftButtonUp <Occasion>;
            giftsDataGrid.MouseLeftButtonUp     += DataGrid_MouseLeftButtonUp <Gift>;
        }
        public AddOrEditPersonWindow(GTContext context, Person person = null)
        {
            InitializeComponent();
            PeopleRepository           = new GTRepository <Person>(context);
            OccasionsRepository        = new GTRepository <Occasion>(context);
            userImageItems.ItemsSource = Directory.EnumerateFiles(@"..\..\Images\DefaultUserImages", "*.png");

            if (person == null)
            {
                IsEdited        = false;
                TemporaryPerson = new Person();
                userImageItems.SelectedIndex = 0;
                userImageItems.Focus();
            }
            else
            {
                CurrentPerson   = person;
                TemporaryPerson = new Person()
                {
                    Image = person.Image, Name = person.Name, Birthday = person.Birthday
                };
                IsEdited = true;
            }
            this.DataContext = TemporaryPerson;
        }
        public AddOrEditGiftWindow(GTContext context, Gift gift = null)
        {
            Initialize(context);
            if (gift == null)
            {
                TemporaryGift = new Gift();
                NewGift();
                IsPersonal = false;
                onePersonCheckBox.IsEnabled = true;
                deleteButton.IsEnabled      = false;
            }
            else
            {
                CurrentGift   = gift;
                TemporaryGift = new Gift()
                {
                    Image = gift.Image, Name = gift.Name, WasGiven = gift.WasGiven, Description = gift.Description
                };
                IsEdited = true;
                if (CurrentGift.Owner != null && CurrentGift.Occasion != null)
                {
                    IsPersonal      = true;
                    CurrentPerson   = CurrentGift.Owner;
                    CurrentOccasion = CurrentGift.Occasion;
                }
                else
                {
                    IsPersonal = false;
                    onePersonCheckBox.IsEnabled = true;
                }
            }
            this.DataContext = TemporaryGift;

            OccasionRepository = new GTRepository <Occasion>(context);
            PeopleRepository   = new GTRepository <Person>(context);
            Context            = context;

            if (CurrentGift != null && CurrentGift.WasGiven)
            {
                hasBeenGivenCheckBox.IsChecked = true;
            }
        }
Beispiel #4
0
        public DetailsWindow(object item, GTContext context)
        {
            InitializeComponent();
            this.SizeToContent  = SizeToContent.WidthAndHeight;
            Context             = context;
            PeopleRepository    = new GTRepository <Person>(context);
            OccasionsRepository = new GTRepository <Occasion>(context);
            GiftsRepository     = new GTRepository <Gift>(context);

            if (item is Person person)
            {
                CurrentPerson = person;
            }
            else if (item is Occasion occasion)
            {
                CurrentOccasion = occasion;
                if (CurrentOccasion.Name == "New Year")
                {
                    deleteButton.Visibility = Visibility.Hidden;
                    editButton.Visibility   = Visibility.Hidden;
                }
                else
                {
                    deleteButton.Content = "Delete occasion";
                    editButton.Content   = "Edit occasion";
                    deleteButton.Tag     = "Occasion";
                    editButton.Tag       = "Occasion";
                }
            }
            else if (item is Gift gift)
            {
                CurrentGift          = gift;
                deleteButton.Content = "Delete gift";
                editButton.Content   = "Edit gift";
                deleteButton.Tag     = "Gift";
                editButton.Tag       = "Gift";
            }
            Load();
        }
        public AddOrEditOccasionWindow(GTContext context, Occasion occasion = null)
        {
            InitializeComponent();
            OccasionRepository = new GTRepository <Occasion>(context);
            PeopleRepository   = new GTRepository <Person>(context);
            People             = PeopleRepository.GetAll();
            severalPeopleListBox.ItemsSource = People;
            userImageItems.ItemsSource       = Directory.EnumerateFiles(@"..\..\Images\DefaultOccasionImages", "*.png");

            if (occasion == null)
            {
                IsEdited                     = false;
                TemporaryOccasion            = new Occasion();
                userImageItems.SelectedIndex = 0;
                userImageItems.Focus();
            }
            else
            {
                CurrentOccasion   = occasion;
                TemporaryOccasion = new Occasion()
                {
                    Image = occasion.Image, Name = occasion.Name, Date = occasion.Date
                };
                if (CurrentOccasion.People.Count < People.Count)
                {
                    severalPeopleCheckBox.IsChecked = true;
                    foreach (var person in People)
                    {
                        if (CurrentOccasion.People.Contains(person))
                        {
                            severalPeopleListBox.SelectedItems.Add(person);
                        }
                    }
                }
                IsEdited = true;
            }
            this.DataContext = TemporaryOccasion;
        }
 private void Initialize(GTContext context)
 {
     InitializeComponent();
     GiftRepository             = new GTRepository <Gift>(context);
     giftImageItems.ItemsSource = Directory.EnumerateFiles(@"..\..\Images\DefaultGiftImages", "*.png");
 }