public void CopyTo(Word w) { w.source = this.source; w.translate = this.translate; w.test_count = this.test_count; w.attempts = this.attempts; w.knowing = this.knowing; }
private void updateViewCurrentWord(Word w) { view.source = w.source; view.translate = w.translate; view.test_count = w.test_count; view.attempts = w.attempts; view.knowing = w.knowing; }
private void updateWordFromView(Word w) { w.source = view.source; w.translate = view.translate; w.test_count = view.test_count; w.attempts = view.attempts; w.knowing = view.knowing; }
//создает кросворд из редактора private void CreateCellModel(List<Word> words) { #region перебрать tableCell по горизонтале //создать слова for (int y = 0; y < tableLayoutPanel1.RowCount; y++) { int length = 0; for (int x = 0; x < tableLayoutPanel1.ColumnCount;) { CellWordX(y, x,ref length); if (length > 1) { Word word = new Word(); word.VH = false; word.Length = length; word.XY = new Point(x, y); words.Add(word); x = x + length; length = 0; } else { x++; length = 0; } } } #endregion #region перебрать tableCell по вертикале //создать слова for (int x = 0; x < tableLayoutPanel1.ColumnCount; x++) { int length = 0; for (int y = 0; y < tableLayoutPanel1.RowCount; ) { CellWordY(y, x, ref length); if (length > 1) { Word word = new Word(); word.VH = true; word.Length = length; word.XY = new Point(x, y); words.Add(word); y = y + length; length = 0; } else { y++; length = 0; } } } #endregion }
public static void AddWord(MongoCollection words) { Console.Write("Enter word: "); string loweredWordt = Console.ReadLine().ToLower(); Console.Write("Enter translation: "); string loweredTranslation = Console.ReadLine().ToLower(); Word newWord = new Word(loweredWordt, loweredTranslation); int countWords = words.AsQueryable<Word>().Where(w => w.Value == newWord.Value).Count(); if (countWords > 0) { Console.WriteLine("This word already exist"); } else { words.Insert<Word>(newWord); } }
public void ShowTrueSource(Word w) { Font font; this.lblTrueSource.Text = w.source; this.txtTypeSource.ReadOnly = true; this.txtTypeSource.BackColor = System.Drawing.SystemColors.Window; this.txtTypeSource.ForeColor = Color.Red; font = new Font(System.Drawing.FontFamily.GenericSansSerif, 10, this.txtTypeSource.Font.Style | FontStyle.Strikeout); this.txtTypeSource.Font = font; }
//вернуть слово из базы. Рандомно по списку private string WordBase(BackgroundWorker worker,Word word, Dictionary<int, Word> inter, List<string> listWords) { //создать регулярное выражение StringBuilder pattern = new StringBuilder(); string result = string.Empty; for (int i = 0; i < word.Length; i++) { if (inter.ContainsKey(i)) { //по координате в слове пересечения вернуть букву в пересикаемом слове int ind = inter[i].WordPointInt[word.WordPoint[i]]; if (inter[i].WordStr.Length!=0) { pattern.Append("[" + inter[i].WordStr[ind] + "]"); } else { pattern.Append("\\w{1}"); } } else { pattern.Append("\\w{1}"); } } Regex regex = new Regex(pattern.ToString()); List<string> listWordsTmp = new List<string>(listWords.ToArray()); bool exit = true; do { Random random = new Random(unchecked((int)(DateTime.Now.Ticks))); int randIndex = random.Next(listWordsTmp.Count); if (listWordsTmp.Count !=0) { if (regex.IsMatch(listWordsTmp[randIndex])) { exit = false; result = listWordsTmp[randIndex]; } } if (listWordsTmp.Count == 0) { return null; } listWordsTmp.RemoveAt(randIndex); if (worker != null) { worker.ReportProgress(100); } } while (exit); return result; }
public void RemoveWord(Word wsource) { int i = this.findRowIndexByWord(wsource); if (i >= 0) this.gridWords.Rows[i].Cells["Source"].Value = ""; }
protected override void AddWrongWord(Word w) { }
public bool CheckWord(Word w) { if (!this.currentWord.Equals(w)) { this.model.CurrentTest.CurrentPart.CheckWord(new Word(this.currentWord.source, "&*$")); return false; } else { this.addToHistory(w, true); this.model.CurrentTest.CurrentPart.CheckWord(w); this.Next(); return true; } }
private void reset() { this.t.Stop(); if (this.isHit) view.RemoveWord(this.selectedSourceWord); else { view.ShuffleWordsTranslate(Test.GetShuffleWords(this._testWords)); } this.selectedSourceWord = null; this.selectedTranslateWord = null; view.Reset(); if (view.InvokeRequired) view.Invoke(new Action<bool>(b=>view.CanCheck=b),true); }
public override bool CheckWord(Word w) { return true; }
public void Next() { //view.CanNextWord = false; if (view.InvokeRequired) view.Invoke(new Action<bool>(b => view.CanNextWord = b), false); else view.CanNextWord = false; this.timer.Stop(); if (view.InvokeRequired) view.Invoke(new Action(this.view.Stop)); else this.view.Stop(); this.currentWord = this.model.CurrentTest.CurrentPart.PartWords().FirstOrDefault(); //if (this.model.CurrentTest.CurrentPart.PartWords().GetEnumerator().MoveNext()) if(this.currentWord != null) { //this.currentWord = this.model.CurrentTest.CurrentPart.PartWords().fi if (view.InvokeRequired) view.Invoke(new Action<Word>(wrd => view.TestWord = wrd), this.currentWord); else view.TestWord = this.currentWord; if (view.InvokeRequired) view.Invoke(new Action<double>(i => this.view.Start(i)), this.timer.Interval); else this.view.Start(this.timer.Interval); this.timer.Start(); } }
public void SetKnowing(Word w, bool is_known) { w.knowing = is_known; }
// End Desin pattern State for dictionary states public void SaveWord(Word w) { model.addWord(w); }
protected override void AddWrongWord(Word w) { this.addWrongWordHandler(w); }
private Result MakeWordResult(Word word) => MakeResultItem(word.word, (word.phonetic != "" ? ("/" + word.phonetic + "/ ") : "") + word.translation.Replace("\n", "; "), "!", word.word);
public void CheckWord(Word wsource, Word wtranslate) { if ((this.selectedSourceWord != null) && (this.selectedTranslateWord != null)) this.reset(); if (wsource!=null) this.selectedSourceWord = wsource; if (wtranslate != null) this.selectedTranslateWord = wtranslate; if ((this.selectedSourceWord != null) && (this.selectedTranslateWord != null)) { this.isHit = this.model.CurrentTest.CurrentPart.CheckWord(new Word(this.selectedSourceWord.source, this.selectedTranslateWord.translate)); view.CheckWord(this.selectedSourceWord, this.selectedTranslateWord, this.isHit); view.CanCheck = false; this.t.Start(); } else if (this.selectedSourceWord != null) view.MarkSource(this.selectedSourceWord); else if (this.selectedTranslateWord != null) view.MarkTranslate(this.selectedTranslateWord); }
public void AddToHistory(Word w, bool result) { Color c; if (result) c = Color.Green; else c = Color.Red; gridHistory.Rows.Insert(0, w.translate, w.source); //gridHistory.Rows[0].Cells[0].Style.BackColor = c; gridHistory.Rows[0].Cells[0].Style.ForeColor = c; gridHistory.Rows[0].Cells[1].Style.ForeColor = c; }
public void MarkSource(Word w) { this.markWord(w, "Source", SELECT_COLOR); }
public void AddWord(string name, string translation) { Word word = new Word(name, translation); dictionary.Insert(word); }
public void CheckWord(Word wsource, Word wtranslate, bool IsHit) { this.markWord(wsource, "Source", IsHit ? TRUE_CHECK_COLOR : FALSE_CHECK_COLOR); this.markWord(wtranslate, "Translate", IsHit ? TRUE_CHECK_COLOR : FALSE_CHECK_COLOR); }
private void addToHistory(Word w, bool result) { if (view.InvokeRequired) { view.Invoke(new Action<Word, bool>((wrd, b) => view.AddToHistory(wrd, b)), w, result); } else view.AddToHistory(w, result); }
protected override void AddWrongWord(Word w) { this.addWrongWordHandler(w); this._uncheckedWords.Add(w); this._uncheckedWords = Test.GetShuffleWords(this._uncheckedWords); }
private int findRowIndexByWord(Word w) { for (int i = 0; i < gridWords.RowCount; i++ ) { if (w.Equals(new Word(gridWords.Rows[i].Cells["Source"].Value.ToString(), gridWords.Rows[i].Cells["Translate"].Value.ToString()))) return i; } return -1; }
public void CheckWord(Word wsource, Word wtranslate) { }
public void MarkTranslate(Word w) { this.markWord(w, "Translate", SELECT_COLOR); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { List<Word> words = new List<Word>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Application.StartupPath + "\\crossModel"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open); StreamReader streamReader = new StreamReader(file, ASCIIEncoding.Default); TableClear(); string crossStr = string.Empty; string[] crossParam; try { crossStr = streamReader.ReadLine(); crossParam = Regex.Split(crossStr, ","); string[] whStr = Regex.Split(crossParam[0], " "); width = int.Parse(whStr[0]); height = int.Parse(whStr[1]); ColumnCount = width / CellSize; RowCount = height / CellSize; } catch (Exception) { throw; } for (int i = 1; i < crossParam.Length-1; i++) { Word word = new Word(); try { string[] paramStr = Regex.Split(crossParam[i], " "); word.XY = new Point(int.Parse(paramStr[0]), int.Parse(paramStr[1])); if (paramStr[3]=="H") { word.VH = false; } else if (paramStr[3] == "V") { word.VH = true; } word.Length = int.Parse(paramStr[2]); words.Add(word); } catch (Exception) { throw; } } //отобразить foreach (var item in words) { Dictionary<int, Point> wordP = item.WordPoint; foreach (var charP in wordP) { ((CellButton)tableLayoutPanel1.GetControlFromPosition(charP.Value.X, charP.Value.Y)).PressedCell = true; } } } }
private void markWord(Word w, string column, Color c) { clearGridColumns(column); int i = this.findRowIndexByWord(w); if (i >= 0) gridWords.Rows[i].Cells[column].Style.BackColor = c; }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { //words.Clear(); words = new List<Word>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Application.StartupPath + "\\crossModel"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(openFileDialog.FileName, FileMode.Open); StreamReader streamReader = new StreamReader(file, ASCIIEncoding.Default); string crossStr = string.Empty; string[] crossParam; try { crossStr = streamReader.ReadLine(); streamReader.Close(); crossParam = Regex.Split(crossStr, ","); string[] whStr = Regex.Split(crossParam[0], " "); width = int.Parse(whStr[0]); height = int.Parse(whStr[1]); ColumnCount = width / CellSize; RowCount = height / CellSize; } catch (Exception) { throw; } //настройки таблицы for (int i = 1; i < crossParam.Length - 1; i++) { Word word = new Word(i); try { string[] paramStr = Regex.Split(crossParam[i], " "); word.XY = new Point(int.Parse(paramStr[0]), int.Parse(paramStr[1])); if (paramStr[3] == "H") { word.VH = false; } else if (paramStr[3] == "V") { word.VH = true; } word.Length = int.Parse(paramStr[2]); words.Add(word); } catch (Exception) { throw; } } tableLayoutPanel1.ColumnCount = ColumnCount; tableLayoutPanel1.RowCount = RowCount; this.tableLayoutPanel1.Size = new System.Drawing.Size(CellSize * ColumnCount + ColumnCount, CellSize * RowCount + RowCount); //отобразить for (int i = 0; i < ColumnCount; i++) { tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, CellSize)); } for (int i = 0; i < RowCount; i++) { tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, CellSize)); } TableClear(); for (int i = 0; i < words.Count; i++) { Dictionary<int, Point> wordP = words[i].WordPoint; foreach (var charP in wordP) { MyGroupBox btn = new MyGroupBox(); btn.Name = charP.Value.X.ToString() + " " + charP.Value.Y.ToString(); if (charP.Key == 0) { btn.Index = (i + 1).ToString(); } if (tableLayoutPanel1.Controls.Find(btn.Name, false).Length == 0) { tableLayoutPanel1.Controls.Add(btn); tableLayoutPanel1.SetCellPosition(btn, new TableLayoutPanelCellPosition(charP.Value.X, charP.Value.Y)); } else if (charP.Key == 0) { ((MyGroupBox)tableLayoutPanel1.GetControlFromPosition(charP.Value.X, charP.Value.Y)).Index = (i + 1).ToString(); } } } } }
private void gridWords_CellClick(object sender, DataGridViewCellEventArgs e) { Word w; DataGridViewCell cell = (sender as DataGridView).CurrentCell; if ((this._canCheck) && (cell.Value.ToString() != "") && (this.controller != null)) { w = new Word(cell.OwningRow.Cells["Source"].Value.ToString(), cell.OwningRow.Cells["Translate"].Value.ToString()); if (cell.OwningColumn.Name == "Source") controller.CheckWord(wsource: w); else if (cell.OwningColumn.Name == "Translate") controller.CheckWord(wtranslate: w); } }
private Result MakeWordResult(Word word) => MakeResultItem(word.word, (word.phonetic != "" ? ("/" + word.phonetic + "/ ") : "") + (settings.ShowEnglishDefinition ? word.definition.Replace("\n", "; ") : word.translation.Replace("\n", "; ")), "!", word.word);