private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { DefaultSettings settings = DefaultSettings.Instance; switch(e.Button.Tag as string) { case "save": xml.Save(settings.LanguageMappingFile); MarkAsDirty(false); break; case "new": { int count = this.cboxLanguage.Items.Count; string[] languages = new string[count]; for(int i = 0; i < this.cboxLanguage.Items.Count; i++) { languages[i] = this.cboxLanguage.Items[i] as string; } AddLanguageMappingDialog dialog = new AddLanguageMappingDialog(languages, this.dbDriver); if(dialog.ShowDialog() == DialogResult.OK) { if(dialog.BasedUpon != string.Empty) { string xPath = @"//Languages/Language[@From='" + this.dbDriver + "' and @To='" + dialog.BasedUpon + "']"; XmlNode node = xml.SelectSingleNode(xPath); XmlNode newNode = node.CloneNode(true); newNode.Attributes["To"].Value = dialog.NewLanguage; node.ParentNode.AppendChild(newNode); } else { XmlNode parentNode = xml.SelectSingleNode(@"//Languages"); XmlAttribute attr; // Language Node langNode = xml.CreateNode(XmlNodeType.Element, "Language", null); parentNode.AppendChild(langNode); attr = xml.CreateAttribute("From"); attr.Value = settings.DbDriver; langNode.Attributes.Append(attr); attr = xml.CreateAttribute("To"); attr.Value = dialog.NewLanguage; langNode.Attributes.Append(attr); } this.cboxLanguage.Items.Add(dialog.NewLanguage); this.cboxLanguage.SelectedItem = dialog.NewLanguage; PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; case "delete": if(this.cboxLanguage.SelectedItem != null) { string language = this.cboxLanguage.SelectedItem as String; DialogResult result = MessageBox.Show("Delete '" + language + "' Mappings. Are you sure?", "Delete Language Mappings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if(result == DialogResult.Yes) { string xPath = @"//Languages/Language[@From='" + this.dbDriver + "' and @To='" + language + "']"; XmlNode node = xml.SelectSingleNode(xPath); node.ParentNode.RemoveChild(node); this.cboxLanguage.Items.Remove(language); if(this.cboxLanguage.Items.Count > 0) { this.cboxLanguage.SelectedItem = this.cboxLanguage.SelectedIndex = 0; } PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; } }
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { DefaultSettings settings = DefaultSettings.Instance; switch (e.Button.Tag as string) { case "save": xml.Save(settings.LanguageMappingFile); MarkAsDirty(false); break; case "new": { int count = this.cboxLanguage.Items.Count; string[] languages = new string[count]; for (int i = 0; i < this.cboxLanguage.Items.Count; i++) { languages[i] = this.cboxLanguage.Items[i] as string; } AddLanguageMappingDialog dialog = new AddLanguageMappingDialog(languages, this.dbDriver); if (dialog.ShowDialog() == DialogResult.OK) { if (dialog.BasedUpon != string.Empty) { string xPath = @"//Languages/Language[@From='" + this.dbDriver + "' and @To='" + dialog.BasedUpon + "']"; XmlNode node = xml.SelectSingleNode(xPath); XmlNode newNode = node.CloneNode(true); newNode.Attributes["To"].Value = dialog.NewLanguage; node.ParentNode.AppendChild(newNode); } else { XmlNode parentNode = xml.SelectSingleNode(@"//Languages"); XmlAttribute attr; // Language Node langNode = xml.CreateNode(XmlNodeType.Element, "Language", null); parentNode.AppendChild(langNode); attr = xml.CreateAttribute("From"); attr.Value = settings.DbDriver; langNode.Attributes.Append(attr); attr = xml.CreateAttribute("To"); attr.Value = dialog.NewLanguage; langNode.Attributes.Append(attr); } this.cboxLanguage.Items.Add(dialog.NewLanguage); this.cboxLanguage.SelectedItem = dialog.NewLanguage; PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; case "delete": if (this.cboxLanguage.SelectedItem != null) { string language = this.cboxLanguage.SelectedItem as String; DialogResult result = MessageBox.Show("Delete '" + language + "' Mappings. Are you sure?", "Delete Language Mappings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { string xPath = @"//Languages/Language[@From='" + this.dbDriver + "' and @To='" + language + "']"; XmlNode node = xml.SelectSingleNode(xPath); node.ParentNode.RemoveChild(node); this.cboxLanguage.Items.Remove(language); if (this.cboxLanguage.Items.Count > 0) { this.cboxLanguage.SelectedItem = this.cboxLanguage.SelectedIndex = 0; } PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; } }