public void SavePhrase(Word_Phrase phrase)
        {
            //CREATE
            if (phrase.Id == 0)
            {
                context.Phrases.Add(phrase);
            }

            else
            {
                Word_Phrase dbEntry = context.Phrases.Find(phrase.Id);

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

            context.SaveChanges();
        }
Пример #2
0
        public Reader_Phrases()
        {
            string resourceName = "Domain.DataFiles.Phrases.Phrases.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_Phrase ph = new Word_Phrase(line);

                        PhrasesList.Add(ph);
                    }
                }
                catch (Exception ex)
                {
                    string something = ex.Message;
                }
            }
        }
Пример #3
0
        public ActionResult Delete(int Id)
        {
            Word_Phrase deletedPhrase = phrasesRepository.DeletePhrase(Id);

            if (deletedPhrase != null)
            {
                TempData["message"] = string.Format("{0} has been deleted", deletedPhrase.Character);
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public Word_Phrase DeletePhrase(int id)
        {
            Word_Phrase dBEntry = context.Phrases.Find(id);

            if (dBEntry != null)
            {
                context.Phrases.Remove(dBEntry);
                context.SaveChanges();
            }

            return(dBEntry);
        }
Пример #5
0
        public FileContentResult GetImage(int Id)
        {
            Word_Phrase phrase = phrasesRepository.Phrases.FirstOrDefault(p => p.Id == Id);

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

                return(fileContentResult);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        public ActionResult Edit(Word_Phrase phrase, HttpPostedFileBase Image = null)
        {
            if (ModelState.IsValid)
            {
                if (Image != null)
                {
                    phrase.ImageMimeType = Image.ContentType;
                    phrase.ImageData     = new byte[Image.ContentLength];
                    Image.InputStream.Read(phrase.ImageData, 0, Image.ContentLength);
                }


                phrasesRepository.SavePhrase(phrase);
                TempData["message"] = string.Format("{0} has been saved", phrase.Character);
                return(RedirectToAction("Index"));
            }

            else
            {
                return(View(phrase));
            }
        }
Пример #7
0
        public ViewResult Edit(int Id)
        {
            Word_Phrase phrase = phrasesRepository.Phrases.FirstOrDefault(p => p.Id == Id);

            return(View(phrase));
        }
Пример #8
0
        private void GenerateWith(Int32 option)
        {
            panel3.Controls.Clear();
            _pinyinToPronunce.Clear();

            Int32 FastCompute = 10;

            Int32 CaractersPerLine = panel1.Width / GeneratorButtonSize_Width - 1;

            string Input = getInputText();

            int Lenght = Input.Length;

            int textCursor = 0;

            Int32 Posx = 0;
            Int32 Posy = 0;

            while (textCursor < Input.Length)
            {
                ArrayList Matches   = new ArrayList();
                Word      BestMatch = new Word();

                Int32 MaxMatch = 0;

                for (Int32 x = 1; x < Input.Length - textCursor + 1; x++)
                {
                    if (x > FastCompute)
                    {
                        break;                                      //Fast Compute
                    }
                    if ((textCursor + x < Lenght) || (textCursor + x == Lenght))
                    {
                        foreach (Word w in Included_Words)
                        {
                            if (w.Character == Input.Substring(textCursor, x))
                            {
                                MaxMatch = x;
                                Matches.Add(w);
                                BestMatch = w;
                            }
                        }
                    }
                }                 //End for Single Match

                int CountMatches = Matches.Count;

                if (CountMatches != 0)
                {
                    Button btnWordMatch = new Button();
                    btnWordMatch.Size     = new Size(GeneratorButtonSize_Width * BestMatch.Character.Length, GeneratorButtonSize_Height);
                    btnWordMatch.Text     = BestMatch.Character;
                    btnWordMatch.Location = new Point(StartPositionPanel.X + Posx * GeneratorButtonSize_Width,
                                                      StartPositionPanel.Y + Posy * GeneratorButtonSize_Height);
                    //btnWordMatch.Font = textBoxInputText.Font;

                    //Puede que tenga mas de un pinyin para pronunciar

                    if (BestMatch.NumberPinyin != null)
                    {
                        BestMatch.NumberPinyin = BestMatch.NumberPinyin.Replace("1", "1 ");
                        BestMatch.NumberPinyin = BestMatch.NumberPinyin.Replace("2", "2 ");
                        BestMatch.NumberPinyin = BestMatch.NumberPinyin.Replace("3", "3 ");
                        BestMatch.NumberPinyin = BestMatch.NumberPinyin.Replace("4", "4 ");
                        //No existe entrada de audio para el tono 5
                        //BestMatch.NumberPinyin = BestMatch.NumberPinyin.Replace("5", "1 ");

                        string[] numberPinyinDecomposed = BestMatch.NumberPinyin.Split(' ');

                        foreach (string PinyinSillabe in numberPinyinDecomposed)
                        {
                            Word_Phrase toPronunce = new Word_Phrase();
                            toPronunce.NumberPinyin = PinyinSillabe.Trim();
                            this._pinyinToPronunce.Add((toPronunce));
                        }
                    }


                    switch (BestMatch.Level)
                    {
                    case 0:
                        btnWordMatch.BackColor = Color.GreenYellow;
                        break;

                    case 1:                             //HSK1
                        btnWordMatch.BackColor = Color.LimeGreen;
                        break;

                    case 2:
                        btnWordMatch.BackColor = Color.Green;
                        break;

                    case 3:
                        btnWordMatch.BackColor = Color.Aqua;
                        break;

                    case 4:
                        btnWordMatch.BackColor = Color.Blue;
                        break;

                    case 5:
                        btnWordMatch.BackColor = Color.Orange;
                        break;

                    case 6:
                        btnWordMatch.BackColor = Color.DarkOrange;
                        break;

                    case 7:
                        btnWordMatch.BackColor = Color.Crimson;
                        break;

                    case 20:
                        btnWordMatch.BackColor = Color.MediumVioletRed;
                        break;



                    default:
                        btnWordMatch.ForeColor = Color.Red;
                        break;
                    }


                    this.panel3.Controls.Add((btnWordMatch));

                    if (option == 0)
                    {
                        this.toolTip1.SetToolTip(btnWordMatch, "[" + BestMatch.Level.ToString() + "]" + "\n[" + BestMatch.Pinyin + "]\n" + BestMatch.Description);
                    }

                    if (option == 1)
                    {
                        this.toolTip1.SetToolTip(btnWordMatch, BestMatch.Pinyin);
                    }


                    //string[] descriptions = BestMatch.Description.Split(';');

                    //this.textBoxTranslated.Text = this.textBoxTranslated.Text + " " + descriptions[0];

                    Posx = Posx + BestMatch.Character.Length;

                    if (Posx > CaractersPerLine)
                    {
                        Posy++;
                        Posx = 0;
                    }

                    textCursor = textCursor + MaxMatch;
                }

                else
                {
                    //No hay match


                    Button WordMatch = new Button();
                    WordMatch.Size     = new Size(GeneratorButtonSize_Width, GeneratorButtonSize_Height);
                    WordMatch.Text     = Input[textCursor].ToString();
                    WordMatch.Location = new Point(StartPositionPanel.X + Posx * GeneratorButtonSize_Width,
                                                   StartPositionPanel.Y + Posy * GeneratorButtonSize_Height);
                    //WordMatch.Font = textBoxInputText.Font;
                    WordMatch.ForeColor = Color.Red;

                    this.panel3.Controls.Add((WordMatch));
                    this.toolTip1.SetToolTip(WordMatch, "Not Match Found");


                    Posx = Posx + 1;

                    if (Posx > CaractersPerLine)
                    {
                        Posy++;
                        Posx = 0;
                    }

                    textCursor = textCursor + 1;
                }
            }             //While Cursor
        }