예제 #1
0
        public void loadServices(String service_name)
        {
            ScatterView sv = ((ScatterView)MainView.GetWindow(this).FindName("MainScatterView"));
            sv.Items.Clear();

            // init trashbin
            StaticField.trashSVI = new TrashBinScatterViewItem(new TrashBin());
            sv.Items.Add(StaticField.trashSVI);

            var dataTemplate = new ObservableCollection<Trash>();

            foreach (ProviderType provider_type in StaticField.wedding.service_types)
            {
                if (provider_type.name == service_name)
                {

                    foreach (Provider pr in provider_type.services)
                    {
                        ProviderTemplate pt = new ProviderTemplate(pr);
                        if (pr.activated)
                        {
                            sv.Items.Add(new ProviderScatterViewItem(pt));
                        }
                        else
                        {
                            Trash trash = new Trash(pt, pt.ProviderImage.Source);
                            dataTemplate.Add(trash);
                        }
                    }
                    StaticField.trashSVI.trashBin.ItemsSource = dataTemplate;
                }
            }
        }
        void ProviderScatterViewItem_ContactUp(object sender, ContactEventArgs e)
        {
            TrashBin t = StaticField.trashSVI.trashBin;

            ProviderScatterViewItem s = sender as ProviderScatterViewItem;
            ScatterViewItem trashSVI = StaticField.trashSVI;

            Point centerS = s.ActualCenter;
            Point centerTrashSVI = trashSVI.ActualCenter;

            double trashSVIWidth = trashSVI.ActualWidth;
            double trashSVIHeight = trashSVI.ActualHeight;

            double max = Math.Min(trashSVIHeight, trashSVIWidth);

            if ((centerS.X <= centerTrashSVI.X + max / 2) &&
                (centerS.X >= centerTrashSVI.X - max / 2) &&
                (centerS.Y <= centerTrashSVI.Y + max / 2) &&
                (centerS.Y >= centerTrashSVI.Y - max / 2))
            {

                ObservableCollection<Trash> dataTemplate = (ObservableCollection<Trash>) t.ItemsSource;

                if (dataTemplate == null)
                {
                    dataTemplate = new ObservableCollection<Trash>();
                }

                Trash trash = new Trash(s.providerTemplate, s.providerTemplate.ProviderImage.Source);
                dataTemplate.Add(trash);

                t.ItemsSource = dataTemplate;

                // loop over Wedding services to disactivate
                var st = StaticField.wedding.service_types;
                for (int i = 0; i < st.Count; i++)
                {
                    for (int j = 0; j < st[i].services.Count; j++)
                    {
                        if (s.providerTemplate.provider.id == st[i].services[j].id)
                        {
                            st[i].services[j].activated = false;
                            Console.WriteLine("GOT IT !" + st[i].services[j].activated);
                        }
                    }
                }

                // loop over all scattersView to delete
                ScatterView sv = ((ScatterView)MainView.GetWindow(this).FindName("MainScatterView"));
                ItemCollection tmp = (ItemCollection) sv.Items;
                tmp.Remove(s);
            }
        }