예제 #1
0
        public static ReportsFile GetReportsFile(string filePath)
        {
            ReportsFile   reportsFile = new ReportsFile();
            List <Report> reportList  = new List <Report>();

            if (File.Exists(filePath))
            {
                reportsFile.FilePath = filePath;

                XmlDocument doc = new XmlDocument();
                doc.Load(filePath);
                XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Report");
                foreach (XmlNode node in nodes)
                {
                    Report report = new Report();
                    report.ReportID = Int32.Parse(node.SelectSingleNode("/ReportID").ToString());
                    report.FileName = node.SelectSingleNode("/FileName").ToString();
                    report.FilePath = node.SelectSingleNode("/FilePath").ToString();

                    reportList.Add(report);
                }
            }
            reportsFile.ReportList = reportList;
            return(reportsFile);
        }
예제 #2
0
        public static void SaveReportsToFile(ReportsFile reportsFile)
        {
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings {
                Encoding = Encoding.UTF8, Indent = true
            };

            xmlWriterSettings.OmitXmlDeclaration = true;

            XmlWriter writer = XmlWriter.Create(reportsFile.FilePath, xmlWriterSettings);

            writer.WriteStartElement("Reports");

            foreach (Report report in reportsFile.ReportList)
            {
                writer.WriteStartElement("Report");
                writer.WriteElementString("ReportID", report.ReportID.ToString());
                writer.WriteElementString("FileName", report.FileName);
                writer.WriteElementString("FilePath", report.FilePath);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndDocument();

            writer.Flush();
            writer.Close();
            writer = null;
        }
예제 #3
0
        private void GetReports()
        {
            string filePath = FileUtility.GetAssemblyDirectory() + "\\Reports.xml";

            if (!File.Exists(filePath))
            {
                CreateReportsFile(filePath);
            }

            _reportsFile = XmlUtility.GetReportsFile(filePath);
        }