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.DbTargetMappingFile); MarkAsDirty(false); break; case "new": { int count = this.cboxDbTarget.Items.Count; string[] dbTargets = new string[count]; for (int i = 0; i < this.cboxDbTarget.Items.Count; i++) { dbTargets[i] = this.cboxDbTarget.Items[i] as string; } AddDbTargetMappingDialog dialog = new AddDbTargetMappingDialog(dbTargets, this.dbDriver); if (dialog.ShowDialog() == DialogResult.OK) { if (dialog.BasedUpon != string.Empty) { string xPath = @"//DbTargets/DbTarget[@From='" + this.dbDriver + "' and @To='" + dialog.BasedUpon + "']"; XmlNode node = xml.SelectSingleNode(xPath); XmlNode newNode = node.CloneNode(true); newNode.Attributes["To"].Value = dialog.NewDbTarget; node.ParentNode.AppendChild(newNode); } else { XmlNode parentNode = xml.SelectSingleNode(@"//DbTargets"); XmlAttribute attr; // Language Node langNode = xml.CreateNode(XmlNodeType.Element, "DbTarget", null); parentNode.AppendChild(langNode); attr = xml.CreateAttribute("From"); attr.Value = settings.DbDriver; langNode.Attributes.Append(attr); attr = xml.CreateAttribute("To"); attr.Value = dialog.NewDbTarget; langNode.Attributes.Append(attr); } this.cboxDbTarget.Items.Add(dialog.NewDbTarget); this.cboxDbTarget.SelectedItem = dialog.NewDbTarget; PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; case "delete": if (this.cboxDbTarget.SelectedItem != null) { string target = this.cboxDbTarget.SelectedItem as String; DialogResult result = MessageBox.Show("Delete '" + target + "' Mappings. Are you sure?", "Delete DbTarget Mappings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { string xPath = @"//DbTargets/DbTarget[@From='" + this.dbDriver + "' and @To='" + target + "']"; XmlNode node = xml.SelectSingleNode(xPath); node.ParentNode.RemoveChild(node); this.cboxDbTarget.Items.Remove(target); if (this.cboxDbTarget.Items.Count > 0) { this.cboxDbTarget.SelectedItem = this.cboxDbTarget.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.DbTargetMappingFile); MarkAsDirty(false); break; case "new": { int count = this.cboxDbTarget.Items.Count; string[] dbTargets = new string[count]; for(int i = 0; i < this.cboxDbTarget.Items.Count; i++) { dbTargets[i] = this.cboxDbTarget.Items[i] as string; } AddDbTargetMappingDialog dialog = new AddDbTargetMappingDialog(dbTargets, this.dbDriver); if(dialog.ShowDialog() == DialogResult.OK) { if(dialog.BasedUpon != string.Empty) { string xPath = @"//DbTargets/DbTarget[@From='" + this.dbDriver + "' and @To='" + dialog.BasedUpon + "']"; XmlNode node = xml.SelectSingleNode(xPath); XmlNode newNode = node.CloneNode(true); newNode.Attributes["To"].Value = dialog.NewDbTarget; node.ParentNode.AppendChild(newNode); } else { XmlNode parentNode = xml.SelectSingleNode(@"//DbTargets"); XmlAttribute attr; // Language Node langNode = xml.CreateNode(XmlNodeType.Element, "DbTarget", null); parentNode.AppendChild(langNode); attr = xml.CreateAttribute("From"); attr.Value = settings.DbDriver; langNode.Attributes.Append(attr); attr = xml.CreateAttribute("To"); attr.Value = dialog.NewDbTarget; langNode.Attributes.Append(attr); } this.cboxDbTarget.Items.Add(dialog.NewDbTarget); this.cboxDbTarget.SelectedItem = dialog.NewDbTarget; PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; case "delete": if(this.cboxDbTarget.SelectedItem != null) { string target = this.cboxDbTarget.SelectedItem as String; DialogResult result = MessageBox.Show("Delete '" + target + "' Mappings. Are you sure?", "Delete DbTarget Mappings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if(result == DialogResult.Yes) { string xPath = @"//DbTargets/DbTarget[@From='" + this.dbDriver + "' and @To='" + target + "']"; XmlNode node = xml.SelectSingleNode(xPath); node.ParentNode.RemoveChild(node); this.cboxDbTarget.Items.Remove(target); if(this.cboxDbTarget.Items.Count > 0) { this.cboxDbTarget.SelectedItem = this.cboxDbTarget.SelectedIndex = 0; } PopulateGrid(this.dbDriver); MarkAsDirty(true); } } break; } }