Esempio n. 1
0
        // call "AddCarToXML" and add car into XML after refresh tables
        private void btnAddCar_Click(object sender, RoutedEventArgs e)
        {
            var cars = new List <Car>();

            if (String.IsNullOrEmpty(nameTextBox.Text) ||
                String.IsNullOrEmpty(dateTextBox.Text) ||
                String.IsNullOrEmpty(priceTextBox.Text) ||
                String.IsNullOrEmpty(dphTextBox.Text))
            {
                btnInfo.Content = "Zadejte vsechny hodnoty";
            }
            else
            {
                XmlData.AddCarToXML(openFile.FileName, nameTextBox.Text, dateTextBox.Text, priceTextBox.Text, dphTextBox.Text);
            }

            cars = XmlData.LoadXml(openFile.FileName);
            carListView.ItemsSource = cars;

            grCarList.ItemsSource =
                (from c in XmlData.ViewCars(cars)
                 group c by c.ModelName into g
                 select new
            {
                ModelName = g.Key,
                dph = g.Select(c => c.DPH),
                priceNoDPH = g.Sum(c => c.PriceNoDPH),
                priceWithDPH = g.Sum(c => c.PriceWithDph)
            }).OrderByDescending(x => x.priceWithDPH);

            CollectionView           view  = (CollectionView)CollectionViewSource.GetDefaultView(grCarList.ItemsSource);
            PropertyGroupDescription group = new PropertyGroupDescription("ModelName");

            view.GroupDescriptions.Add(group);
        }