public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<ConfluxDbContext, Configuration>()); var db = new ConfluxDbContext(); JSON.SaveFile(db); var carPrices = db.Cars .Select(c => new { c.Model, c.Make, c.Price }) .ToList(); PDFReporter.CreateReport(carPrices, "../../PDF-Reports/car-price.pdf", "Car prices report"); Console.WriteLine("Car prices report created."); var carPricesInRange = db.Cars .Where(c => c.Price > 15000 && c.Price < 25000) .ToList(); PDFReporter.CreateReport(carPricesInRange, "../../PDF-Reports/car-price-between-15000-and-25000.pdf", "Car prices between 15000 and 25000"); Console.WriteLine("Car prices between 15000 and 25000 report created."); XmlReport xlmReport = new XmlReport(); bool success = xlmReport.GenerateXmlReport("../../xmlReport.xml"); Console.WriteLine("XML Report created at: '../ConfluxApplication/xmlReport.xml'"); db.Dispose(); }
public bool GenerateXmlReport(string name) { using (var db = new ConfluxDbContext()) { try { XDocument xmlDocument = new XDocument( new XDeclaration("1.0", "utf-8", "no"), new XProcessingInstruction("xml-stylesheet", @"type=""text/xsl"" href=""SalesStyle.xslt""")); var dealerExpenses = from dealer in db.DealerExpenses select dealer; var dealerByName = dealerExpenses.GroupBy(x => x.DealerName); var exp = new XElement("Expenses-By-Month"); xmlDocument.Add(exp); foreach (var item in dealerByName) { var saleInMonth = new XElement("dealer"); exp.Add(saleInMonth); var dealer = new XAttribute("name", item.Key); saleInMonth.Add(dealer); foreach (var date in item) { //// TODO Get date for sum of price and calculate total sum saleInMonth.Add( new XElement( "expenses", new XAttribute("date", (date.Month).ToString("MMM yyyy")), date.Value)); } } xmlDocument.Save(name); } catch (Exception e) { Console.WriteLine("Error when generating XML report! Error: {0}", e.InnerException.Message); return false; } return true; } }