public void AddMonitorItem(MonitorData data) { if (null == _xdoc) { return; } XElement elmt = new XElement(ELEMENT_DIR); XAttribute attr = new XAttribute(ATTRIBUTE_NAME, data.Name); elmt.Add(attr); attr = new XAttribute(ATTRIBUTE_PATH, data.WatchPath); elmt.Add(attr); attr = new XAttribute(ATTRIBUTE_ACTION, data.NextAction); elmt.Add(attr); if (!string.IsNullOrEmpty(data.BackupPath)) { attr = new XAttribute(ATTRIBUTE_BACKUP, data.BackupPath); elmt.Add(attr); } attr = new XAttribute(ATTRIBUTE_TYPE, data.ProcessType); elmt.Add(attr); _xdoc.Descendants(SECTION_WATCH).FirstOrDefault().Add(elmt); _xdoc.Save(_configFile); }
private void menuUpdate_Click(object sender, EventArgs e) { if (this.dgvWatch.SelectedRows.Count == 0) { return; } var cells = this.dgvWatch.SelectedRows[0].Cells; this.txtName.Text = cells[0].Value as string; this.txtWatchDirectory.Text = cells[1].Value as string; string action = cells[2].Value as string; this.cmbAction.SelectedValue = action; if (action == AfterProcessAction.Backup.ToString()) { this.txtBackupDirectory.Text = cells[3].Value as string; this.panelBackup.Visible = true; } else { this.panelBackup.Visible = false; } this.cmbProcessClass.Text = cells[4].Value as string; beforeUpdateData = CollectWatchDetailData(); formStatus = ActionStatus.Update; }
private MonitorData CollectWatchDetailData() { MonitorData data = new MonitorData(); data.Name = this.txtName.Text.Trim(); data.WatchPath = this.txtWatchDirectory.Text.Trim(); data.NextAction = this.cmbAction.SelectedValue as string; if (data.NextAction == AfterProcessAction.Backup.ToString()) { data.BackupPath = this.txtBackupDirectory.Text.Trim(); } else { data.BackupPath = string.Empty; } data.ProcessType = this.cmbProcessClass.SelectedValue as string; return data; }