public LearningWordPage(int CategoryID)
        {
            InitializeComponent();
            wdal        = new WordDAL();
            idal        = new ImageDAL();
            _CategoryID = CategoryID;
            //LoadRandomWordByCategory(_CategoryID);
            //LoadRandomListWordByCategory(_CategoryID);
            lstW = new List <Word>();
            lstW = wdal.getRandomWordForLearningWord(_CategoryID);

            //lấy từ đầu tiên trong danh sách
            _currentW       = lstW[0];
            lblWord.Content = lstW[0].Word1;
            lblWord.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblWord.VerticalContentAlignment   = VerticalAlignment.Center;
            lblTranslate.Content = lstW[0].Translate;
            lblTranslate.HorizontalContentAlignment = HorizontalAlignment.Center;
            lblTranslate.VerticalContentAlignment   = VerticalAlignment.Center;
            DataAccess.Image img = idal.getImageOfWord(lstW[0].Word1);
            byte[]           i   = img.Image1.ToArray();
            if (img == null)
            {
                throw new Exception("#113 Từ " + lstW[0].Word1 + "chưa có hình.");
            }
            BitmapImage image = LoadImage(i);

            img_word.Source  = image;
            img_word.Stretch = Stretch.Fill;
            PlayThePronunciation(lstW[0]);
        }
Example #2
0
        //public void LoadWordByCategory(int categoryId)
        //{
        //    Word word = wdal.geRandomtWordByCategory(categoryId);
        //    lblChooseWord.Content = "Hãy chọn hình cho từ " + word.Word1;
        //    DataAccess.Image img = idal.getImageOfWord(word.Word1);
        //    byte[] i = img.Image1.ToArray();
        //    if (img == null) throw new Exception("#113 Từ " + word.Word1 + "chưa có hình.");
        //    BitmapImage image = LoadImage(i);
        //    image_1.Source = image;
        //    //LoadImage(img.Image1);
        //}

        public void setImageSource(System.Windows.Controls.Image imgControl, Word word)
        {
            try {
                DataAccess.Image img = idal.getImageOfWord(word.Word1);
                if (img == null)
                {
                    return;
                }
                byte[]      i     = img.Image1.ToArray();
                BitmapImage image = LoadImage(i);
                imgControl.Source  = image;
                imgControl.Stretch = Stretch.Fill;
            }
            catch { }
        }
 private void BtnPrevious_Click(object sender, RoutedEventArgs e)
 {
     if (_index > 0)
     {
         _index              -= 1;
         _currentW            = lstW[_index];
         lblWord.Content      = lstW[_index].Word1;
         lblTranslate.Content = lstW[_index].Translate;
         DataAccess.Image img = idal.getImageOfWord(lstW[_index].Word1);
         byte[]           i   = img.Image1.ToArray();
         if (img == null)
         {
             throw new Exception("#113 Từ " + lstW[_index].Word1 + "chưa có hình.");
         }
         BitmapImage image = LoadImage(i);
         img_word.Source = image;
         PlayThePronunciation(lstW[_index]);
     }
 }
 private void BtnNext_Click(object sender, RoutedEventArgs e)
 {
     if (_index < lstW.Count - 1)
     {
         _index              += 1;
         _currentW            = lstW[_index];
         lblWord.Content      = lstW[_index].Word1;
         lblTranslate.Content = lstW[_index].Translate;
         //convert image from binary to image
         DataAccess.Image img = idal.getImageOfWord(lstW[_index].Word1);
         byte[]           i   = img.Image1.ToArray();
         if (img == null)
         {
             throw new Exception("#113 Từ " + lstW[_index].Word1 + "chưa có hình.");
         }
         BitmapImage image = LoadImage(i);
         img_word.Source = image;
         //play audio of word
         PlayThePronunciation(lstW[_index]);
     }
 }
        protected List <Card> CreateCards(int pairs)
        {
            gameState = GameState.Running;
            List <Card> cards = new List <Card>();

            BitmapImage backgroundImage = GetBackImage();

            getImageList();
            //for (int x = 0; x < pairs; x++)
            //{

            //    BitmapImage frontImage = GetImage(String.Format("../../Images/Animals/Animal{0}.jpg", x));
            //    Card a = new Card("Animal" + x.ToString(), frontImage, backgroundImage);

            //    frontImage = GetImage(String.Format("../../Images/Animals/Animal{0}.jpg", x));
            //    Card b = new Card("Animal" + x.ToString(), frontImage, backgroundImage);

            //    cards.Add(a);
            //    cards.Add(b);

            //}

            foreach (Word w in wordList)
            {
                DataAccess.Image img = imgList.Where(x => x.WordID == w.Word1).SingleOrDefault();
                byte[]           i   = img.Image1.ToArray();
                if (img == null)
                {
                    break;
                }
                BitmapImage frontImage = GetImage(i);
                Card        a          = new Card(w.Word1, frontImage, backgroundImage);
                Card        b          = new Card(w.Word1, frontImage, backgroundImage);

                cards.Add(a);
                cards.Add(b);
            }
            return(cards);
        }