public static void incAttempts(this XDocument doc, User u, MyDictionary d, Word editWord) { XElement elWord = (from el in doc.Descendants("Dictionary") where long.Parse(el.Attribute("id").Value) == d.id select el).Descendants("Word") .Where(x => string.Compare(x.Element("Source").Value.ToString().Trim(), editWord.source.Trim(), true) == 0) .Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Single(); int i = 0; int.TryParse(elWord.getExistsOrCreateNewChild("Attempts").Value, out i); elWord.getExistsOrCreateNewChild("Attempts").Value = (++i).ToString(); d.RefreshWordList(); }
public static void updWord(this XDocument doc, MyDictionary d, User u, Word fromWord, Word toWord) { if ((fromWord.source != toWord.source) && !doc.checkWordUserDictUniq(d, toWord)) { //MessageBox.Show("Слово не может быть изменено, т.к. уже присутствует в словаре пользователя!"); throw new DuplicateWaitObjectException(toWord.source,"Слово не может быть изменено, т.к. уже присутствует в словаре пользователя!"); //return; } XElement elWord = (from word in (from el in doc.Descendants("Dictionary") where long.Parse(el.Attribute("id").Value) == d.id select el).Descendants("Word") .Where(x => string.Compare( x.Element("Source").Value.ToString().Trim(), fromWord.source.Trim(), true) == 0) select word).Single(); elWord.Element("Source").Value = toWord.source; elWord.getExistsOrCreateNewChild("Translate").Value = toWord.translate; int unodes = elWord.Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Count(); if (unodes == 0) elWord.Add(new XElement("User", new XAttribute("id_user", u.id))); XElement elWordUser = elWord.Descendants("User").Where(x => int.Parse(x.Attribute("id_user").Value) == u.id).Single(); elWordUser.getExistsOrCreateNewChild("Knowing").Value = toWord.knowing.ToString(); //elWord.getExistsOrCreateNewChild("Test_count").Value = toWord.test_count.ToString(); //elWord.getExistsOrCreateNewChild("Attempts").Value = toWord.attempts.ToString(); d.RefreshWordList(); }
public static void delWord(this XDocument doc, MyDictionary d, Word w) { IEnumerable<XElement> elWord = from dict in doc.Descendants("Dictionary") where long.Parse(dict.Attribute("id").Value) == d.id from word in dict.Descendants("Word") where string.Compare(word.Element("Source").Value.Trim(), w.source.Trim(), true) == 0 select word; elWord.Single().Remove(); d.RefreshWordList(); }
public static void addWord(this XDocument doc, MyDictionary d, Word w) { if (!doc.checkWordUserDictUniq(d, w)) { MessageBox.Show("Слово не может быть добавлено, т.к. уже присутствует в словаре пользователя!"); return; } XElement Element = new XElement("Word", new XElement("Source", new XCData(w.source)), new XElement("Translate",new XCData(w.translate))); doc.Descendants("Dictionary") .Where(dict => long.Parse(dict.Attribute("id").Value) == d.id).Single().Add(Element); d.RefreshWordList(); }