Пример #1
0
        public void GetPageRtf(int departmentId)
        {
            HttpRequest request = _context.Request;
            Filter      filters = new Filter();

            filters.Rules = new List <Rule>();
            string[] fields =
            {
                "CreationDate",
                "CreationDateStart",
                "CreationDateEnd",
                "Number",
                "ExternalNumber",
                "DocumentCodeID",
                "Content",
                "OrganizationName",
                "InnerNumber",
                "Controlled",
                "EndDateFrom",
                "EndDateTo",
                "IsInput",
                "IsDepartmentOwner",
                "ControlledInner",
                "InnerEndDateFrom",
                "InnerEndDateTo",
                "LableID",
                "DocStatusID"
            };

            foreach (var f in fields)
            {
                string data = request[f];
                if (!String.IsNullOrWhiteSpace(data))
                {
                    filters.AddRule(new Rule {
                        Field = f, Data = data, Op = "cn"
                    });
                }
            }
            PageSettings gridSettings = new PageSettings {
                IsSearch   = bool.Parse(request["_search"] ?? "false"),
                PageIndex  = int.Parse(request["page"] ?? "1"),
                PageSize   = int.Parse(request["rows"] ?? "50"),
                SortColumn = request["sidx"] ?? "",
                SortOrder  = request["sord"] ?? "asc",
                Where      = filters
            };

            DataTable     dtPage        = AdminDocumets.GetPage(gridSettings, UserId, departmentId);
            JqGridResults jqGridResults = AdminDocumets.BuildJqGridResults(dtPage, gridSettings);

            _context.Response.Clear();


            RtfDocument rtf = new RtfDocument();

            rtf.FontTable.Add(new RtfFont("Times New Roman"));

            RtfFormattedParagraph header = new RtfFormattedParagraph(new RtfParagraphFormatting(14, RtfTextAlign.Center));

            header.AppendText("");
            header.AppendParagraph();

            RtfTable tbl = new RtfTable(RtfTableAlign.Center, 8, dtPage.Rows.Count + 1);

            tbl.Width                       = TwipConverter.ToTwip(489, MetricUnit.Point);
            tbl.DefaultCellStyle            = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Center));
            tbl.Columns[0].Width            = TwipConverter.ToTwip(14, MetricUnit.Point);
            tbl.Columns[1].Width            = TwipConverter.ToTwip(60, MetricUnit.Point);
            tbl.Columns[2].Width            = TwipConverter.ToTwip(30, MetricUnit.Point);
            tbl.Columns[3].Width            = TwipConverter.ToTwip(30, MetricUnit.Point);
            tbl.Columns[4].Width            = TwipConverter.ToTwip(30, MetricUnit.Point);
            tbl.Columns[5].Width            = TwipConverter.ToTwip(70, MetricUnit.Point);
            tbl.Columns[5].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Left));
            tbl.Columns[6].Width            = TwipConverter.ToTwip(85, MetricUnit.Point);
            tbl.Columns[6].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Left));
            tbl.Columns[7].Width            = TwipConverter.ToTwip(170, MetricUnit.Point);
            tbl.Columns[7].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(10, RtfTextAlign.Left));

            foreach (RtfTableRow row in tbl.Rows)
            {
                row.Height = TwipConverter.ToTwip(20, MetricUnit.Point);
            }
            tbl.Rows[0].Height = TwipConverter.ToTwip(30, MetricUnit.Point);
            //tbl.Rows[0].Cells[5].Formatting = new RtfParagraphFormatting(12, RtfTextAlign.Center);

            tbl[0, 0].AppendText("");
            tbl[1, 0].AppendText("Дата створення");
            tbl[2, 0].AppendText("Шифр");
            tbl[3, 0].AppendText("№");
            tbl[4, 0].AppendText("№ внутрішній");
            tbl[5, 0].AppendText("№ в організації");
            tbl[6, 0].AppendText("Організація");
            tbl[7, 0].AppendText("Зміст");
            int numRow = 1;

            foreach (JqGridRow dr in jqGridResults.rows)
            {
                tbl[0, numRow].AppendText(numRow.ToString());
                tbl[1, numRow].AppendText(dr.cell[2]);
                tbl[2, numRow].AppendText(dr.cell[16]);
                tbl[3, numRow].AppendText(dr.cell[3]);
                tbl[4, numRow].AppendText(dr.cell[23]);
                tbl[5, numRow].AppendText(dr.cell[4]);
                tbl[6, numRow].AppendText(dr.cell[19]);
                tbl[7, numRow].AppendText(dr.cell[5]);

                numRow++;
            }

            RtfFormattedParagraph footer = new RtfFormattedParagraph(new RtfParagraphFormatting(14, RtfTextAlign.Left));

            footer.AppendParagraph();
            footer.AppendText(String.Format("Список станом на "));
            footer.AppendParagraph();
            footer.AppendText(String.Format("Всього документів: {0}", dtPage.Rows.Count));
            footer.AppendParagraph();
            footer.AppendText("Виконав ______________________");

            rtf.Contents.AddRange(new RtfDocumentContentBase[] { header, tbl, footer });


            RtfWriter     rtfWriter = new RtfWriter();
            StringBuilder sb        = new StringBuilder();

            using (TextWriter writer = new StringWriter(sb))
            {
                rtfWriter.Write(writer, rtf);
            }

            string fileName = String.Format("docTempates_({0}).rtf", DateTime.Now.ToString("yyyy.MM.dd"));

            _context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            _context.Response.ContentType = "application/rtf";
            _context.Response.Write(sb.ToString());
        }