private void setImageDataAndStoreLocal(int imageId, byte[] imageData) { _imagesData[imageId] = imageData; var image = UtilFuction.ByteToImage(imageData); image.Save(_fullImagePath + imageId.ToString(), ImageFormat.Jpeg); }
public void reloadFoodTableUI(bool isReloadFromServer = false, Action cbAfterReload = null) { if (isReloadFromServer) { RequestManager.getInstance().showLoading(); Action <NetworkResponse> cbSuccessSent = delegate(NetworkResponse networkResponse) { RequestManager.getInstance().hideLoading(); if (!networkResponse.Successful) { WindownsManager.getInstance().showMessageBoxSomeThingWrong(); } else { reloadFoodTableUI(false, cbAfterReload); } }; Action <string> cbError = delegate(string err) { WindownsManager.getInstance().showMessageBoxErrorNetwork(); RequestManager.getInstance().hideLoading(); }; FoodManager.getInstance().getAllFoodFromServerAndUpdate( cbSuccessSent, cbError ); } else { LVFood.Items.Clear(); foreach (KeyValuePair <int, Food> entry in FoodManager.getInstance().FoodList) { if (entry.Value != null) { var foodCell = new FoodCell(entry.Value, this); LVFood.Items.Add(foodCell); var imageId = entry.Value.ImageId ?? default(int); if (entry.Value.ImageId != null && imageId >= 0) { if (ImageManager.getInstance().checkImageExistLocal(imageId)) { ImageManager.getInstance().loadImage(imageId, delegate(byte[] imageData) { foodCell.setImageFood(UtilFuction.ByteToImage(imageData)); }); } else { ImageManager.getInstance().loadImage(imageId, delegate(byte[] imageData) { checkAndSetImageForFoodCell(entry.Value.FoodId, imageId, UtilFuction.ByteToImage(imageData)); }); } } } } cbAfterReload?.Invoke(); } }
public void checkAndAddFoodIdToComboBox(int foodId) { foreach (ComboBoxItem comboData in ComboBoxSelectFood.ComboBoxData.Items) { if ((int)comboData.Tag == foodId) { return; } } var foodData = FoodManager.getInstance().FoodList[foodId]; string txt = foodData.FoodId + " - " + foodData.Name; var imgSrc = (ImageSource)Application.Current.FindResource("ImageDefaultFood"); if (foodData.ImageId != null) { byte[] imgData = null; ImageManager.getInstance().loadImageFromLocal(foodData.ImageId ?? default(int), out imgData); if (imgData != null) { var img = UtilFuction.ByteToImage(imgData); imgSrc = UtilFuction.imageToBitmapSource(img); } } var item = ComboBoxSelectFood.addItem(txt, imgSrc); item.Tag = foodData.FoodId; }
public void reloadAllUI() { reloadLVOrderWithFood(); var order = OrderManager.getInstance().OrderList[OrderId]; TextBlockHeader.Text = "Order " + OrderId; billMoney = order.BillMoney; BtnAccept.Visibility = Visibility.Hidden; BtnCancel.Visibility = Visibility.Hidden; ComboBoxSelectFood.clear(); foreach (KeyValuePair <int, Food> entry in FoodManager.getInstance().FoodList) { if (entry.Value != null) { bool isContinue = false; foreach (FoodWithOrder foodWithOrder in order.FoodWithOrders) { if (foodWithOrder.FoodId == entry.Value.FoodId) { isContinue = true; } } if (isContinue) { continue; } string txt = entry.Value.FoodId + " - " + entry.Value.Name; var imgSrc = (ImageSource)Application.Current.FindResource("ImageDefaultFood"); if (entry.Value.ImageId != null) { byte[] imgData = null; ImageManager.getInstance().loadImageFromLocal(entry.Value.ImageId ?? default(int), out imgData); if (imgData != null) { var img = UtilFuction.ByteToImage(imgData); imgSrc = UtilFuction.imageToBitmapSource(img); } } var item = ComboBoxSelectFood.addItem(txt, imgSrc); item.Tag = entry.Value.FoodId; } } onChangeMoney(); if (orderHistoryTab != null) { BtnAddFood.Visibility = Visibility.Hidden; TextBlockHeader.Text += (" - " + order.CreatedDate.ToShortDateString()) + " - " + UtilFuction.formatMoney(billMoney) + " VND"; } }
private void setupUIWithFoodData(Food foodData) { TextBoxId.Text = foodData.FoodId.ToString(); TextBoxName.Text = foodData.Name; TextBoxPrice.Text = foodData.Price.ToString(); _currentImage = null; if (foodData.ImageId != null) { loadingAnim.Visibility = Visibility.Visible; _currentImageId = foodData.ImageId ?? default(int); ImageManager.getInstance().loadImage( _currentImageId, delegate(byte[] imageData) { if (imageData != null && imageData.Length > 0) { ImageFood.Source = UtilFuction.imageToBitmapSource(UtilFuction.ByteToImage(imageData)); } loadingAnim.Visibility = Visibility.Hidden; } ); } else { _currentImageId = -1; ImageFood.Source = (ImageSource)Application.Current.FindResource("ImageDefaultFood"); } ComboBoxCategory.SelectedValue = foodData.FoodCategorizeId; foreach (IngredientWithFood ingredientWithFood in foodData.IngredientWithFoods) { _ingredientsWithFood.Add(new IngredientWithFoodTable() { Id = ingredientWithFood.IngredientId, Name = IngredientManager.getInstance().IngredientList[ingredientWithFood.IngredientId].Name, UnitName = UnitManager.getInstance().UnitList[IngredientManager.getInstance().IngredientList[ingredientWithFood.IngredientId].UnitId].Name, Quantity = ingredientWithFood.Quantities }); } }
private void setupUI() { var foodId = _foodDetailId; var categorizeNames = new List <ComboData>(); foreach (KeyValuePair <int, FoodCategorize> entry in FoodCategorizeManager.getInstance().FoodCategorizeList) { if (entry.Value != null) { categorizeNames.Add(new ComboData() { Id = entry.Key, Value = entry.Value.Name }); } } ComboBoxCategory.ItemsSource = categorizeNames; ComboBoxCategory.DisplayMemberPath = "Value"; ComboBoxCategory.SelectedValuePath = "Id"; var ingredientsName = new List <ComboData>(); foreach (KeyValuePair <int, Ingredient> entry in IngredientManager.getInstance().IngredientList) { if (entry.Value != null) { ingredientsName.Add(new ComboData() { Id = entry.Key, Value = entry.Value.Name }); } } ComboBoxIngredient.ItemsSource = ingredientsName; ComboBoxIngredient.DisplayMemberPath = "Value"; ComboBoxIngredient.SelectedValuePath = "Id"; if (foodId != Constant.ID_CREATE_NEW) { var foodData = FoodManager.getInstance().FoodList[foodId]; setupUIWithFoodData(foodData); BtnConfirm.Content = "Sửa"; Title = "Sửa chi tiết món"; TextBlockTile.Text = "Sửa chi tiết món"; TextBlockId.Visibility = Visibility.Visible; TextBoxId.Visibility = Visibility.Visible; BtnCopy.Visibility = Visibility.Collapsed; ComboBoxFoodCopy.Visibility = Visibility.Collapsed; } else { foreach (KeyValuePair <int, Food> entry in FoodManager.getInstance().FoodList) { if (entry.Value != null) { string txt = entry.Value.FoodId + " - " + entry.Value.Name; var imgSrc = (ImageSource)Application.Current.FindResource("ImageDefaultFood"); if (entry.Value.ImageId != null) { byte[] imgData = null; ImageManager.getInstance().loadImageFromLocal(entry.Value.ImageId ?? default(int), out imgData); if (imgData != null) { var img = UtilFuction.ByteToImage(imgData); imgSrc = UtilFuction.imageToBitmapSource(img); } } var item = ComboBoxFoodCopy.addItem(txt, imgSrc); item.Tag = entry.Value.FoodId; } } } }