private void addTagButton_Click(object sender, EventArgs e) { Dialogs.AddTagDialog dialog = new Dialogs.AddTagDialog(); String[] categories = new String[m_Categories.Count]; for (int i = 0; i < m_Categories.Count; ++i) { categories[i] = m_Categories[i].Name; } String selCat = ((categoriesBox.SelectedIndex != -1 && categoriesBox.SelectedIndex != categoriesBox.Items.Count - 1) ? categoriesBox.SelectedItem.ToString() : String.Empty); dialog.SetCategories(categories, selCat); if (dialog.ShowDialog(this) == DialogResult.OK) { String category = dialog.Category; String tagName = dialog.TagName; AddTag(category, tagName); } }
private void AddTag() { if (m_LanguageId == -1) { return; } String[] categories = new String[m_Categories.Count]; for (int i = 0; i < categories.Length; ++i) { categories[i] = m_Categories[i].Name; } String selCat = categoriesList.SelectedIndex != -1 && categoriesList.Items.Count > 0 ? categoriesList.Items[categoriesList.SelectedIndex].ToString() : String.Empty; Dialogs.AddTagDialog dialog = new Dialogs.AddTagDialog(); dialog.SetCategories(categories, selCat); if (dialog.ShowDialog(this) == DialogResult.OK) { String category = dialog.Category; String tagName = dialog.TagName; var existingCategory = m_Categories.FirstOrDefault((Ares.Tags.CategoryForLanguage item) => { return(item.Name.Equals(category, StringComparison.OrdinalIgnoreCase)); }); int catId; try { var dbWrite = Ares.Tags.TagsModule.GetTagsDB().GetWriteInterfaceByLanguage(m_LanguageId); var dbRead = Ares.Tags.TagsModule.GetTagsDB().GetReadInterfaceByLanguage(m_LanguageId); if (existingCategory != null) { catId = existingCategory.Id; } else { catId = dbWrite.AddCategory(category); } var allTags = dbRead.GetAllTags(catId); var existingTag = allTags.FirstOrDefault((tagForLanguage) => { return(tagForLanguage.Name.Equals(tagName, StringComparison.OrdinalIgnoreCase)); }); if (existingTag != null) { MessageBox.Show(this, StringResources.TagExists, StringResources.Ares, MessageBoxButtons.OK, MessageBoxIcon.Information); m_LastTagId = existingTag.Id; } else { m_LastTagId = dbWrite.AddTag(catId, tagName); } Ares.Editor.Actions.TagChanges.Instance.FireTagsDBChanged(this); m_Listen = false; if (m_LastCategoryId != catId) { m_LastCategoryId = catId; UpdateCategories(); } UpdateTags(); m_LastTranslationType = TranslationType.Tag; UpdateTranslations(); m_Listen = true; } catch (Ares.Tags.TagsDbException ex) { MessageBox.Show(this, String.Format(StringResources.TagsDbError, ex.Message), StringResources.Ares, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }