Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            Report      report    = new Report();
            RtfDocument rtf       = report.GetRtf();
            RtfWriter   rtfWriter = new RtfWriter();
            DateTime    start;
            TimeSpan    time;

            try
            {
                using (TextWriter writer = new StreamWriter("test.rtf"))
                {
                    start = DateTime.Now;

                    rtfWriter.Write(writer, rtf);

                    time = DateTime.Now - start;

                    label1.Text = String.Format("{0}.{1}", time.Seconds, time.Milliseconds.ToString().PadLeft(3, '0'));
                }
            }
            catch (IOException)
            {
                label1.Text = "I/O Exception";
            }

            button1.Enabled = true;
        }
        public void CloseFile()
        {
            CloseCurrentParagraph();
            RtfWriter  rtfWriter = new RtfWriter();
            TextWriter writer    = new StreamWriter(m_strFilepath);

            rtfWriter.Write(writer, m_doc);
            writer.Close();
        }
        /// <summary>
        /// Gets the name of the exported file.
        /// </summary>
        /// <param name="appealLetter">The appeal letter container.</param>
        /// <param name="reportVirtualPath">The report virtual path.</param>
        /// <param name="fileBaseName">Name of the file base.</param>
        /// <returns></returns>
        public static string[] GetExportedFileName(AppealLetter appealLetter, string reportVirtualPath, string fileBaseName)
        {
            string fileName;

            if (appealLetter.ReportThreshold == Constants.ReportThreshold) // Exceeded threshold limit
            {
                fileName = Convert.ToString(Constants.ReportThreshold);
            }
            else if (appealLetter.AppealLetterClaims.Count == 0) //No Records Found
            {
                fileName = Constants.EmptyReportResult;
            }
            else
            {
                _appealLetter = appealLetter;
                string dateTimeStamp = DateTime.Now.ToString(Constants.DateTimeExtendedFormat);
                fileName  = string.Format("{0}{1}.{2}", fileBaseName, dateTimeStamp, Constants.AppealLetterFileExtension);
                _filePath = Path.Combine(reportVirtualPath, fileName);
                //Build rtf document object
                RtfDocument rtfDocument = GetRtfDocument();

                //Get rtf content String
                RtfWriter rtfWriter          = new RtfWriter();
                string    templateRtfContent = rtfWriter.GetRtfContent(rtfDocument);
                //loop through each claim data and replace claim text and merge rtf content
                string finalRtfContent = _appealLetter.AppealLetterClaims.Select(
                    appealLetterClaim => ReplaceClaimData(templateRtfContent, appealLetterClaim))
                                         .Aggregate(string.Empty,
                                                    (current, rtfClaimText) =>
                                                    !string.IsNullOrEmpty(current)
                                ? MergeRtfContent(current, rtfClaimText)
                                : rtfClaimText);

                //Write rtf content into file
                using (TextWriter writer = new StreamWriter(_filePath))
                {
                    rtfWriter.Write(writer, finalRtfContent);
                }
                if (appealLetter.IsPreview)
                {
                    return(new[] { appealLetter.LetterTemplaterText, fileName });
                }
            }
            return(new[] { fileName });
        }
        private void createGlobalRtfReport()
        {
            int         maxPagesInReport  = AppSettings.Settings.Rtf.RtfNumberOfPagesInReport;
            RtfDocument globalDoc         = null;
            string      globalDocFilename = "";

            for (int idx = 0; idx < m_allDocuments.Count; idx++)
            {
                if ((idx % maxPagesInReport) == 0)
                {
                    // close the current document
                    if (globalDoc != null)
                    {
                        globalDocFilename = m_reportFolder + String.Format("{0}{1}-{2}.rtf", AppSettings.Settings.Rtf.RtfReportBaseFilename, idx - maxPagesInReport, idx - 1);
                        RtfWriter  rtfWriter = new RtfWriter();
                        TextWriter writer    = new StreamWriter(globalDocFilename);
                        rtfWriter.Write(writer, globalDoc);
                        writer.Close();
                    }

                    // start new document
                    globalDoc = new RtfDocument();
                }

                RtfDocument currDoc = m_allDocuments[idx];
                foreach (RtfDocumentContentBase item in currDoc.Contents)
                {
                    globalDoc.Contents.Add(item);
                }
            }

            // close the last file
            if (globalDoc != null)
            {
                int lastCount = (m_allDocuments.Count / maxPagesInReport) * maxPagesInReport;
                globalDocFilename = m_reportFolder + String.Format("{0}{1}-{2}.rtf", AppSettings.Settings.Rtf.RtfReportBaseFilename, lastCount, m_allDocuments.Count);
                RtfWriter  rtfWriter = new RtfWriter();
                TextWriter writer    = new StreamWriter(globalDocFilename);
                rtfWriter.Write(writer, globalDoc);
                writer.Close();
            }
        }
Esempio n. 5
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());
        }