示例#1
0
        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());
        }
示例#2
0
        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));
                }
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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);
            }
        }