Exemplo n.º 1
0
        private void GetProduct(int productId)
        {
            ProductViewModel productInfo = null;

             using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
             {
                 var product = (from p in dc.Products
                                where p.Id == productId
                                select p).FirstOrDefault();

                 if (product != null)
                 {
                     productInfo = new ProductViewModel(product);
                 }

             }

             if (productInfo != null)
             {

                 txtName.Text = productInfo.ProductName;

                 imgProductImage.Source = new BitmapImage(new Uri(productInfo.ImageUrl, UriKind.Absolute));

                 btnSave.IsEnabled = true;
             }
        }
Exemplo n.º 2
0
        private void AddToInventoryClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                // TODO: Add notification error saying product name cannot be empty
                return;
            }

            try
            {
                using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
                {
                    var existingProduct = (from p in dc.Products
                                           where p.Barcode == _scannedBarcode || p.ProductName == txtName.Text
                                           select p).FirstOrDefault();

                    Product product;

                    if (existingProduct == null)
                    {
                        product = new Product
                        {
                            ProductName = txtName.Text,
                            Barcode = _scannedBarcode,
                            ImageUrl = _currentProduct.ImageUrl,
                        };

                        dc.Products.InsertOnSubmit(product);
                        dc.SubmitChanges();
                    }
                    else
                    {
                        product = existingProduct;
                    }

                    var purchase = new Purchase
                        {
                            ProductId = product.Id,
                            Currency = txtCurrency.Text,
                            DatePurchased = DateTime.Parse(txtDate.Text),
                            Quantity = int.Parse(txtQuantity.Text),
                            Price = decimal.Parse(txtPrice.Text)
                        };

                    dc.Purchases.InsertOnSubmit(purchase);
                    dc.SubmitChanges();
                }
                // Navigate to main page.
                NavigationService.Navigate(new Uri("/Home", UriKind.RelativeOrAbsolute));
            }
            catch (Exception ex)
            {
                txtName.Text = ex.Message;
            }
        }
Exemplo n.º 3
0
        private void SearchBoxTextChanged(object sender, TextChangedEventArgs e)
        {
            string searchTerm = SearchBox.Text;

            List<ProductListItemViewModel> productList;

            try
            {
                using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
                {
                    productList = (from product in dc.Products
                                   join purchase in dc.Purchases on product.Id equals purchase.ProductId
                                   group purchase by new { product.Id, product.ProductName, product.ImageUrl }
                                       into psummary
                                       where psummary.Key.ProductName.Contains(searchTerm)
                                       orderby psummary.Max(pur => pur.DatePurchased) descending
                                       select
                                           new ProductListItemViewModel(psummary.Key.Id, psummary.Key.ProductName,
                                                                        psummary.Max(pur => pur.DatePurchased),
                                                                        psummary.Key.ImageUrl,
                                                                        psummary.Sum(pur => pur.Quantity))
                                  ).ToList();
                }
            }
            catch (Exception ex)
            {
                productList = new List<ProductListItemViewModel>();
                txtResults.Text = ex.Message;
            }

            ProductList.ItemsSource = productList;
        }
Exemplo n.º 4
0
        private void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            WP7BarcodeManager.aStartProgress = StartProgress;
            WP7BarcodeManager.ScanMode = BarcodeFormat.ALL_1D;

            List<ProductListItemViewModel> productList;

            try
            {
                using (var dc = new ProductsDataContext(ProductsDataContext.ConnectionString))
                {
                    productList = (from product in dc.Products
                                   join purchase in dc.Purchases on product.Id equals purchase.ProductId
                                   group purchase by new { product.Id, product.ProductName, product.ImageUrl } into psummary
                                   orderby psummary.Max(pur => pur.DatePurchased) descending
                                   select new ProductListItemViewModel(psummary.Key.Id, psummary.Key.ProductName, psummary.Max(pur => pur.DatePurchased), psummary.Key.ImageUrl, psummary.Sum(pur => pur.Quantity))

                                   ).ToList();
                }

            }
            catch (Exception ex)
            {
                productList = new List<ProductListItemViewModel>();
                txtResults.Text = ex.Message;
            }

            ProductList.ItemsSource = productList;
        }