public byte[] printCongNoDaiLy(List <Sach> DMSach, DateTime startDate, DateTime endDate)
        {
            try
            {
                var       filePath = Path.Combine(FolderPath, FileName);
                PdfWriter writer   = PdfWriter.GetInstance(_doc, new FileStream(filePath, FileMode.Create));
                //Create table here for write database data

                var soLuongNo   = (decimal)DMSach.Sum(s => s.TongSoLuongDaiLyNoTheoThang);
                var tongTienNo  = (decimal)DMSach.Sum(s => s.TongTienDaiLyNoTheoTang);
                var HeaderTable = new PdfPTable(2);
                HeaderTable.HorizontalAlignment = 0;
                HeaderTable.SpacingBefore       = 20;
                HeaderTable.SpacingAfter        = 10;
                HeaderTable.SetWidths(new int[] { 2, 6 });

                HeaderTable.AddCell(createNoBorderCell("Ngày in", 2, 1, 1));
                HeaderTable.AddCell(createNoBorderCell(": " + DataDisplayHelper.dislayShortDate(DateTime.Now), 0, 1, 1));

                //Thông tin thống kê
                var InfoTable = new PdfPTable(4);
                InfoTable.HorizontalAlignment = 0;
                InfoTable.SpacingAfter        = 10;
                InfoTable.DefaultCell.Border  = 0;
                InfoTable.TotalWidth          = 15;
                InfoTable.SetWidths(new int[] { 2, 2, 2, 2 });
                InfoTable.WidthPercentage    = 100;
                InfoTable.DefaultCell.Border = Rectangle.BOX;
                InfoTable.AddCell(createHeaderCell("Xem từ tháng", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.dislayMonth(startDate), 1, 1, 1));
                InfoTable.AddCell(createHeaderCell("Đến tháng", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.dislayMonth(endDate), 1, 1, 1));
                InfoTable.AddCell(createHeaderCell("Số lượng nợ", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.displayNumber(soLuongNo), 0, 3, 1));
                InfoTable.AddCell(createHeaderCell("Tổng tiền", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.displayMoney(tongTienNo), 0, 3, 1));

                //Thống kê nguồn thu
                var DetailTable = new PdfPTable(8);
                DetailTable.HorizontalAlignment = 1;
                DetailTable.SpacingAfter        = 10;
                DetailTable.WidthPercentage     = 100;
                DetailTable.SetWidths(new int[] { 1, 6, 4, 3, 1, 3, 2, 3 });
                DetailTable.AddCell(createTableTitleCell("Danh mục sách Đại lý nợ", 0, 8, 1));
                DetailTable.AddCell(createNoBorderCell(" ", 1, 8, 1));
                foreach (var s in DMSach)
                {
                    DetailTable.AddCell(createBottomBorderCell(s.MaSoSach.ToString(), 1, 1, 1, BaseColor.LIGHT_GRAY));
                    DetailTable.AddCell(createBottomBorderCell(s.TenSach, 1, 1, 1, BaseColor.LIGHT_GRAY));
                    DetailTable.AddCell(createBottomBorderCell(" ", 1, 3, 1, BaseColor.LIGHT_GRAY));
                    DetailTable.AddCell(createBottomBorderCell("Tổng cộng", 1, 1, 1, BaseColor.LIGHT_GRAY));
                    DetailTable.AddCell(createBottomBorderCell(DataDisplayHelper.displayNumber((decimal)s.TongSoLuongDaiLyNoTheoThang), 1, 1, 1, BaseColor.LIGHT_GRAY));
                    DetailTable.AddCell(createBottomBorderCell(DataDisplayHelper.displayMoney((decimal)s.TongTienDaiLyNoTheoTang), 1, 1, 1, BaseColor.LIGHT_GRAY));
                    var CongNo = s.getCongNoDaiLyTheoThang(startDate.Month, startDate.Year, endDate.Month, endDate.Year);
                    foreach (var p in CongNo)
                    {
                        DetailTable.AddCell(createNoBorderCell(" ", 1, 2, 1));
                        //DetailTable.AddCell(createNoBorderCell("Phiếu xuất số " + p.Maso, 1, 1, 1));
                        DetailTable.AddCell(createNoBorderCell("Tháng " + DataDisplayHelper.dislayMonth(p.Thang), 1, 2, 1));
                        DetailTable.AddCell(createNoBorderCell(" ", 1, 1, 1));
                        DetailTable.AddCell(createNoBorderCell(DataDisplayHelper.displayMoney(p.DonGia), 1, 1, 1));
                        DetailTable.AddCell(createNoBorderCell(p.SoLuong.ToString(), 1, 1, 1));
                        DetailTable.AddCell(createNoBorderCell(DataDisplayHelper.displayMoney(p.ThanhTien), 1, 1, 1));
                    }
                }

                _doc.Open();
                _doc.Add(_tilte);
                _doc.Add(HeaderTable);
                _doc.Add(InfoTable);
                _doc.Add(DetailTable);
                _doc.Close();

                return(File.ReadAllBytes(filePath));
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                _doc.Close();
            }
        }
        public byte[] printDoanhThu(List <DaiLy> DMDaiLy, List <NhaXuatBan> DMNXB, DateTime startDate, DateTime endDate)
        {
            try
            {
                var       filePath = Path.Combine(FolderPath, FileName);
                PdfWriter writer   = PdfWriter.GetInstance(_doc, new FileStream(filePath, FileMode.Create));
                //Create table here for write database data

                var tongTienThu = (decimal)DMDaiLy.Sum(dl => dl.TongTienThanhToanTheoThang);
                var tongTienChi = (decimal)DMNXB.Sum(s => s.TongTienThanhToanTheoThang);
                var HeaderTable = new PdfPTable(2);
                HeaderTable.HorizontalAlignment = 0;
                HeaderTable.SpacingBefore       = 20;
                HeaderTable.SpacingAfter        = 10;
                HeaderTable.SetWidths(new int[] { 2, 6 });

                HeaderTable.AddCell(createNoBorderCell("Ngày in", 2, 1, 1));
                HeaderTable.AddCell(createNoBorderCell(": " + DataDisplayHelper.dislayShortDate(DateTime.Now), 0, 1, 1));

                //Thông tin thống kê
                var InfoTable = new PdfPTable(4);
                InfoTable.HorizontalAlignment = 0;
                InfoTable.SpacingAfter        = 10;
                InfoTable.DefaultCell.Border  = 0;
                InfoTable.TotalWidth          = 15;
                InfoTable.SetWidths(new int[] { 2, 2, 2, 2 });
                InfoTable.WidthPercentage    = 100;
                InfoTable.DefaultCell.Border = Rectangle.BOX;
                InfoTable.AddCell(createHeaderCell("Xem từ tháng", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.dislayMonth(startDate), 1, 1, 1));
                InfoTable.AddCell(createHeaderCell("Đến tháng", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.dislayMonth(endDate), 1, 1, 1));
                InfoTable.AddCell(createHeaderCell("Tổng thu", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.displayMoney(tongTienThu), 0, 3, 1));
                InfoTable.AddCell(createHeaderCell("Tổng chi", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.displayMoney(tongTienChi), 0, 3, 1));
                InfoTable.AddCell(createHeaderCell("Lợi nhuận", 1, 1, 1));
                InfoTable.AddCell(createCell(DataDisplayHelper.displayMoney(tongTienThu - tongTienChi), 0, 3, 1));

                //Thống kê nguồn thu
                var DLDetailTable = new PdfPTable(4);
                DLDetailTable.HorizontalAlignment = 1;
                DLDetailTable.SpacingAfter        = 10;
                DLDetailTable.WidthPercentage     = 100;
                DLDetailTable.SetWidths(new int[] { 3, 4, 3, 3 });
                DLDetailTable.AddCell(createTableTitleCell("Nguồn thu", 0, 4, 1));
                DLDetailTable.AddCell(createNoBorderCell(" ", 1, 4, 1));
                DLDetailTable.AddCell(createHeaderCell(DaiLyManager.Properties.MaSoDaiLy, 1, 1, 1));
                DLDetailTable.AddCell(createHeaderCell(DaiLyManager.Properties.TenDaiLy, 1, 1, 1));
                DLDetailTable.AddCell(createHeaderCell(DaiLyManager.Properties.TongTienThanhToan, 1, 1, 1));
                DLDetailTable.AddCell(createHeaderCell(DaiLyManager.Properties.TongTienThanhToanTheoThang, 1, 1, 1));


                foreach (var s in DMDaiLy)
                {
                    DLDetailTable.AddCell(createCell(s.MaSoDaiLy.ToString(), 1, 1, 1));
                    DLDetailTable.AddCell(createCell(s.TenDaiLy, 0, 1, 1));
                    DLDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)s.TongTienThanhToan), 0, 1, 1));
                    DLDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)s.TongTienThanhToanTheoThang), 0, 1, 1));
                }
                DLDetailTable.AddCell(createHeaderCell("Tổng cộng", 2, 2, 1));
                DLDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)DMDaiLy.Sum(dl => dl.TongTienThanhToan)), 1, 1, 1));
                DLDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)DMDaiLy.Sum(dl => dl.TongTienThanhToanTheoThang)), 1, 1, 1));

                //Thông kê nguồn chi
                var NXBDetailTable = new PdfPTable(4);
                NXBDetailTable.HorizontalAlignment = 1;
                NXBDetailTable.SpacingAfter        = 10;
                NXBDetailTable.WidthPercentage     = 100;
                NXBDetailTable.SetWidths(new int[] { 3, 4, 3, 3 });
                NXBDetailTable.AddCell(createTableTitleCell("Nguồn chi", 0, 4, 1));
                NXBDetailTable.AddCell(createNoBorderCell(" ", 1, 4, 1));
                NXBDetailTable.AddCell(createHeaderCell(NhaXuatBanManager.Properties.MaSoNXB, 1, 1, 1));
                NXBDetailTable.AddCell(createHeaderCell(NhaXuatBanManager.Properties.TenNXB, 1, 1, 1));
                NXBDetailTable.AddCell(createHeaderCell(NhaXuatBanManager.Properties.TongTienThanhToan, 1, 1, 1));
                NXBDetailTable.AddCell(createHeaderCell(NhaXuatBanManager.Properties.TongTienThanhToanTheoThang, 1, 1, 1));


                foreach (var s in DMNXB)
                {
                    NXBDetailTable.AddCell(createCell(s.MaSoNXB.ToString(), 1, 1, 1));
                    NXBDetailTable.AddCell(createCell(s.TenNXB, 0, 1, 1));
                    NXBDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)s.TongTienThanhToan), 0, 1, 1));
                    NXBDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)s.TongTienThanhToanTheoThang), 0, 1, 1));
                }
                NXBDetailTable.AddCell(createHeaderCell("Tổng cộng", 2, 2, 1));
                NXBDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)DMNXB.Sum(dl => dl.TongTienThanhToan)), 1, 1, 1));
                NXBDetailTable.AddCell(createCell(DataDisplayHelper.displayMoney((decimal)DMNXB.Sum(dl => dl.TongTienThanhToanTheoThang)), 1, 1, 1));



                _doc.Open();
                _doc.Add(_tilte);
                _doc.Add(HeaderTable);
                _doc.Add(InfoTable);
                _doc.Add(DLDetailTable);
                _doc.Add(NXBDetailTable);
                _doc.Close();

                return(File.ReadAllBytes(filePath));
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                _doc.Close();
            }
        }