Exemple #1
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string cs = ConfigurationManager.ConnectionStrings["ShopDBEntities"].ConnectionString;
            try
            {
                ICategoryManager categoryManager = new CategoryManager(cs);
                IMeasureManager measureManager = new MeasureManager(cs);
                IPackageManager packageManager = new PackageManager(cs);
                IPriceManager priceManager = new PriceManager(cs);
                IProducerManager producerManager = new ProducerManager(cs);
                IProductManager productManager = new ProductManager(cs);

                CatalogViewModel catalogViewModel =
                    new CatalogViewModel(
                         categoryManager,
                         measureManager,
                         packageManager,
                         priceManager,
                         producerManager,
                         productManager
                        );
                if (comboBox.SelectedIndex != comboBox.Items.Count - 1)
                {
                    vwCatalog.dgCatalogUC.DataContext = catalogViewModel.CatalogFilterByCategory(comboBox.SelectedItem.ToString());
                }
                else
                {
                    vwCatalog.dgCatalogUC.DataContext = catalogViewModel.Catalog;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string cs = ConfigurationManager.ConnectionStrings["ShopDBEntities"].ConnectionString;
            try
            {
                ICategoryManager categoryManager = new CategoryManager(cs);
                IMeasureManager measureManager = new MeasureManager(cs);
                IPackageManager packageManager = new PackageManager(cs);
                IPriceManager priceManager = new PriceManager(cs);
                IProducerManager producerManager = new ProducerManager(cs);
                IProductManager productManager = new ProductManager(cs);

                CatalogViewModel catalogViewModel =
                    new CatalogViewModel(
                         categoryManager,
                         measureManager,
                         packageManager,
                         priceManager,
                         producerManager,
                         productManager
                        );

                vwCatalog.dgCatalogUC.DataContext = catalogViewModel.Catalog;
                comboBox.ItemsSource = catalogViewModel.Categories;
                comboBox.SelectedItem = catalogViewModel.Categories.FirstOrDefault(x => x == "Всі категорії");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void InitializeAddForm()
        {
            try
            {
                ICategoryManager categoryManager = new CategoryManager(cs);
                CategoryViewModel categoryViewModel = new CategoryViewModel(categoryManager);

                IProducerManager producerManager = new ProducerManager(cs);
                ProducerViewModel producerViewModel = new ProducerViewModel(producerManager);

                IMeasureManager measureManager = new MeasureManager(cs);
                MeasureViewModel measureViewModel = new MeasureViewModel(measureManager);
                MeasureViewModel volumeMeasureViewModel = new MeasureViewModel(measureManager);

                cbxCategory.DataContext = categoryViewModel.Category;
                cbxCategory.ItemsSource = categoryViewModel.Categories;
                cbxCategory.SelectedItem = categoryViewModel.Categories.FirstOrDefault();

                cbxSubCategoty.DataContext = categoryViewModel.Subcategory(cbxCategory.SelectedItem.ToString());
                cbxSubCategoty.ItemsSource = categoryViewModel.Subcategories;
                cbxSubCategoty.SelectedItem = categoryViewModel.Subcategories.FirstOrDefault();

                cbxProducer.DataContext = producerViewModel.Producer;
                cbxProducer.ItemsSource = producerViewModel.Producers;
                cbxProducer.SelectedItem = producerViewModel.Producers.FirstOrDefault();

                cbxMeasure.DataContext = measureViewModel.Measure;
                cbxMeasure.ItemsSource = measureViewModel.Measures;
                cbxMeasure.SelectedItem = measureViewModel.Measures.First();

                cbxVolumeMeasure.DataContext = volumeMeasureViewModel.VolumeMeasure;
                cbxVolumeMeasure.ItemsSource = volumeMeasureViewModel.Measures;
                cbxVolumeMeasure.SelectedItem = volumeMeasureViewModel.Measures.First();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }