コード例 #1
0
ファイル: Reader_HSK.cs プロジェクト: davidlorente78/HSK-5.0
        private void LoadListHSK()
        {
            string resourceName = "DomainHSK.DataFiles.Levels.NewHSKLevel" + Level.ToString() + ".txt";

            Assembly currentAssembly = Assembly.GetExecutingAssembly();

            // Get all embedded resources
            string[] arrResources = currentAssembly.GetManifestResourceNames();

            Lines = ReadLines(() => Assembly.GetExecutingAssembly()
                              .GetManifestResourceStream(resourceName),
                              Encoding.Unicode)
                    .ToList();


            foreach (string line in Lines)
            {
                try
                {
                    if (line[0] != '#')
                    {
                        Word_HSK w = new Word_HSK(line);
                        w.Level = Level;
                        Words.Add(w);

                        string check = w.Pinyin;
                    }
                }
                catch (Exception ex)
                {
                    string something = ex.Message;
                }
            }
        }
コード例 #2
0
        public void SaveWord(Word_HSK word)
        {
            //CREATE
            if (word.Id == 0)
            {
                context.Words.Add(word);
            }

            else
            {
                //TODO Pag 290
                Word_HSK dbEntry = context.Words.Find(word.Id);

                if (dbEntry != null)
                {
                    //UPDATE
                    dbEntry.Character            = word.Character;
                    dbEntry.Description          = word.Description;
                    dbEntry.TraditionalCharacter = word.TraditionalCharacter;
                    dbEntry.NumberPinyin         = word.NumberPinyin;
                    dbEntry.Level         = word.Level;
                    dbEntry.ImageData     = word.ImageData;
                    dbEntry.ImageMimeType = word.ImageMimeType;
                }
            }

            context.SaveChanges();
        }
コード例 #3
0
        //http://jesseliberty.com/2017/07/06/learning-xamarin-forms-part-2-mvvm/
        public WordView()
        {
            InitializeComponent();
            word           = new Word_HSK();
            word.Character = "好";

            viewModel      = new WordViewModel(word);
            BindingContext = viewModel;
        }
コード例 #4
0
        public FileContentResult GetImage(int Id)
        {
            Word_HSK phrase = wordRepository.Words.FirstOrDefault(p => p.Id == Id);

            if (phrase != null)
            {
                FileContentResult fileContentResult = File(phrase.ImageData, phrase.ImageMimeType);

                return(fileContentResult);
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
        public ActionResult Edit(Word_HSK word, HttpPostedFileBase Image = null)
        {
            if (ModelState.IsValid)
            {
                if (Image != null)
                {
                    word.ImageMimeType = Image.ContentType;
                    word.ImageData     = new byte[Image.ContentLength];
                    Image.InputStream.Read(word.ImageData, 0, Image.ContentLength);
                }


                wordRepository.SaveWord(word);
                TempData["message"] = string.Format("{0} has been saved", word.Character);
                return(RedirectToAction("Index"));
            }

            else
            {
                return(View(word));
            }
        }
コード例 #6
0
        public ViewResult Edit(int Id)
        {
            Word_HSK word = wordRepository.Words.FirstOrDefault(p => p.Id == Id);

            return(View(word));
        }
コード例 #7
0
 public WordViewModel(Word_HSK word)
 {
     Character = word.Character;
 }