private void listPinyin_SelectedIndexChanged(object sender, EventArgs e) { if (WorkChinese.Text.Length == 0) { listPinyin.Items.Clear(); listPinyin.Visible = false; listBoPoMoFo.Items.Clear(); listBoPoMoFo.Visible = false; return; } _current = Cursor.Position; IList <string> checkBoPo; string workPin = listPinyin.SelectedItem.ToString(); bool pinUsit = _diction.TryGetPinBo(workPin, out checkBoPo); if (!pinUsit) { Status.Text = @"Pinyin To PoPoMoFo: Table problem. Selected Pinyin not found!"; return; } if (checkBoPo.Count == 1) { textBopo.Text = checkBoPo[0]; WritePinyin.Text += listPinyin.SelectedItem; WritePinyin.Text += @" "; WorkPinyin.Text = ""; WriteChinese.Text += WorkChinese.Text; WriteBoPoMoFo.Text = WriteBoPoMoFo.Text + checkBoPo[0]; WorkPinyin.Text = ""; listBoPoMoFo.Items.Clear(); listBoPoMoFo.Visible = false; listPinyin.Items.Clear(); listPinyin.Visible = false; //Status.Text = ""; Cursor.Position = _current; try { char[] chinChars = WorkChinese.Text.ToCharArray(); string uniHex = ExpandUnihex(chinChars); using (var ceDictionary = new CeDictDataContext(Properties.Settings.Default.ChineseStudyConnection)) { var definitions = from ed in ceDictionary.CeDicts where ed.Char == WorkChinese.Text where ed.Bopo == checkBoPo[0] select ed; foreach (var definition in definitions) { textDefinition.Text = definition.English; break; } } WorkChinese.Text = ""; using (var uniHan = new CeDictDataContext(Properties.Settings.Default.ChineseStudyConnection)) { var characters = from q in uniHan.UniHans where q.cp == uniHex select q; try { foreach (var character in characters) { textCangjie.Text = character.kCangjie; break; } } catch (System.Data.StrongTypingException ex) { textCangjie.Text = @"DBNull"; Status.Text = ex.Message; } } } catch (System.Data.StrongTypingException ex) { textDefinition.Text = @"OUTERex"; textCangjie.Text = @"OUTERex"; Status.Text = ex.Message; } } else { Status.Text = @"Please select desired BoPoMoFo"; WorkBoPoMoFo.Text = ""; listBoPoMoFo.BeginUpdate(); listBoPoMoFo.Items.Clear(); foreach (string t in checkBoPo) { listBoPoMoFo.Items.Add(t); } listBoPoMoFo.EndUpdate(); listBoPoMoFo.Visible = true; listPinyin.Visible = false; } //SendKeys.Send("\t"); }
private void WorkChinese_TextChanged(object sender, EventArgs e) { InputLanguage.CurrentInputLanguage = _myLanguages[Properties.Settings.Default.Studying]; WorkChinese.ImeMode = ImeMode.On; IList <string> foundPin; IList <string> foundBo; if ((WorkChinese.Text == "") || (WorkChinese.Text == @" ")) { Variables.InputsBopo = null; WorkChinese.Text = ""; return; } if ((Variables.InputsBopo != null) && (Variables.InputsBopo == "xxxx")) { Variables.InputsBopo = null; textBopo.Text = ""; } //Status.Text = ""; bool boUsit = _diction.TryGetCharPin(WorkChinese.Text, out foundPin); bool pinUsit = _diction.TryGetCharBo(WorkChinese.Text, out foundBo); if ((!boUsit) || (!pinUsit)) { Status.Text = @"Character not in dictionary"; WorkChinese.Text = ""; textBopo.Text = ""; return; } int boCount = foundBo.Count; int pinCount = foundPin.Count; if ((Variables.InputsBopo != null) && (foundPin.Count > 1) && (foundBo.Count > 1)) { string working = Variables.InputsBopo; textBopo.Text = ""; for (int j = 0; j <= 3; j++) { if (working.Substring(j, 1) != "x") { textBopo.Text += working.Substring(j, 1); } } for (int i = 0; i < foundBo.Count; i++) { if (textBopo.Text == foundBo[i]) { foundBo[0] = foundBo[i]; boCount = 1; _diction.TryGetBoPin(textBopo.Text, out foundPin); pinCount = 1; textBopo.Text = ""; break; } } } if ((pinCount == 1) && (boCount == 1)) { textBopo.Text = foundBo[0]; WriteBoPoMoFo.Text += foundBo[0]; WriteBoPoMoFo.Text += @" "; WorkBoPoMoFo.Text = ""; WriteChinese.Text += WorkChinese.Text; IList <string> foundMyPin; bool myPin = _diction.TryGetMyPin(foundPin[0], out foundMyPin); if (myPin) { WritePinyin.Text = WritePinyin.Text + foundMyPin[0] + @" "; } WorkPinyin.Text = ""; listBoPoMoFo.Items.Clear(); listBoPoMoFo.Visible = false; listPinyin.Items.Clear(); listPinyin.Visible = false; char[] chinChars = WorkChinese.Text.ToCharArray(); string uniHex = ExpandUnihex(chinChars); using (var ceDictionary = new CeDictDataContext(Properties.Settings.Default.ChineseStudyConnection)) { var definitions = from ed in ceDictionary.CeDicts where ed.Char == WorkChinese.Text where ed.Bopo == foundBo[0] select ed; try { foreach (var definition in definitions) { textDefinition.Text = definition.English; break; } } catch (System.Data.StrongTypingException eng) { Status.Text = eng.Message; textDefinition.Text = @"DBNull"; } } WorkChinese.Text = ""; using (var uniHan = new CeDictDataContext(Properties.Settings.Default.ChineseStudyConnection)) { var characters = from q in uniHan.UniHans where q.cp == uniHex select q; try { foreach (var character in characters) { textCangjie.Text = character.kCangjie; break; } } catch (System.Data.StrongTypingException ex) { textCangjie.Text = @"DBNull"; Status.Text = ex.Message; } } return; } listPinyin.BeginUpdate(); listPinyin.Items.Clear(); foreach (string t in foundPin) { listPinyin.Items.Add(t); } listPinyin.EndUpdate(); listPinyin.Visible = true; listBoPoMoFo.BeginUpdate(); listBoPoMoFo.Items.Clear(); foreach (string t in foundBo) { listBoPoMoFo.Items.Add(t); } listBoPoMoFo.EndUpdate(); listBoPoMoFo.Visible = true; }