Ejemplo n.º 1
0
 private void DeleteWordFromExcel(WordData word)
 {
     Excel.Range wordCell = null;
     foreach (Excel.Worksheet sheet in dictionary.excelObj.Sheets)
     {
         Excel.Range temp = sheet.Cells.Find(word.word);
         if (temp != null)
         {
             wordCell = temp;
             break;
         }
     }
     if (wordCell != null)
     {
         Excel.Range wordRow = wordCell.EntireRow;
         wordRow.Delete(Excel.XlDeleteShiftDirection.xlShiftUp);
     }
 }
Ejemplo n.º 2
0
 public void AddWord(WordData word)
 {
     TrieRoot.AddWord(word);
     Excel.Worksheet currentSheet;
     try
     {
         currentSheet = excelObj.Sheets[word.Group];
     }
     catch
     {
         excelObj.Sheets.Add(Type.Missing, excelObj.Sheets[excelObj.Sheets.Count]);
         Excel.Worksheet newSheet = excelObj.Sheets[excelObj.Sheets.Count];
         newSheet.Name = word.Group;
         currentSheet  = newSheet;
     }
     Excel.Range last = currentSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
     currentSheet.Cells[last.Row + 1, 1] = word.word;
     currentSheet.Cells[last.Row + 1, 2] = word.definition;
     currentSheet.Cells[last.Row + 1, 3] = word.type.ToString();
     excelObj.ActiveWorkbook.Save();
 }
Ejemplo n.º 3
0
        private void Save_Button_Click(object sender, EventArgs e)
        {
            if (WordList.SelectedItem != null &&
                WordComboBox.Text.CompareTo(WordList.SelectedItem.ToString()) == 0)
            {
                string sCaption = "Save Changes?";
                string sMessageBoxText;
                bool   GroupChanged = false;
                bool   NewGroup     = false;
                if (Group_ComboBox.SelectedItem == null && Group_ComboBox.Text.Length > 0)
                {
                    sMessageBoxText = "Creating a new group:" + Group_ComboBox.Text;
                    NewGroup        = true;
                }
                else if (Group_ComboBox.SelectedItem.ToString() != ((WordData)WordList.SelectedItem).Group)
                {
                    sMessageBoxText = "Group has been changed";
                    GroupChanged    = true;
                }
                else
                {
                    sMessageBoxText = "Changes are irreversible";
                }
                MessageBoxButtons btnMessageBox  = MessageBoxButtons.YesNoCancel;
                MessageBoxIcon    icnMessageBox  = MessageBoxIcon.Warning;
                DialogResult      rsltMessageBox = MessageBox.Show(sMessageBoxText, sCaption, btnMessageBox, icnMessageBox);
                switch (rsltMessageBox)
                {
                case DialogResult.Yes:
                    if (GroupChanged)
                    {
                        Excel.Range wordCell = null;
                        foreach (Excel.Worksheet tempsheet in dictionary.excelObj.Sheets)
                        {
                            Excel.Range temp = tempsheet.Cells.Find(WordComboBox.Text);
                            if (temp != null)
                            {
                                wordCell = temp;
                                break;
                            }
                        }
                        if (wordCell != null)
                        {
                            Excel.Range wordRow = wordCell.EntireRow;
                            wordRow.Delete(Excel.XlDeleteShiftDirection.xlShiftUp);
                        }
                        Excel.Worksheet sheet   = dictionary.excelObj.Sheets[Group_ComboBox.SelectedItem];
                        WordData        newWord = (WordData)WordList.SelectedItem;
                        dictionary.RemoveWord(newWord);
                        newWord.word       = ((WordData)WordList.SelectedItem).ToString();
                        newWord.definition = Definition.Text as string;
                        newWord.type       = getSelectedType();
                        newWord.Group      = Group_ComboBox.SelectedItem as string;
                        dictionary.AddWord(newWord);
                        WordList.SelectedItem = newWord;
                    }
                    else if (NewGroup)
                    {
                        Excel.Range wordCell = null;
                        foreach (Excel.Worksheet sheet in dictionary.excelObj.Sheets)
                        {
                            Excel.Range temp = sheet.Cells.Find(WordComboBox.Text);
                            if (temp != null)
                            {
                                wordCell = temp;
                                break;
                            }
                        }
                        if (wordCell != null)
                        {
                            Excel.Range wordRow = wordCell.EntireRow;
                            wordRow.Delete(Excel.XlDeleteShiftDirection.xlShiftUp);
                        }
                        WordData newWord = (WordData)WordList.SelectedItem;
                        newWord.Group = Group_ComboBox.Text;
                        dictionaryData.Groups.Add(Group_ComboBox.Text);
                        Group_ComboBox.Items.Add(Group_ComboBox.Text);
                        dictionary.AddWord(newWord);
                    }
                    else
                    {
                        ((WordData)WordList.SelectedItem).type       = getSelectedType();
                        ((WordData)WordList.SelectedItem).definition = Definition.Text;
                        Excel.Range wordCell = null;
                        foreach (Excel.Worksheet tempsheet in dictionary.excelObj.Sheets)
                        {
                            Excel.Range temp = tempsheet.Cells.Find(WordComboBox.Text);
                            if (temp != null)
                            {
                                wordCell = temp;
                                break;
                            }
                        }
                        Excel.Range wordRow = wordCell.EntireRow;
                        Object[,] value2 = wordRow.Value2;
                        value2[1, 2]     = Definition.Text;
                        value2[1, 3]     = TypeComboBox.SelectedItem.ToString();
                        wordRow.Value2   = value2;
                        dictionary.excelObj.ActiveWorkbook.Save();
                    }
                    break;

                case DialogResult.No:
                    /* ... */
                    break;

                case DialogResult.Cancel:
                    /* ... */
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private void WordList_SelectedIndexChanged(object sender, EventArgs e)
        {
            WordData temp = (WordData)WordList.SelectedItem;

            LoadWordData(temp);
        }