public FileStreamResult CongNoNXB(DateTime startDate, DateTime endDate)
        {
            List<Sach> DMSach = SachManager.getAll()
                                    .Where(s => s.tongSoLuongNXBNoTheoThang(
                                        ((DateTime)startDate).Month,
                                        ((DateTime)startDate).Year,
                                        ((DateTime)endDate).Month,
                                        ((DateTime)endDate).Year) > 0 &&
                                        s.tongTienNXBNoTheoThang(
                                        ((DateTime)startDate).Month,
                                        ((DateTime)startDate).Year,
                                        ((DateTime)endDate).Month,
                                        ((DateTime)endDate).Year) > 0).ToList();
            var printer = new PrintHelper();
            printer.FileName = "report.pdf";
            printer.FolderPath = "D://";
            printer.Title = "Thống kê công nợ với Nhà xuất bản";
            var info = new MemoryStream(printer.printCongNoNXB(DMSach, startDate, endDate));

            return new FileStreamResult(info, "application/pdf");
        }
        public FileStreamResult DoanhThu(DateTime startDate, DateTime endDate)
        {
            List<DaiLy> DMDaily = DaiLyManager.getAllAlive()
                                    .Where(dl => dl.tinhTongTienThanhToanTheoThang(
                                        ((DateTime)startDate).Month,
                                        ((DateTime)startDate).Year,
                                        ((DateTime)endDate).Month,
                                        ((DateTime)endDate).Year) > 0).ToList();
            List<NhaXuatBan> DMNXB = NhaXuatBanManager.getAllAlive()
                                    .Where(nxb => nxb.tinhTongTienThanhToanTheoThang(
                                        ((DateTime)startDate).Month,
                                        ((DateTime)startDate).Year,
                                        ((DateTime)endDate).Month,
                                        ((DateTime)endDate).Year) > 0).ToList();
            var printer = new PrintHelper();
            printer.FileName = "report.pdf";
            printer.FolderPath = "D://";
            printer.Title = "Thống kê doanh thu";
            var info = new MemoryStream(printer.printDoanhThu(DMDaily, DMNXB,startDate,endDate));

            return new FileStreamResult(info, "application/pdf");
        }
        private void btIn_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn xuất tạo file báo cáo", "Thông báo", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                var printer = new PrintHelper();
                string x = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "";

                string tenfile = x + "ReportDoanhThu.pdf";
                printer.FileName = tenfile;
                printer.FolderPath = "D://Report";
                printer.Title = "Báo cáo Doanh Thu";
                var startDate = new DateTime(_startYear, _startMonth, 1);
                var endDate = new DateTime(_endYear, _endMonth, 1);
                endDate.AddMonths(1).AddDays(-1);
                printer.printDoanhThu(_DSDaiLy,_DSNXB, startDate, endDate);
                MessageBox.Show("Đã tạo file thành công , Tên file là : " + tenfile);
                //var redListTextFont = FontFactory.RegisterDirectory(Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts");
                //var _bold = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                //var _bold1 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                //PdfPTable pdfTable = new PdfPTable(gdvDaiLy.ColumnCount);
                //pdfTable.DefaultCell.Padding = 3;
                //pdfTable.WidthPercentage = 30;
                //pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
                //pdfTable.DefaultCell.BorderWidth = 1;
                //pdfTable.TotalWidth = 350f;
                //pdfTable.LockedWidth = true;
                //float[] widths = new float[] { 50f, 100f, 100f, 100f };
                //pdfTable.SetWidths(widths);

                //PdfPTable pdfTable1 = new PdfPTable(gdvNXB.ColumnCount);
                //pdfTable1.DefaultCell.Padding = 3;
                //pdfTable1.WidthPercentage = 30;
                //pdfTable1.HorizontalAlignment = Element.ALIGN_CENTER;
                //pdfTable1.DefaultCell.BorderWidth = 1;
                //pdfTable1.TotalWidth = 350f;
                //pdfTable1.LockedWidth = true;
                //pdfTable1.SetWidths(widths);

                ////Adding Header row
                //foreach (DataGridViewColumn column in gdvDaiLy.Columns)
                //{
                //    PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, _bold));
                //    cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);

                //    pdfTable.AddCell(cell);
                //}
                //foreach (DataGridViewColumn column in gdvNXB.Columns)
                //{
                //    PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, _bold));
                //    cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);

                //    pdfTable1.AddCell(cell);
                //}

                ////Adding DataRow
                //foreach (DataGridViewRow row in gdvDaiLy.Rows)
                //{
                //    foreach (DataGridViewCell cell in row.Cells)
                //    {
                //        if (!String.IsNullOrEmpty(Convert.ToString(cell.Value)))
                //            pdfTable.AddCell(new Phrase(cell.Value.ToString(), _bold1));
                //    }
                //}
                //foreach (DataGridViewRow row in gdvNXB.Rows)
                //{
                //    foreach (DataGridViewCell cell in row.Cells)
                //    {
                //        if (!String.IsNullOrEmpty(Convert.ToString(cell.Value)))
                //            pdfTable1.AddCell(new Phrase(cell.Value.ToString(), _bold1));
                //    }
                //}

                ////Exporting to PDF
                //string folderPath = @"C:\Users\huy\Desktop\Report\";
                //string x = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "";

                //string tenfile = x + "ReportThongKeDoanhThu.pdf";
                //if (!Directory.Exists(folderPath))
                //{
                //    Directory.CreateDirectory(folderPath);
                //}
                //using (FileStream stream = new FileStream(folderPath + tenfile, FileMode.Create))
                //{

                //    Document pdfDoc = new Document(PageSize.A3, 100f, 100f, 100f, 0);
                //    PdfWriter.GetInstance(pdfDoc, stream);
                //    pdfDoc.Open();
                //    var FontColour = new BaseColor(255, 0, 0);
                //    var _bold2 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 20f, iTextSharp.text.Font.NORMAL, BaseColor.BLUE);
                //    Paragraph docTitle = new Paragraph("Thống kê doanh thu " + "\n", _bold2);
                //    Paragraph docTitle1 = new Paragraph("Từ tháng        : " + cmbStartMonth.Text + " Năm  " + cmbStartYear.Text + "\n", _bold2);
                //    Paragraph docTitle2 = new Paragraph("đến tháng       : " + cmbEndMonth.Text + " Năm  " + cmbEndYear.Text + "\n", _bold2);
                //    Paragraph docTitle3 = new Paragraph("Tổng thu        : " + lbTongThu.Text + "\n", _bold2);
                //    Paragraph docTitle4 = new Paragraph("Tổng chi        : " + lbTongChi.Text + "\n", _bold2);
                //    Paragraph docTitle5 = new Paragraph("Tổng lợi nhuận  : " + lbLoiNhuan.Text + "\n", _bold2);
                //    docTitle.Alignment = Element.ALIGN_LEFT;
                //    docTitle1.Alignment = Element.ALIGN_LEFT;
                //    docTitle2.Alignment = Element.ALIGN_LEFT;
                //    docTitle3.Alignment = Element.ALIGN_LEFT;
                //    docTitle4.Alignment = Element.ALIGN_LEFT;
                //    docTitle5.Alignment = Element.ALIGN_LEFT;
                //    pdfDoc.Add(docTitle);
                //    pdfDoc.Add(docTitle1);
                //    pdfDoc.Add(docTitle2);
                //    pdfDoc.Add(docTitle3);
                //    pdfDoc.Add(docTitle4);
                //    pdfDoc.Add(docTitle5);
                //    pdfDoc.Add(new Paragraph("\n"));
                //    pdfDoc.Add(new Paragraph("\n"));
                //    Paragraph docTitle6 = new Paragraph("Nguồn thu : " + "\n", _bold2);
                //    docTitle6.Alignment = Element.ALIGN_CENTER;
                //    pdfDoc.Add(docTitle6);
                //    pdfDoc.Add(new Paragraph("\n"));

                //    pdfDoc.Add(pdfTable);

                //    Paragraph docTitle7 = new Paragraph("Nguồn chi : " + "\n", _bold2);
                //    docTitle7.Alignment = Element.ALIGN_CENTER;
                //    pdfDoc.Add(docTitle7);
                //    pdfDoc.Add(new Paragraph("\n"));

                //    pdfDoc.Add(pdfTable1);

                //    pdfDoc.Close();
                //    stream.Close();

                //    MessageBox.Show("Đã tạo file thành công , Tên file là : " + tenfile);
                //}
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }
        public FileStreamResult TonKho(DateTime date)
        {
            var models = TheKhoManager.getAllByDate(date);
            var printer = new PrintHelper();
            printer.FileName = "report.pdf";
            printer.FolderPath = "D://";
            printer.Title = "Thống kê tồn kho";
            var info = new MemoryStream(printer.printTonKho(models, date));

            return new FileStreamResult(info, "application/pdf");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Bạn có muốn xuất tạo file báo cáo", "Thông báo", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                var printer = new PrintHelper();
                string x = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + "";

                string tenfile = x + "ReportTonKho.pdf";
                printer.FileName = tenfile;
                printer.FolderPath = "D://Report";
                printer.Title = "Báo cáo tồn kho";
                printer.printTonKho(_DMTheKho, dtpNgayGhi.Value);
                MessageBox.Show("Đã tạo file thành công , Tên file là : " + tenfile);
                //var redListTextFont = FontFactory.RegisterDirectory(Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts");
                //var _bold = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f,iTextSharp.text.Font.BOLD, BaseColor.BLACK);
                //var _bold1 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                //PdfPTable pdfTable = new PdfPTable(gdvTheKho.ColumnCount);
                //pdfTable.DefaultCell.Padding = 3;
                //pdfTable.WidthPercentage = 30;
                //pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
                //pdfTable.DefaultCell.BorderWidth = 1;
                //pdfTable.TotalWidth = 350f;
                //pdfTable.LockedWidth = true;
                //float[] widths = new float[] { 50f, 100f, 100f, 100f };
                //pdfTable.SetWidths(widths);

                ////Adding Header row
                //foreach (DataGridViewColumn column in gdvTheKho.Columns)
                //{
                //    PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText,_bold));
                //    cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);

                //    pdfTable.AddCell(cell);
                //}

                ////Adding DataRow
                //foreach (DataGridViewRow row in gdvTheKho.Rows)
                //{
                //    foreach (DataGridViewCell cell in row.Cells)
                //    {
                //        if (!String.IsNullOrEmpty(Convert.ToString(cell.Value)))
                //            pdfTable.AddCell(new Phrase(cell.Value.ToString(),_bold1));
                //    }
                //}

                ////Exporting to PDF
                //string folderPath = @"D:\Report\";
                //string x = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-"+ DateTime.Now.Hour + "-"+ DateTime.Now.Minute +"-"+ DateTime.Now.Second + "";

                //string tenfile = x + "ReportTonKho.pdf";
                //if (!Directory.Exists(folderPath))
                //{
                //    Directory.CreateDirectory(folderPath);
                //}
                //using (FileStream stream = new FileStream(folderPath + tenfile, FileMode.Create))
                //{
                //    Document pdfDoc = new Document(PageSize.A3, 100f, 100f, 100f, 0);
                //    PdfWriter.GetInstance(pdfDoc, stream);
                //    pdfDoc.Open();
                //    var FontColour = new BaseColor(255, 0, 0);
                //    var _bold2 = FontFactory.GetFont("Times New Roman", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 20f, iTextSharp.text.Font.NORMAL, BaseColor.BLUE);
                //    Paragraph docTitle = new Paragraph("Thống kê tồn kho ngày : " + dtpNgayGhi.Value.Day + "-" + dtpNgayGhi.Value.Month + "-" + dtpNgayGhi.Value.Year + "\n", _bold2);
                //    Paragraph docTitle1 = new Paragraph("Tổng số lượng sách   : " + lbTongLuongSach.Text + "\n", _bold2);
                //    docTitle.Alignment = Element.ALIGN_LEFT;
                //    docTitle1.Alignment = Element.ALIGN_LEFT;
                //    pdfDoc.Add(docTitle);
                //    pdfDoc.Add(docTitle1);
                //    pdfDoc.Add(new Paragraph("\n"));
                //    pdfDoc.Add(new Paragraph("\n"));
                //    pdfDoc.Add(pdfTable);
                //    pdfDoc.Close();
                //    stream.Close();

                //    MessageBox.Show("Đã tạo file thành công , Tên file là : " + tenfile);
                //}
            }
            else if (dialogResult == DialogResult.No)
            {
                return;
            }
        }