public static void GeneratePdfReports()
    {

        StringBuilder sb = new StringBuilder();
        //sb.Append("<style>.th {background-color: red;}</style>");

        using (supermarketEntities context = new supermarketEntities())
        {


            var reports = from r in context.SellsReports
                          select r;

            PDFTable(sb, reports);

            PDFBuilder.HtmlToPdfBuilder builder = new PDFBuilder.HtmlToPdfBuilder(PageSize.LETTER);
            //builder.ImportStylesheet(AppDomain.CurrentDomain.BaseDirectory + "style.css"); 

            PDFBuilder.HtmlPdfPage page = builder.AddPage();
            page.AppendHtml(sb.ToString());
            byte[] file = builder.RenderPdf();

            string tempFolder = "../../../";
            string tempFileName = "Sample-Aggregated-Sales-Report.pdf";
            if (DirectoryExist(tempFolder))
            {
                if (!File.Exists(tempFolder + tempFileName))
                    File.WriteAllBytes(tempFolder + tempFileName, file);
            }
        }
    }
        static void Main(string[] args)
        {
            
            using (supermarketEntities sqlDb= new supermarketEntities())
            {

            
                string query =
                    "select VendorName, FromDate, SUM(Quantity * UnitPrice) as Sum from SellsReport s " +
                    "inner join Products p on s.ProductID = p.ID " +
                    "inner join Vendors v on p.vendors_ID = v.ID " +
                    "group by VendorName, FromDate " +
                    "order by VendorName";

                var objects = sqlDb.Database.SqlQuery<XmlReport>(query);

                foreach (var item in objects)
                {
                    Console.WriteLine("{0} - {1:d} - {2}", item.VendorName, item.FromDate, item.Sum);
                }

                //var xmlReportsData = sqlDb.SellsReports
                // .Include("Product")
                // .Select(p => new
                // {
                //     VendorName = p.Product.Vendor.VendorName,
                //     FromDate = p.FromDate,
                //     Sum = p.Quantity * p.UnitPrice
                // })
                // .GroupBy(p => new { p.VendorName, p.FromDate });

                //List<object> xmlReportObjects = new List<object>();
                //foreach (var report in xmlReportsData)
                //{
                //    string vName = null;
                //    DateTime? date = null;
                //    decimal sum = 0.0m;
                //    foreach (var atrib in report)
                //    {
                //        vName = atrib.VendorName;
                //        date = atrib.FromDate;
                //        sum += atrib.Sum;
                //    }

                //    xmlReportObjects.Add(new { VendorName = vName,FromDate = date,Sum = sum});
                //}

                //foreach (var item in xmlReportObjects)
                //{
                //    Console.WriteLine(item.ToString());
                //}
            }
        }
    public static IEnumerable<XmlReport> GetDataForXmlReport()
    {
        using (supermarketEntities sqlDb = new supermarketEntities())
        {
            string query =
                "select VendorName, FromDate, SUM(Quantity * UnitPrice) as Sum from SellsReport s " +
                "inner join Products p on s.ProductID = p.ID " +
                "inner join Vendors v on p.vendors_ID = v.ID " +
                "group by VendorName, FromDate " +
                "order by VendorName";
            var objects = sqlDb.Database.SqlQuery<XmlReport>(query);

            return objects.ToList();
        }
    }
    public static ICollection<Expenses> ReadExpensesFromXml()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        using (supermarketEntities sqlDb = new supermarketEntities())
        {
            Dictionary<string, int> vendorIds = new Dictionary<string, int>();
            var vendors = sqlDb.Vendors;

            foreach (var item in vendors)
            {
                vendorIds.Add(item.VendorName, item.ID);
            }

            List<Expenses> expenses = new List<Expenses>();
            using (XmlReader reader = XmlReader.Create("../../../Vendor-Expences.xml"))
            {
                string name = "";
                string date = null;
                decimal expense = 0;
                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) &&
                        (reader.Name == "sale"))
                    {
                        name = reader.GetAttribute(0);

                    }
                    else if ((reader.NodeType == XmlNodeType.Element) &&
                        (reader.Name == "expenses"))
                    {
                        date = reader.GetAttribute("month");
                        expense = decimal.Parse(reader.ReadElementContentAsString());
                        Expenses newExpense = new Expenses()
                        {
                            ID = expenses.Count+1,
                            VendorID = vendorIds[name],
                            Expenses1 = expense,
                            Mounth = date
                        };

                        expenses.Add(newExpense);
                    }
                }
            }
         
            return expenses;
        }
    }
    public static void WriteSellsReports(ICollection<SellsReport> reports)
    {
        using (supermarketEntities sqlDB = new supermarketEntities())
        {
            List<int> ids = sqlDB.SellsReports.Select(x => x.ID).ToList();

            foreach (var report in reports)
            {
                if (!ids.Contains(report.ID))
                {
                    sqlDB.SellsReports.Add(report);
                }
            }

            sqlDB.SaveChanges();
        }
    }
    public static void WriteVendors(ICollection<Vendor> vendors)
    {
        using (supermarketEntities sqlDB = new supermarketEntities())
        {
            List<int> ids = sqlDB.Vendors.Select(x => x.ID).ToList();

            foreach (var vendor in vendors)
            {
                if (!ids.Contains(vendor.ID))
                {
                    sqlDB.Vendors.Add(vendor);
                }
            }

            sqlDB.SaveChanges();
        }
    }
    public static void WriteMesures(ICollection<Mesure> mesures)
    {
        using (supermarketEntities sqlDB = new supermarketEntities())
        {
            List<int> ids = sqlDB.Mesures.Select(x => x.ID).ToList();
            foreach (var mesure in mesures)
            {
                if (!ids.Contains(mesure.ID))
                {

                    sqlDB.Mesures.Add(mesure);
                }
            }

            sqlDB.SaveChanges();
        }
    }
    public static void WriteProducts(ICollection<Product> products)
    {
        using (supermarketEntities sqlDB = new supermarketEntities())
        {
            List<int> ids = sqlDB.Products.Select(x => x.ID).ToList();

            foreach (var product in products)
            {
                if (!ids.Contains(product.ID))
                {
                    sqlDB.Products.Add(product);
                }
            }

            sqlDB.SaveChanges();
        }
    }
    public static void WriteVendorExpenses(ICollection<Expenses> expenses)
    {
        using (supermarketEntities sqlDB = new supermarketEntities())
        {
            List<int> ids = sqlDB.Expenses.Select(x => x.ID).ToList();

            foreach (var expens in expenses)
            {
                if (!ids.Contains(expens.ID))
                {
                    sqlDB.Expenses.Add(expens);
                }
            }

            sqlDB.SaveChanges();
        }
    }