示例#1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            foreach (GlossingControl aGC in flowLayoutPanel.Controls)
            {
                // means we have to add it to the kb. The source word will get trimmed, but not the target
                string strTargetWord = aGC.TargetWord.Trim(m_aEC.DelimitersReverse);
                TargetWords.Add(strTargetWord);
                m_aEC.AddEntryPair(aGC.SourceWord, strTargetWord);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private void UpdateKB()
        {
            System.Diagnostics.Debug.Assert(m_aEC != null);
            AddKBEntry dlg = new AddKBEntry(SelectedWord, SelectedWord, m_fontSource, m_fontTarget);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
#if !MovedToEncCnvtrs
                try
                {
                    m_aEC.AddEntryPair(dlg.Source, dlg.Target, true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("Unable to access the knowledge base because:{0}{0}{1}",
                                                  Environment.NewLine, ex.Message), DiscourseChartForm.cstrCaption);
                }

                m_bTurnOffSelectedIndexChange = true;
                SelectedWord = dlg.Target;
                m_bTurnOffSelectedIndexChange = false;
#else
                AdaptItKnowledgeBase aikb = new AdaptItKnowledgeBase();
                string strKbPath          = m_aEC.GetEncConverter.ConverterIdentifier;
                aikb.ReadXml(strKbPath);
                if ((aikb.KB.Count > 0) && (aikb.MAP.Count > 0))
                {
                    // first see if there's already a row with this word in it (in which case, we just add a new entry)
                    if (!FindExistingEntry(aikb, strKbPath, dlg.Source, dlg.Target))
                    {
                        AdaptItKnowledgeBase.TURow aTURow = aikb.TU.AddTURow("0", dlg.Source, aikb.MAP[0]);
                        aikb.RS.AddRSRow("1", dlg.Target, aTURow);
                        aikb.WriteXml(strKbPath);
                    }

                    m_bTurnOffSelectedIndexChange = true;
                    SelectedWord = dlg.Target;
                    m_bTurnOffSelectedIndexChange = false;
                }
#endif
            }
        }