コード例 #1
0
        private void buttonSearchNanny_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                nannyList = bl.getAllNanny();

                if (checkBoxNannyByTamt.IsChecked == true)
                {
                    nannyList = from a in nannyList
                                where a.isTamatNanny == true
                                select a;
                }

                if (checkBoxNannyByHour.IsChecked == true)
                {
                    nannyList = from a in nannyList
                                where a.isByHourNanny == true
                                select a;
                }

                dataGridNanny.Visibility  = Visibility.Visible;
                dataGridNanny.ItemsSource = nannyList;

                if (checkBoxNannyByAge.IsChecked == true)
                {
                    dataGridNanny.Visibility              = Visibility.Hidden;
                    dataGridGrouping.Visibility           = Visibility.Visible;
                    dataGridGroupingByDistance.Visibility = Visibility.Hidden;
                    nannyListByAge = new List <BE.Nanny>();
                    if (checkBoxGroupByMax.IsChecked == true)
                    {
                        list1 = bl.getChildByAgeRange(false, true);
                    }
                    else
                    {
                        list1 = bl.getChildByAgeRange(true, true);
                    }
                    foreach (var it in list1)
                    {
                        if (it != null)
                        {
                            foreach (var item in it)
                            {
                                string tmp  = (it.Key * 3).ToString();
                                string tmp2 = ((it.Key * 3) - 3).ToString();
                                string tmp3 = tmp2 + "-" + tmp + " Months";
                                item.KayGroupAge = tmp3.ToString();
                                nannyListByAge.Add(item);
                            }
                        }
                    }

                    collection = new ListCollectionView(nannyListByAge);
                    collection.GroupDescriptions.Add(new PropertyGroupDescription("KayGroupAge"));
                    dataGridGrouping.ItemsSource = collection;
                }



                if (checkBoxNannyByMom.IsChecked == true)
                {
                    dataGridNanny.Visibility              = Visibility.Hidden;
                    dataGridGrouping.Visibility           = Visibility.Hidden;
                    dataGridGroupingByDistance.Visibility = Visibility.Visible;

                    new Thread(() =>
                    {
                        nannyListByDistance = new List <BE.Nanny>();
                        list1 = bl.getNannyByDistance(mom.AddressMom, true);

                        foreach (var it in list1)
                        {
                            if (it != null)
                            {
                                foreach (var item in it)
                                {
                                    string tmp            = ((it.Key + 1) * 500).ToString();
                                    string tmp2           = (((it.Key + 1) * 500) - 500).ToString();
                                    string tmp3           = tmp2 + "-" + tmp + " מטר";
                                    item.KayGroupDistance = tmp3.ToString();
                                    nannyListByDistance.Add(item);
                                }
                            }
                        }
                        Dispatcher.Invoke(new Action(() =>
                        {
                            collection = new ListCollectionView(nannyListByDistance);
                            collection.GroupDescriptions.Add(new PropertyGroupDescription("KayGroupDistance"));
                            dataGridGroupingByDistance.ItemsSource = collection;
                        }));
                    }).Start();
                }
            }

            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }