コード例 #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;
             }
        }
コード例 #2
0
        private void GetProductCompleted(object sender, GetProductJSONCompletedEventArgs e)
        {
            var js = new JsonSerializer();

            SearchUpcItemInfo p = null;
            foreach (var token in JObject.Parse(e.Result).Values())
            {
                p = js.Deserialize<SearchUpcItemInfo>(token.CreateReader());
                if (p != null)
                {
                    break;
                }
            }

            if (p != null)
            {
                _currentProduct = new ProductViewModel(p);

                txtName.Text = p.ProductName;
                txtPrice.Text = p.Price;
                txtQuantity.Text = "1";
                txtCurrency.Text = ProductViewModel.GetCurrencySymbol(p.Currency);

                txtDate.Text = DateTime.Now.ToShortDateString();

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

            }
            else
            {
                //
                // TODO: Add notification saying that no info could be found.
                // leave all controls blank, set imgProductImage to the default image
                // to allow for manual entry.
            }

            btnAddToInventory.IsEnabled = true;
        }
コード例 #3
0
        private void CaptureImageTaskCompleted(object sender, PhotoResult e)
        {
            try
            {
                if (e.TaskResult == TaskResult.OK)
                {
                    _currentImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);

                    if (_currentProduct == null)
                    {
                        _currentProduct = new ProductViewModel();
                    }

                    _currentProduct.ImageUrl = e.OriginalFileName;

                }
            }
            catch (Exception ex)
            {
                txtName.Text = ex.Message + Environment.NewLine + e.Error.Message + Environment.NewLine + e.OriginalFileName;
            }
        }