private void btnRemoveNode_Click(object sender, EventArgs e) { try { //_DataMessage.LoadData("XmlFile.xml"); string name = this.cmbConfigSelect.SelectedItem.ToString(); string value = _DataMessage.GetValue(name); if (name != null) { DataModule module = new DataModule(name, value); if (this._DataMessage.RemoveNode("XmlFile.xml", module)) { MessageBox.Show("删除成功!"); } else { MessageBox.Show("删除失败!"); } } } catch (Exception ex) { throw ex; } }
private void btnAddNode_Click(object sender, EventArgs e) { try { DataModule module = new DataModule(rhtbConfigName.Text, rhtbConfigValue.Text); _DataMessage.AddDataToXml("XmlFile.xml", module); MessageBox.Show("添加成功"); } catch (Exception ex) { throw ex; } }
public bool RemoveNode(string filePath, DataModule module) { bool isRemoveSucceed = false; //isRemoveSucceed = this._DataModules.Remove(module); for (int i = 0; i < _DataModules.Count; i++) { if (_DataModules[i].Name == module.Name && _DataModules[i].Value == module.Value) { _DataModules.RemoveAt(i); isRemoveSucceed = true; } } Function.XmlSerializeToFile(typeof(List <DataModule>), this._DataModules, filePath); return(isRemoveSucceed); }
public void AddDataToXml(string filePath, DataModule module) { this._DataModules.Add(module); Function.XmlSerializeToFile(typeof(List <DataModule>), this._DataModules, filePath); }