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]);
        }
 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]);
     }
 }
예제 #3
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 { }
        }