public void Load() { XmlDocument xDoc = new XmlDocument(); xDoc.Load(savePath + saveFolder + saveFile); foreach(XmlNode xNode in xDoc.SelectNodes("Information/Columns/Column")) { bool exists = false; foreach(DataGridViewColumn col in this.Columns) { if (col.HeaderText.Equals(xNode.InnerText)) { exists = true; break; } } if (!exists) this.Columns.Add(xNode.InnerText, xNode.InnerText); } foreach (XmlNode xNode in xDoc.SelectNodes("Information/Contacts/Person")) { List<string> info = new List<string>(); if(xNode.HasChildNodes) foreach(XmlNode node in xNode.ChildNodes) info.Add(node.InnerText); bool isEmpty = true; foreach(string s in info) if(!String.IsNullOrEmpty(s)) { isEmpty = false; break; } string[] array = info.ToArray(); if(!isEmpty) this.Rows.Add(array); } }
private void SaveToFile() { List<LogEntry> entries = new List<LogEntry>(); foreach (var c in entriesPanel.Controls) { LogEntryControl entry = c as LogEntryControl; entries.Add(entry.LogEntry); } var xs = new XmlSerializer(entries.GetType()); var xml = new StringWriter(); xs.Serialize(xml, entries); File.WriteAllText("entries.xml", xml.ToString()); }
public void Save() { CheckDirectory(); XmlDocument xDoc = new XmlDocument(); xDoc.Load(savePath + saveFolder + saveFile); XmlNode xNode = xDoc.SelectSingleNode("Information/Contacts"); xNode.RemoveAll(); XmlNode xNode2 = xDoc.SelectSingleNode("Information/Columns"); xNode2.RemoveAll(); for (int i = 0; i < this.Columns.Count; i++) { XmlNode column = xDoc.CreateElement("Column"); column.InnerText = this.Columns[i].HeaderText; xDoc.DocumentElement.SelectSingleNode("Columns").AppendChild(column); } foreach(DataGridViewRow row in this.Rows) { XmlNode xTop = xDoc.CreateElement("Person"); List<XmlNode> otherNodes = new List<XmlNode>(); for(int i = 0; i < row.Cells.Count; i++) { string name = Regex.Replace(this.Columns[i].HeaderText, @"\s+", ""); XmlNode node = xDoc.CreateElement(name); node.InnerText = (row.Cells[i].Value == null) ? "" : row.Cells[i].Value.ToString(); otherNodes.Add(node); } foreach (XmlNode node in otherNodes) xTop.AppendChild(node); xDoc.DocumentElement.SelectSingleNode("Contacts").AppendChild(xTop); } xDoc.Save(savePath + saveFolder + saveFile); }
private void LoadNotes() { if (this.InvokeRequired) { this.Invoke(new ProcessBookDelegate(LoadNotes)); } else { if (string.IsNullOrEmpty(Setting.NotesPath) == false) { List<FileInfo> fileInfos = new List<FileInfo>(); var files = Directory.GetFiles(Setting.NotesPath); foreach (string f in files) { fileInfos.Add(new FileInfo(f)); } fileInfos = (from f in fileInfos orderby f.LastWriteTime descending select f).ToList(); string content = string.Empty; DisplayFile filePanel = null; NotesList.Controls.Clear(); Regex regex; foreach (var f in fileInfos) { string q = Query.Text.Trim().ToLower(); SaveRegistry("Query", q); filePanel = new DisplayFile(f.FullName, this); regex = new Regex( q, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); if (regex.IsMatch(filePanel.DisplayName) || regex.IsMatch(filePanel.Content)) { if (_notes.ContainsKey(f.FullName) == false) _notes.Add(f.FullName, filePanel); NotesList.Controls.Add(filePanel); } } } //Open_CommandLineArgs(); } }