/// <summary> /// SetFavorite /// </summary> /// <param name="inWord"></param> public void SetFavorite(string inWord) { using (var context = new EnViEntities1()) { // update table EnWord! try { // var a = context.ENWORDs.Single(p => p.EnWord1.Equals(inWord)); var result = (from a in context.ENWORDs where a.EnWord1.Equals(inWord) select a).FirstOrDefault(); result.Favote = 1; // a.Favote = 1; context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //insert word to Favorite Table try { } catch (Exception e) { } } }
/// <summary> /// DemRecent /// </summary> /// <returns></returns> public int DemRecent() { using (var context = new EnViEntities1()) { return((from a in context.Favorites select a).Count()); } }
/// <summary> /// DeleteRecent /// </summary> internal void DeleteRecent() { using (var context = new EnViEntities1()) { var result = ((IObjectContextAdapter)context).ObjectContext; result.ExecuteStoreCommand("Delete from favorite"); } }
/// <summary> /// Dem /// </summary> /// <returns></returns> public int Dem() { using (var context = new EnViEntities1()) { int result = (from a in context.idioms select a).Count(); return(result); } }
/// <summary> /// Dem /// </summary> /// <returns></returns> public int Dem() { using (var context = new EnViEntities1()) { var s = (from a in context.ENWORDs select a.ID).Max(); return(s); } }
/// <summary> /// GetRecent /// </summary> /// <returns></returns> public List <string> GetRecent() { using (var context = new EnViEntities1()) { var result = (from a in context.Favorites select a.EnWord).ToList(); return(result); } }
/// <summary> /// GetFavoriteWord /// </summary> /// <returns></returns> public List <string> GetFavoriteWord() { using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.Favote == 1 select a.EnWord1).ToList(); return(result); } }
/// <summary> /// GetAllVerbs /// todo show irregular verbs /// </summary> /// <returns></returns> public List <Verb> GetAllVerbs() { using (var context = new EnViEntities1()) { var result = (from a in context.Verbs select a ).ToList(); return(result); } }
/// <summary> /// Init /// </summary> /// <returns></returns> public List <string> Init() { using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs select a.EnWord1 ).ToList(); return(result); } }
/// <summary> /// XoaFavorite /// </summary> /// <param name="inWord"></param> public void XoaFavorite(string inWord) { using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.EnWord1 == inWord && a.Favote == 1 select a).First(); result.Favote = 0; context.SaveChanges(); } }
/// <summary> /// GetTuRandom /// </summary> /// <returns></returns> public string GetTuRandom() { Random ran = new Random(); int VT = ran.Next(0, Dem()); using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.ID == VT && a.EnWord1 != null select a.EnWord1).First(); return(result); } }
/// <summary> /// GetAllIdiormInDatabase /// </summary> /// <returns></returns> public List <Idiorm> GetAllIdiormInDatabase() { using (var context = new EnViEntities1()) { var result = (from a in context.idioms select new Idiorm() { ID = a.ID, EnWord = a.EnWord, ViWord = a.ViWord }).ToList(); return(result); } }
/// <summary> /// SearchStructure /// </summary> /// <param name="inKey"></param> /// <returns></returns> public List <Structure> SearchStructure(string inKey) { using (var context = new EnViEntities1()) { var result = (from a in context.structure1 where a.Key == inKey select new Structure() { ID = a.ID, EnWord = a.EnWord, ViWord = a.EnVi, Example = a.Example, Key = a.Key }).ToList <Structure>(); return(result); } }
/// <summary> /// GetAllStructure -- init in Main /// </summary> /// <returns></returns> public List <Structure> GetAllStructure() { using (var context = new EnViEntities1()) { var result = (from a in context.structure1 select new Structure() { ID = a.ID, EnWord = a.EnWord, ViWord = a.EnVi, Example = a.Example, Key = a.Key } ).ToList <Structure>(); return(result); } }
/// <summary> /// AddRecentWord /// </summary> /// <param name="inWords"></param> public void AddRecentWord(string inWords) { using (var context = new EnViEntities1()) { Favorite word = new Favorite() { ID = DemRecent() + 1, EnWord = inWords }; context.Favorites.Add(word); context.Entry(word).State = EntityState.Added; context.SaveChanges(); //context.ENWORDs.Add(word); //context.Entry(word).State = EntityState.Added; //context.SaveChanges(); } }
/// <summary> /// InsertNewWords /// </summary> /// <param name="inID"></param> /// <param name="inEnWord"></param> /// <param name="inViWord"></param> /// <param name="inType"></param> /// <param name="inExample"></param> public void InsertNewWords(int inID, string inEnWord, string inViWord, string inType, string inExample) { using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.EnWord1 == inEnWord select a).ToList(); if (result.Count() > 0) { MessageBox.Show("this word is existed!"); } else { { //try { ENWORD word = new ENWORD() { ID = inID, EnWord1 = inEnWord, EnVi = inViWord, Type = inType, Example = inExample, Favote = 0 }; context.ENWORDs.Add(word); context.Entry(word).State = EntityState.Added; context.SaveChanges(); } //catch (Exception ex) //{ //} } } } }
/// <summary> /// GetWordWhenSearch /// </summary> /// <param name="inKeyWords"></param> /// <returns> List of result search </returns> public Word GetWordWhenSearch(string inKeyWords) { using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.EnWord1 == inKeyWords select new Word() { EnWord = a.EnWord1, ViWord = a.EnVi, Type = a.Type, Example = a.Example, }).FirstOrDefault(); if (result != null) { return(result); } else { return(null); } } }
/// <summary> /// GetDataWordWithID /// </summary> /// <param name="k"></param> /// <returns></returns> public BaseWord GetDataWordWithID(int k) { Random ran = new Random(); int i = ran.Next(0, Dem()); while (!CheckExist(i)) { i = ran.Next(0, Dem()); } arrRandom[k] = i; using (var context = new EnViEntities1()) { var result = (from a in context.ENWORDs where a.ID == i && a.EnWord1 != null select new BaseWord() { EnWord = a.EnWord1, ViWord = a.EnVi }).FirstOrDefault(); return(result); } }
/// <summary> /// SearchVerbs in irregular verbs /// </summary> /// <param name="inWords"></param> /// <param name="key"></param> /// <returns></returns> public List <Verb> SearchVerbs(string inWords, int key) { using (var context = new EnViEntities1()) { if (key == 1) //search first { var result = (from a in context.Verbs where a.First == inWords select a).ToList <Verb>(); return(result); } else if (key == 2) //search second { var result = (from a in context.Verbs where a.Second == inWords select a).ToList <Verb>(); return(result); } else if (key == 3) // search thirst { var result = (from a in context.Verbs where a.Thirst == inWords select a).ToList <Verb>(); return(result); } else // search default (all) { var result = (from a in context.Verbs where a.Thirst == inWords || a.First == inWords || a.Second == inWords select a ).ToList <Verb>(); return(result); } } }
/// <summary> /// GetDataIdoirmWithID /// </summary> /// <param name="k"></param> /// <returns></returns> public Idiorm GetDataIdoirmWithID(int k) { Random ran = new Random(); int i = ran.Next(0, Dem()); while (!CheckExist(i)) { i = ran.Next(0, Dem()); } arrRandom[k] = i; using (var context = new EnViEntities1()) { var result = (from a in context.idioms where a.ID == i select new Idiorm() { ID = a.ID, EnWord = a.EnWord, ViWord = a.ViWord }).FirstOrDefault(); return(result); } }