public HistoryPage(Product selectedProduct)
        {
            InitializeComponent();


            var allProduct = AvtoServisEntities.GetContext().Products.ToList();

            allProduct.Insert(0, new Product
            {
                Title = "Все товары"
            });
            ComboBoxTovar.ItemsSource = allProduct;


            if (selectedProduct != null)
            {
                ComboBoxTovar.Text = selectedProduct.Title;
                _currentProduct    = selectedProduct;
            }
            else
            {
                ComboBoxTovar.SelectedIndex = 0;
            }


            DataContext = _currentProduct;
            UpdateProduct();
        }
 private void changeVisible(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (Visibility == Visibility.Visible)
     {
         AvtoServisEntities.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload());
         TableProduct.ItemsSource = AvtoServisEntities.GetContext().Products.ToList();
     }
 }
示例#3
0
 public static AvtoServisEntities GetContext()
 {
     if (_context == null)
     {
         _context = new AvtoServisEntities();
     }
     return(_context);
 }
        private void UpdateProduct()
        {
            var currentProductSale = AvtoServisEntities.GetContext().ProductSales.ToList();

            if (ComboBoxTovar.SelectedIndex > 0)
            {
                currentProductSale = currentProductSale.Where(p => p.Product.Equals(ComboBoxTovar.SelectedItem as Product)).ToList();
            }

            LViewProduct.ItemsSource = currentProductSale.OrderBy(p => p.SaleDate).ToList();
        }
        public CreatProductPage(Product selectedProduct)
        {
            InitializeComponent();

            if (selectedProduct != null)
            {
                _currentProduct = selectedProduct;
            }

            DataContext    = _currentProduct;
            cb.ItemsSource = AvtoServisEntities.GetContext().Manufacturers.ToList();
        }
        private void SaveProduct(object sender, RoutedEventArgs e)
        {
            StringBuilder errors = new StringBuilder();

            if (string.IsNullOrWhiteSpace(_currentProduct.Title))
            {
                errors.AppendLine("Не указано название товара.");
            }
            if (string.IsNullOrWhiteSpace(_currentProduct.Cost))
            {
                errors.AppendLine("Не указана стоимость товара.");
            }
            if (string.IsNullOrWhiteSpace(_currentProduct.Description))
            {
                errors.AppendLine("Не указано описание товара.");
            }
            if (string.IsNullOrWhiteSpace(_currentProduct.MainImagePath))
            {
                errors.AppendLine("Не указан путь к изображению.");
            }
            if (_currentProduct.Manufacturer == null)
            {
                errors.AppendLine("Не указан производитель товара.");
            }


            if (errors.Length > 0)
            {
                System.Windows.MessageBox.Show(errors.ToString());
                return;
            }

            if (_currentProduct.ID == 0)
            {
                AvtoServisEntities.GetContext().Products.Add(_currentProduct);
            }

            try
            {
                AvtoServisEntities.GetContext().SaveChanges();
                System.Windows.MessageBox.Show("Информация сохранена");
                Manager.MainFrame.GoBack();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message.ToString());
            }
        }
示例#7
0
        private void  UpdateProduct()
        {
            var currentProduct = AvtoServisEntities.GetContext().Products.ToList();

            if (Manufact.SelectedIndex > 0)
            {
                currentProduct = currentProduct.Where(p => p.Manufacturer.Equals(Manufact.SelectedItem as Manufacturer)).ToList();
            }

            currentProduct = currentProduct.Where(p => p.Title.ToLower().Contains(NameProductSearch.Text.ToLower())).ToList();

            if (actual.IsChecked.Value)
            {
                currentProduct = currentProduct.Where(p => p.IsActive).ToList();
            }

            LViewProduct.ItemsSource = currentProduct.OrderBy(p => p.Cost).ToList();
        }
        private void BtnDeletProduct_Click(object sender, RoutedEventArgs e)
        {
            var DeletProduct = TableProduct.SelectedItems.Cast <Product>().ToList();

            if (MessageBox.Show($"Вы точно хотите удалить следующие {DeletProduct.Count()} элементов?", "Внимание",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    AvtoServisEntities.GetContext().Products.RemoveRange(DeletProduct);
                    AvtoServisEntities.GetContext().SaveChanges();
                    MessageBox.Show("Данные удалены");

                    TableProduct.ItemsSource = AvtoServisEntities.GetContext().Products.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
示例#9
0
        public NewPage()
        {
            InitializeComponent();


            var allManufact = AvtoServisEntities.GetContext().Manufacturers.ToList();

            allManufact.Insert(0, new Manufacturer
            {
                Name = "Все производители"
            });
            Manufact.ItemsSource   = allManufact;
            Manufact.SelectedIndex = 0;
            actual.IsChecked       = true;



            var currentProduct = AvtoServisEntities.GetContext().Products.ToList();

            LViewProduct.ItemsSource = currentProduct;
            UpdateProduct();
        }
 public ListProductPage()
 {
     InitializeComponent();
     TableProduct.ItemsSource = AvtoServisEntities.GetContext().Products.ToList();
 }