public Aspose.Pdf.Generator.Pdf GetCatalog()
        {
            productsList = productDao.GetAll();
            CategoryList = categoryDao.GetAll();

            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.IsTruetypeFontMapCached = false;

            // If you have purchased a license,
            // Set license like this:
            // string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
            // Aspose.Pdf.License lic = new Aspose.Pdf.License();
            // lic.SetLicense(licenseFile);

            string xmlFile = Server.MapPath("~/App_Data/xml/Catalog.xml");
            string path    = Server.MapPath("~/img");

            pdf.BindXML(xmlFile, null);

            Section   section   = pdf.Sections["section1"];
            Paragraph logoPara  = section.Paragraphs["Logo"];
            Image     logoImage = (Image)logoPara;

            logoImage.ImageInfo.File = path + "\\FallCatalog.jpg";
            logoImage.ImageScale     = 0.77F;

            Section   section2      = pdf.Sections["section2"];
            Paragraph beveragePara  = section2.Paragraphs["BeverageTable"];
            Table     beverageTable = (Table)beveragePara;
            Row       row1          = beverageTable.Rows[0];
            Cell      row1Cell2     = row1.Cells[1];
            Image     beverageImage = (Image)row1Cell2.Paragraphs[0];

            beverageImage.ImageInfo.File = path + "\\Beverage.jpg";

            Table beveragesTable1 = (Table)section2.Paragraphs["BeverageTable1"];

            FillTable(beveragesTable1, GetProductsByCateGoryID(1));

            Paragraph condimentsPara          = section2.Paragraphs["CondimentsTable"];
            Table     condimentsTable         = (Table)condimentsPara;
            Row       row1CondimentTable      = condimentsTable.Rows[0];
            Cell      row1Cell2CondimentTable = row1CondimentTable.Cells[1];
            Image     condimentsImage         = (Image)row1Cell2CondimentTable.Paragraphs[0];

            condimentsImage.ImageInfo.File = path + "\\Condiments.jpg";

            Table condimentsTable1 = (Table)section2.Paragraphs["CondimentsTable1"];

            FillTable(condimentsTable1, GetProductsByCateGoryID(2));

            Paragraph confectionsPara           = section2.Paragraphs["ConfectionsTable"];
            Table     confectionsTable          = (Table)confectionsPara;
            Row       row1ConfectionsTable      = confectionsTable.Rows[0];
            Cell      row1Cell2ConfectionsTable = row1ConfectionsTable.Cells[1];
            Image     confectionsImage          = (Image)row1Cell2ConfectionsTable.Paragraphs[0];

            confectionsImage.ImageInfo.File = path + "\\Confections.jpg";

            Table confectionsTable1 = (Table)section2.Paragraphs["ConfectionsTable1"];

            FillTable(confectionsTable1, GetProductsByCateGoryID(3));

            Paragraph dairyPara           = section2.Paragraphs["DairyTable"];
            Table     dairyTable          = (Table)dairyPara;
            Row       row1DairyTable      = dairyTable.Rows[0];
            Cell      row1Cell2DairyTable = row1DairyTable.Cells[1];
            Image     diaryImage          = (Image)row1Cell2DairyTable.Paragraphs[0];

            diaryImage.ImageInfo.File = path + "\\Dairy.jpg";

            Table dairyTable1 = (Table)section2.Paragraphs["DairyTable1"];

            FillTable(dairyTable1, GetProductsByCateGoryID(4));

            Paragraph grainsPara           = section2.Paragraphs["GrainsTable"];
            Table     grainsTable          = (Table)grainsPara;
            Row       row1GrainsTable      = grainsTable.Rows[0];
            Cell      row1Cell2GrainsTable = row1GrainsTable.Cells[1];
            Image     grainsImage          = (Image)row1Cell2GrainsTable.Paragraphs[0];

            grainsImage.ImageInfo.File = path + "\\Grains.jpg";

            Table grainsTable1 = (Table)section2.Paragraphs["GrainsTable1"];

            FillTable(grainsTable1, GetProductsByCateGoryID(5));

            Paragraph meatPara           = section2.Paragraphs["MeatTable"];
            Table     meatTable          = (Table)meatPara;
            Row       row1MeatTable      = meatTable.Rows[0];
            Cell      row1Cell2MeatTable = row1MeatTable.Cells[1];
            Image     meatImage          = (Image)row1Cell2MeatTable.Paragraphs[0];

            meatImage.ImageInfo.File = path + "\\Meat.jpg";

            Table meatTable1 = (Table)section2.Paragraphs["MeatTable1"];

            FillTable(meatTable1, GetProductsByCateGoryID(6));

            Paragraph producePara           = section2.Paragraphs["ProduceTable"];
            Table     produceTable          = (Table)producePara;
            Row       row1ProduceTable      = produceTable.Rows[0];
            Cell      row1Cell2ProduceTable = row1ProduceTable.Cells[1];
            Image     produceImage          = (Image)row1Cell2ProduceTable.Paragraphs[0];

            produceImage.ImageInfo.File = path + "\\Produce.jpg";

            Table produceTable1 = (Table)section2.Paragraphs["ProduceTable1"];

            FillTable(produceTable1, GetProductsByCateGoryID(7));

            Paragraph seafoodPara           = section2.Paragraphs["SeafoodTable"];
            Table     seafoodTable          = (Table)seafoodPara;
            Row       row1SeafoodTable      = seafoodTable.Rows[0];
            Cell      row1Cell2SeafoodTable = row1SeafoodTable.Cells[1];
            Image     seafoodImage          = (Image)row1Cell2SeafoodTable.Paragraphs[0];

            seafoodImage.ImageInfo.File = path + "\\Seafood.jpg";

            Table seafoodTable1 = (Table)section2.Paragraphs["SeafoodTable1"];

            FillTable(seafoodTable1, GetProductsByCateGoryID(8));

            return(pdf);
        }
        public Workbook CreateProductsByCategory()
        {
            productsList = productDao.GetAll();
            CategoryList = categoryDao.GetAll();

            List <ProductCategory> productCatList = (from product in productsList
                                                     join category in CategoryList on product.CategoryID equals category.CategoryID
                                                     orderby category.CategoryName, product.ProductName
                                                     select new ProductCategory
            {
                CategoryName = category.CategoryName,
                ProductName = product.ProductName,
                UnitsInStock = product.UnitsInStock
            }).ToList <ProductCategory>();


            //Open a template file
            string   designerFile = MapPath("~/App_Data/xls/Northwind.xls");
            Workbook workbook     = new Workbook(designerFile);

            DataTable dataTable1 = ConvertToDataTable(productCatList);

            //Get a worksheet
            Worksheet sheet = workbook.Worksheets["Sheet7"];

            //Name it
            sheet.Name = "Products By Category";
            //Get the cells
            Aspose.Cells.Cells cells = sheet.Cells;
            //Get the sheet vertical page breaks
            VerticalPageBreakCollection vPageBreaks = sheet.VerticalPageBreaks;

            //Set row heights
            cells.SetRowHeight(4, 20.25);
            cells.SetRowHeight(5, 18.75);
            ushort currentRow    = 4;
            byte   currentColumn = 0;

            string lastCategory = "";
            string thisCategory, nextCategory;

            int productsCount = 0;

            SetProductsByCategoryStyles(workbook);

            //Fill cells by inputing the values and apply styles to the data
            for (int i = 0; i < dataTable1.Rows.Count; i++)
            {
                thisCategory = (string)dataTable1.Rows[i]["CategoryName"];
                if (thisCategory != lastCategory)
                {
                    currentRow = 4;
                    if (i != 0)
                    {
                        currentColumn += 4;
                    }
                    CreateProductsByCategoryHeader(workbook, cells, currentRow, currentColumn, thisCategory);
                    lastCategory = thisCategory;
                    currentRow  += 2;
                }
                cells[currentRow, currentColumn].PutValue((string)dataTable1.Rows[i]["ProductName"]);
                cells[currentRow, (byte)(currentColumn + 1)].PutValue((short)dataTable1.Rows[i]["UnitsInStock"]);

                if (i != dataTable1.Rows.Count - 1)
                {
                    nextCategory = (string)dataTable1.Rows[i + 1]["CategoryName"];
                    if (thisCategory != nextCategory)
                    {
                        Aspose.Cells.Style style = workbook.Styles["ProductsCount"];
                        cells[currentRow + 1, currentColumn].PutValue("Number of Products:");
                        cells[currentRow + 1, currentColumn].SetStyle(style);

                        style = workbook.Styles["CountNumber"];
                        cells[currentRow + 1, (byte)(currentColumn + 1)].PutValue(productsCount + 1);
                        cells[currentRow + 1, (byte)(currentColumn + 1)].SetStyle(style);
                        currentRow++;
                        productsCount = 0;
                        vPageBreaks.Add(0, currentColumn + 1);
                    }
                    else
                    {
                        productsCount++;
                    }
                }
                else
                {
                    Aspose.Cells.Style style = workbook.Styles["ProductsCount"];
                    cells[currentRow + 1, currentColumn].PutValue("Number of Products:");
                    cells[currentRow + 1, currentColumn].SetStyle(style);

                    style = workbook.Styles["CountNumber"];
                    cells[currentRow + 1, (byte)(currentColumn + 1)].PutValue(productsCount + 1);
                    cells[currentRow + 1, (byte)(currentColumn + 1)].SetStyle(style);
                }
                currentRow++;
            }

            //Remove the unnecessary worksheets in the workbook
            for (int i = 0; i < workbook.Worksheets.Count; i++)
            {
                sheet = workbook.Worksheets[i];
                if (sheet.Name != "Products By Category")
                {
                    workbook.Worksheets.RemoveAt(i);
                    i--;
                }
            }
            //Get the generated workbook
            return(workbook);
        }
Exemple #3
0
 public List <Category> GetAll()
 {
     return(_categoryDao.GetAll());
 }
        public Aspose.Pdf.Generator.Pdf GetProductsByCategory()
        {
            IList <Product>  productsList = productDao.GetAll();
            IList <Category> CategoryList = categoryDao.GetAll();

            Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
            pdf.IsTruetypeFontMapCached = false;

            // If you have purchased a license,
            // Set license like this:
            // string licenseFile = MapPath("License") + "\\Aspose.Pdf.lic";
            // Aspose.Pdf.License lic = new Aspose.Pdf.License();
            // lic.SetLicense(licenseFile);

            string xmlFile = Server.MapPath("~/App_Data/xml/ProductsByCategory.xml");

            pdf.BindXML(xmlFile, null);

            Section section = pdf.Sections["section1"];

            Aspose.Pdf.Generator.Table table1 = new Aspose.Pdf.Generator.Table(section);
            section.Paragraphs.Add(table1);
            table1.ColumnWidths                 = "314 314 314";
            table1.Border                       = new BorderInfo((int)BorderSide.Top, 4, new Aspose.Pdf.Generator.Color(204));
            table1.IsRowBroken                  = false;
            table1.DefaultCellPadding.Top       = table1.DefaultCellPadding.Bottom = 15;
            table1.DefaultCellTextInfo.FontSize = 14;
            table1.Margin.Top                   = 10;

            int  j;
            Row  curRow  = null;
            Cell curCell = null;

            Aspose.Pdf.Generator.Table curSubTab = null;
            string[] names = new string[]
            { "Catagory: Beverages", "Catagory: Condiments", "Catagory: Confections",
              "Catagory: Dairy Products", "Catagory: Grains/Cereals", "Catagory: Meat/Poultry",
              "Catagory: Produce", "Catagory: Seafood" };

            for (j = 1; j <= 8; j++)
            {
                if (j == 1 || j == 4 || j == 7)
                {
                    curRow = table1.Rows.Add();
                }
                curCell   = curRow.Cells.Add();
                curSubTab = new Aspose.Pdf.Generator.Table(curCell);
                curSubTab.DefaultCellPadding.Top = curSubTab.DefaultCellPadding.Bottom = 3;
                curCell.Paragraphs.Add(curSubTab);
                curSubTab.ColumnWidths = "214 90";

                Row row0 = curSubTab.Rows.Add();
                Aspose.Pdf.Generator.TextInfo tf1 = new Aspose.Pdf.Generator.TextInfo();
                tf1.FontSize = 16;
                tf1.FontName = "Times-Bold";

                row0.Cells.Add(names[j - 1], tf1);

                IList <Product> filteredProductsList = (from productsTable in productsList
                                                        where (productsTable.Discontinued == false) && (productsTable.CategoryID == j)
                                                        orderby productsTable.ProductName
                                                        select productsTable).ToList <Product>();

                DataTable dataTable1 = ConvertToDataTable(filteredProductsList);

                curSubTab.ImportDataTable(dataTable1, true, 1, 0);

                curSubTab.Rows[1].Border = new BorderInfo((int)(BorderSide.Top | BorderSide.Bottom), 4, new Aspose.Pdf.Generator.Color(204));

                Row lastRow = curSubTab.Rows[curSubTab.Rows.Count - 1];
                foreach (Cell cCell in lastRow.Cells)
                {
                    cCell.Padding.Bottom = 20;
                }

                lastRow = curSubTab.Rows.Add();
                lastRow.Cells.Add("number of products:");
                lastRow.Cells.Add(dataTable1.Rows.Count.ToString());
                lastRow.Border = new BorderInfo((int)BorderSide.Top, new Aspose.Pdf.Generator.Color(204));
            }

            curRow.Cells.Add();
            return(pdf);
        }
Exemple #5
0
 public IDataResult <List <Category> > GetAll()
 {
     return(new SuccessDataResult <List <Category> >(_categoryDao.GetAll()));;
 }
        public Workbook CreateCatalog()
        {
            //Open a template file
            string   designerFile = MapPath("~/App_Data/xls/Northwind.xls");
            Workbook workbook     = new Workbook(designerFile);

            productsList = productDao.GetAll();
            CategoryList = categoryDao.GetAll();

            //Create a new datatable
            DataTable dataTable2 = new DataTable();
            //Get a worksheet
            Worksheet sheet = workbook.Worksheets["Sheet2"];

            //Name the sheet
            sheet.Name = "Catalog";
            //Get the worksheet cells
            Aspose.Cells.Cells cells = sheet.Cells;

            int currentRow = 55;

            //Add LightGray color to color palette
            workbook.ChangePalette(Color.LightGray, 55);
            //Get the workbook's styles collection
            StyleCollection styles = workbook.Styles;
            //Set CategoryName style with formatting attributes
            int   styleIndex        = styles.Add();
            Style styleCategoryName = styles[styleIndex];

            styleCategoryName.Font.Size   = 14;
            styleCategoryName.Font.Color  = Color.Blue;
            styleCategoryName.Font.IsBold = true;
            styleCategoryName.Font.Name   = "Times New Roman";

            //Set Description style with formatting attributes
            styleIndex = styles.Add();
            Style styleDescription = styles[styleIndex];

            styleDescription.Font.Name     = "Times New Roman";
            styleDescription.Font.Color    = Color.Blue;
            styleDescription.Font.IsItalic = true;

            //Set ProductName style with formatting attributes
            styleIndex = styles.Add();
            Style styleProductName = styles[styleIndex];

            styleProductName.Font.IsBold = true;

            //Set Title style with formatting attributes
            styleIndex = styles.Add();
            Style styleTitle = styles[styleIndex];

            styleTitle.Font.IsBold     = true;
            styleTitle.Font.IsItalic   = true;
            styleTitle.ForegroundColor = Color.LightGray;

            styleIndex = styles.Add();
            Style styleNumber = styles[styleIndex];

            styleNumber.Font.Name = "Times New Roman";
            styleNumber.Number    = 8;

            //Create the styleflag struct
            StyleFlag styleflag = new StyleFlag();

            styleflag.All = true;
            //Get the horizontal page breaks collection
            HorizontalPageBreakCollection hPageBreaks = sheet.HorizontalPageBreaks;

            DataTable dataTable1 = ConvertCategoriesToDataTable(CategoryList);

            for (int i = 0; i < dataTable1.Rows.Count; i++)
            {
                currentRow += 2;
                cells.SetRowHeight(currentRow, 20);
                cells[currentRow, 1].SetStyle(styleCategoryName);
                DataRow categoriesRow = dataTable1.Rows[i];

                //Write CategoryName
                cells[currentRow, 1].PutValue((string)categoriesRow["CategoryName"]);

                //Write Description
                currentRow++;
                cells[currentRow, 1].PutValue((string)categoriesRow["Description"]);
                cells[currentRow, 1].SetStyle(styleDescription);

                dataTable2.Clear();
                dataTable2 = GetProductsByCateGoryID(Convert.ToInt32(categoriesRow["CategoryID"].ToString()));

                currentRow += 2;
                //Import the datatable to the sheet
                cells.ImportDataTable(dataTable2, true, currentRow, 1);
                //Create a range
                Range range = cells.CreateRange(currentRow, 1, 1, 4);
                //Apply style to the range
                range.ApplyStyle(styleTitle, styleflag);
                //Create a range
                range = cells.CreateRange(currentRow + 1, 1, dataTable2.Rows.Count, 1);
                //Apply style to the range
                range.ApplyStyle(styleProductName, styleflag);
                //Create a range
                range = cells.CreateRange(currentRow + 1, 4, dataTable2.Rows.Count, 1);
                //Apply style to the range
                range.ApplyStyle(styleNumber, styleflag);

                currentRow += dataTable2.Rows.Count;
                //Apply horizontal page breaks
                hPageBreaks.Add(currentRow, 0);
            }

            //Remove the unnecessary worksheets in the workbook
            for (int i = 0; i < workbook.Worksheets.Count; i++)
            {
                sheet = workbook.Worksheets[i];
                if (sheet.Name != "Catalog")
                {
                    workbook.Worksheets.RemoveAt(i);
                    i--;
                }
            }
            //Return the generated workbook
            return(workbook);
        }
 public IEnumerable <Category> GetAll()
 {
     return(_categoryDao.GetAll());
 }