private static void SaveFile() { var root = new XElement("OpenTicketWindows"); foreach (var openTicketWindow in OpenTicketWindows) { root.Add(OpenTicketWindow.ToXElement(openTicketWindow)); } File.WriteAllText(Path, new XDocument(root).ToString()); }
private static void LoadFile() { if (File.Exists(Path)) { var document = XDocument.Load(Path); OpenTicketWindows.Clear(); foreach (var element in document.GetXElements("OpenTicketWindows", "rec")) { OpenTicketWindows.Add(OpenTicketWindow.FromXElement(element)); } } }
private static void Add(OpenTicketWindow openTicketWindow) { OpenTicketWindows.Add(openTicketWindow); if (!File.Exists(Path)) { SaveFile(); } var document = XDocument.Load(Path); document.GetXElement("OpenTicketWindows").Add(OpenTicketWindow.ToXElement(openTicketWindow)); File.WriteAllText(Path, document.ToString()); if (SyncData.IsConnect) { using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(InsertQuery, openTicketWindow); } }
public static void Update(OpenTicketWindow openTicketWindow) { var idx = OpenTicketWindows.FindIndex(otw => otw.CustomerId == openTicketWindow.CustomerId); if (idx >= 0) { OpenTicketWindows[idx] = openTicketWindow; } var document = XDocument.Load(Path); var element = document.GetXElements("OpenTicketWindows", "rec").First(el => el.GetXElementValue("CustomerId").ToGuid() == openTicketWindow.CustomerId); OpenTicketWindow.SetXmlValues(element, openTicketWindow); File.WriteAllText(Path, document.ToString()); if (SyncData.IsConnect) { using (var connection = ConnectionFactory.CreateConnection()) connection.Execute(UpdateQuery, openTicketWindow); } }