//Add item to favourite | Remove item from favourite private void favButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //_dishes_list[_selected_index].Fav = !_dishes_list[_selected_index].Fav; if (_dishes_list[_selected_index].Fav == false) { _dishes_list[_selected_index].Fav = true; dishesView.Items.Refresh(); DishDao.WriteUpdatedData(); //write to file } else { var Result = MessageBox.Show("Bạn có chắc chắn muốn xóa món ăn này khỏi danh sách yêu thích?", "Xóa khỏi danh sánh", MessageBoxButton.YesNo, MessageBoxImage.Question); if (Result == MessageBoxResult.Yes) { _dishes_list[_selected_index].Fav = false; dishesView.Items.Refresh(); UpdateView(); UpdatePage(); DishDao.WriteUpdatedData(); //write to file } else { //do nothing } } }
private string getId() { string result = ""; List <Dish> DishDB = DishDao.GetAll().ToList(); //Get ID in DB var myDishIDs = DishDB.Select(x => x.Id).ToList(); bool Loop = true; int count = 0; do { count++; string newID = $"DISH{count}"; //Check if new ID haven't existed in database var checkItem = myDishIDs.Where(x => x.Contains(newID)).FirstOrDefault(); if (checkItem == null) { result = newID; Loop = false; } else /*Do nothing*/ } { } while (Loop); return(result); }
private void UpdatePage() { int totalPages = DishDao.GetTotalPages(this.ActualWidth, this.ActualHeight); viewTotalPages.Text = "/ " + totalPages.ToString(); // _selecting_page = false avoid updating view in paging_SelectionChanged(sender, e); _selecting_page = false; _page = Paging.UpdatePage(totalPages); paging.ItemsSource = _page; paging.SelectedIndex = _current_page - 1; //update selected page paging.Items.Refresh(); _selecting_page = true; }
public DishDaoBean CreateDishDaoBean(DishDao bean) { this.DishDaoId = bean.DishDaoId; this.DishId = bean.DishId; this.Name = bean.Name; this.CreateDatetime = bean.CreateDatetime; this.CreateBy = bean.CreateBy; this.Deleted = bean.Deleted; this.Status = bean.Status; this.UpdateDatetime = bean.UpdateDatetime; this.UpdateBy = bean.UpdateBy; this.OptionalNumber = bean.OptionalNumber; this.Change = false; return(this); }
// prev button handle private void previousButton_Click(object sender, RoutedEventArgs e) { if (_current_page > 1) { _current_page--; } else { _current_page = DishDao.GetTotalPages(this.ActualWidth, this.ActualHeight); } paging.SelectedIndex = _current_page - 1; //update selected page // update data for view //_dishes_list = DishDao.GetAll(this.ActualWidth, this.ActualHeight, _current_page, filter.SelectedIndex, _is_only_fav); //dishesView.ItemsSource = _dishes_list; }
public DishDao CreateDishDao(DishDaoBean bean) { DishDao beanBack = new DishDao(); beanBack.DishDaoId = bean.DishDaoId; beanBack.DishId = bean.DishId; beanBack.Name = bean.Name; beanBack.CreateDatetime = bean.CreateDatetime; beanBack.CreateBy = bean.CreateBy; beanBack.Deleted = bean.Deleted; beanBack.Status = bean.Status; beanBack.UpdateDatetime = bean.UpdateDatetime; beanBack.UpdateBy = bean.UpdateBy; beanBack.OptionalNumber = bean.OptionalNumber; return(beanBack); }
// Delay time before auto generate items in page private void _timer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { int totalPages = DishDao.GetTotalPages(this.ActualWidth, this.ActualHeight); if (_current_page > totalPages) { _current_page = totalPages; } else { //do nothing } UpdateView(); UpdatePage(); }); _timer.Stop(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { //Dish var DishDB = new List <Dish>(DishDao.GetAll()); myDish = DishDB.Where(x => x.Id == myDishId).FirstOrDefault(); myListStep = new ListViewData(); myListStep.ImageList = new ObservableCollection <List <StepImage> >(); //Step var StepDB = RecipeDetailDao.getData(); StepDetail = new BindingList <RecipeDetail>(StepDB.Where(x => x.dishID == myDishId).ToList()); TotalElement += StepDetail.Count; myBtnList = new BindingList <ButtonList>(); myBtnList.Add(new ButtonList() { buttonName = "Main" }); //video if (myDish.LinkVideo != "") { myDish.LinkVideo = getEmbedYoutubeLink(myDish.LinkVideo); if (myDish.LinkVideo != "") { myBtnList.Add(new ButtonList() { buttonName = "Video" }); videoGrid.Visibility = Visibility.Visible; videoSP.Visibility = Visibility.Visible; videolabel.Visibility = Visibility.Visible; videocef.Visibility = Visibility.Visible; videocef.Address = myDish.LinkVideo; TotalElement++; } } /// for (int i = 0; i < StepDetail.Count; i++) { var ListImgTemp = RecipeDetailDao.getStepImageData(myDishId, i + 1, StepDetail[i].quantityOfImage); myBtnList.Add(new ButtonList() { buttonName = $"Step {i + 1}" }); myListStep.ImageList.Add(ListImgTemp); } stepDetailView.ItemsSource = StepDetail; this.DataContext = myListStep; CarouselBtnSkip.ItemsSource = myBtnList; //Food Type myListType = new BindingList <FoodType>(); var DishTypeDB = Dish_TypeDao.getData(); var myDishType = new List <string>(DishTypeDB.Where(x => x.dishID == myDishId).Select(x => x.typeID).ToList()); var TypeDB = FoodTypeDao.getData(); foreach (var item in myDishType) { var temp = TypeDB.Where(x => x.typeID == item).FirstOrDefault(); myListType.Add(temp); } DishNameLabel.Content = myDish.Name; dishDesTextBlock.Text = myDish.Description; dishIngTextBlock.Text = myDish.Ingredient; var Folder = AppDomain.CurrentDomain.BaseDirectory; var path = $"{Folder}Resources\\Images\\{myDishId}.jpg"; var Bitmap = new BitmapImage(new Uri(path, UriKind.Absolute)); dishImage.Source = Bitmap; tagList.ItemsSource = myListType; }
private void UpdateView() { _dishes_list = DishDao.GetAll(this.ActualWidth, this.ActualHeight, _current_page, filter.SelectedIndex, _is_only_fav, _search); dishesView.ItemsSource = _dishes_list; }