示例#1
0
        private void CreateRangePermissions()
        {
            // Create document ranges.
            DocumentRange rangeAdmin     = AppendDocument("Documents\\administrator.docx");
            DocumentRange rangeBody      = AppendDocument("Documents\\body.docx");
            DocumentRange rangeSignature = AppendDocument("Documents\\signature.docx");

            // Protect document ranges.
            #region #CreateRangePermissions
            RangePermissionCollection rangePermissions = richEdit.Document.BeginUpdateRangePermissions();

            RangePermission permission = rangePermissions.CreateRangePermission(rangeAdmin);
            permission.UserName = "******";
            permission.Group    = "Skywalkers";
            rangePermissions.Add(permission);

            RangePermission permission2 = rangePermissions.CreateRangePermission(rangeBody);
            permission2.Group = @"Everyone";
            rangePermissions.Add(permission2);

            RangePermission permission3 = rangePermissions.CreateRangePermission(rangeSignature);
            permission3.Group = "Nihlus";
            rangePermissions.Add(permission3);

            richEdit.Document.EndUpdateRangePermissions(rangePermissions);
            // Enforce protection and set password.
            richEdit.Document.Protect("123");
            #endregion #CreateRangePermissions
        }
示例#2
0
        private static List <RangePermission> CreateRangePermissions(DocumentRange range, string userGroup, params string[] usernames)
        {
            List <RangePermission> rangeList = new List <RangePermission>();

            foreach (string username in usernames)
            {
                RangePermission rp = new RangePermission(range);
                rp.Group    = userGroup;
                rp.UserName = username;
                rangeList.Add(rp);
            }
            return(rangeList);
        }
示例#3
0
        static void CreateRangePermissions(RichEditDocumentServer server)
        {
            #region #CreateRangePermissions
            server.LoadDocument("Documents//Grimm.docx", DocumentFormat.OpenXml);
            Document document = server.Document;

            // Protect document range
            RangePermissionCollection rangePermissions = document.BeginUpdateRangePermissions();
            RangePermission           rp = rangePermissions.CreateRangePermission(document.Paragraphs[3].Range);
            rp.Group = "Everyone";
            rangePermissions.Add(rp);

            document.EndUpdateRangePermissions(rangePermissions);
            // Enforce protection and set password.
            document.Protect("123");
            #endregion #CreateRangePermissions
        }
示例#4
0
        static void CreateRangePermissions(RichEditDocumentServer wordProcessor)
        {
            #region #CreateRangePermissions
            wordProcessor.LoadDocument("Documents//Grimm.docx", DocumentFormat.OpenXml);
            Document document = wordProcessor.Document;

            // Protect document range
            RangePermissionCollection rangePermissions = document.BeginUpdateRangePermissions();
            RangePermission           rp = rangePermissions.CreateRangePermission(document.Paragraphs[3].Range);
            rp.Group    = "Administrators";
            rp.UserName = "******";
            rangePermissions.Add(rp);

            document.EndUpdateRangePermissions(rangePermissions);
            // Enforce protection and set password.
            document.Protect("123");
            #endregion #CreateRangePermissions
        }
示例#5
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if (!IsCallback && !IsPostBack)
            {
                HiddenInvoiceId.Value = Request.Params["OrderID"];

                var arrayInvoice = new ArrayList();

                using (SqlConnection con = new SqlConnection(conStr))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = con;

                        cmd.CommandText = @"select i.InvoiceID, i.OrderID, i.InvoiceRtf 
                                            from Invoices i                                                             
                                            where i.OrderID = " + HiddenInvoiceId.Value + " order by i.InvoiceID desc";

                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            arrayInvoice.Add(reader["InvoiceID"]);
                            arrayInvoice.Add(reader["OrderID"]);
                            arrayInvoice.Add(reader["InvoiceRtf"]);
                        }

                        reader.Close();
                        con.Close();
                    }
                }

                if (arrayInvoice.Count > 0)
                {
                    // Stream var
                    MemoryStream updatedStream = new MemoryStream();

                    // Load stream from database
                    MemoryStream stream = new MemoryStream((byte[])arrayInvoice[2]);

                    // Load document from stream
                    RichEditDocumentServer docServer = new RichEditDocumentServer();
                    docServer.LoadDocument(stream, DocumentFormat.Rtf);

                    // Create document server
                    Document document = docServer.Document;

                    // If the document is not protected
                    if (!document.IsDocumentProtected)
                    {
                        // Protect the document with a password
                        document.Protect("123", DocumentProtectionType.ReadOnly);

                        // Tables
                        DevExpress.XtraRichEdit.API.Native.Table table1 = document.Tables[1];
                        DocumentRange rangeTable1 = table1.Rows[1].Range;

                        DevExpress.XtraRichEdit.API.Native.Table table2 = document.Tables[2];
                        DocumentRange rangeTable2 = table2.Rows[1].Range;

                        // Add table1 as range / Allow editing row 1 over table1
                        RangePermissionCollection coletionTable1   = document.BeginUpdateRangePermissions();
                        RangePermission           permissionTable1 = coletionTable1.CreateRangePermission(rangeTable1);
                        permissionTable1.Group = "Everyone";
                        coletionTable1.Add(permissionTable1);
                        document.EndUpdateRangePermissions(coletionTable1);

                        // Add table2 as range / Allow editing row 1 over table2
                        RangePermissionCollection coletionTable2   = document.BeginUpdateRangePermissions();
                        RangePermission           permissionTable2 = coletionTable2.CreateRangePermission(rangeTable2);
                        permissionTable2.Group = "Everyone";
                        coletionTable2.Add(permissionTable2);
                        document.EndUpdateRangePermissions(coletionTable2);
                    }

                    // Update updatedStream var from stream var
                    document.SaveDocument(updatedStream, DocumentFormat.Rtf);

                    // Open document from updatedStream var
                    ASPxRichEdit1.Open(Guid.NewGuid().ToString(), DocumentFormat.Rtf, () => { return(updatedStream.ToArray()); });
                }
            }
        }
        protected internal MemoryStream Template(bool Type,
                                                 string companyName,
                                                 string companyZip,
                                                 string companySettlement,
                                                 string companyAddress,
                                                 string doctorName,
                                                 int doctorSealNumber,
                                                 string patientName,
                                                 string motherName,
                                                 DateTime birthDate,
                                                 string TAJ,
                                                 string patientZip,
                                                 string patientSettlement,
                                                 string patientAddress,
                                                 string examination,
                                                 string examinationCode)
        {
            Document doc = reds.Document;

            doc.Sections[0].Page.PaperKind          = System.Drawing.Printing.PaperKind.A4;
            doc.DefaultCharacterProperties.FontSize = 12;
            doc.Unit = DevExpress.Office.DocumentUnit.Centimeter;
            doc.Sections[0].Margins.Bottom       = 2;
            doc.Sections[0].Margins.Top          = 2;
            doc.Sections[0].Margins.Left         = 2;
            doc.Sections[0].Margins.Right        = 2;
            doc.Sections[0].Margins.FooterOffset = 0.8F;

            doc.Unit = DevExpress.Office.DocumentUnit.Point;

            SubDocument   subdoc = doc.Sections[0].BeginUpdateHeader(HeaderFooterType.Primary);
            DocumentRange textRange;

            if (Type)
            {
                textRange = subdoc.AppendText("Vizsgálati Lap");
            }
            else
            {
                textRange = subdoc.AppendText("Státusz");
            }
            CharacterProperties cp1 = subdoc.BeginUpdateCharacters(textRange);

            cp1.Bold     = true;
            cp1.Italic   = true;
            cp1.FontSize = 18;
            subdoc.EndUpdateCharacters(cp1);
            subdoc.Paragraphs[0].Alignment       = ParagraphAlignment.Center;
            subdoc.Paragraphs[0].LineSpacingType = ParagraphLineSpacing.Sesquialteral;
            doc.Sections[0].EndUpdateHeader(subdoc);

            SubDocument subdoc2 = doc.Sections[0].BeginUpdateFooter(HeaderFooterType.Primary);
            Table       table2  = subdoc2.Tables.Create(subdoc2.Range.Start, 1, 2);

            table2.TableLayout        = TableLayoutType.Fixed;
            table2.PreferredWidth     = 5000;
            table2.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table2.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table2.Borders.Left.LineStyle   = TableBorderLineStyle.None;
            table2.Borders.Right.LineStyle  = TableBorderLineStyle.None;
            table2.Borders.Bottom.LineStyle = TableBorderLineStyle.None;

            subdoc2.InsertText(table2[0, 0].Range.Start, DateTime.Now.ToString("yyyy. MMMM d.", new CultureInfo("hu-HU")));
            DocumentRange       range = subdoc2.InsertText(table2[0, 0].Range.Start, "Dátum: ");
            CharacterProperties cp    = subdoc2.BeginUpdateCharacters(range);

            cp.Bold = true;
            subdoc2.Paragraphs[0].SpacingBefore = 3;

            subdoc2.InsertText(table2[0, 1].Range.Start, examinationCode);
            DocumentRange       r = subdoc2.InsertText(table2[0, 1].Range.Start, "Azonosító: ");
            CharacterProperties c = subdoc2.BeginUpdateCharacters(r);

            c.Bold = true;
            subdoc2.Paragraphs[1].Alignment     = ParagraphAlignment.Right;
            subdoc2.Paragraphs[1].SpacingBefore = 3;
            doc.Sections[0].EndUpdateFooter(subdoc2);

            Table table = doc.Tables.Create(doc.CaretPosition, 2, 2);

            table.TableLayout        = TableLayoutType.Fixed;
            table.PreferredWidth     = 5000;
            table.PreferredWidthType = WidthType.FiftiethsOfPercent;
            table.Borders.InsideVerticalBorder.LineStyle = TableBorderLineStyle.None;
            table.Borders.Left.LineStyle  = TableBorderLineStyle.None;
            table.Borders.Right.LineStyle = TableBorderLineStyle.None;

            doc.InsertText(table[0, 0].Range.Start, "\t" + companyAddress);
            doc.InsertText(table[0, 0].Range.Start, "  Címe: " + companyZip + " " + companySettlement + "\n");
            doc.InsertText(table[0, 0].Range.Start, "  Neve: " + companyName + "\n");
            DocumentRange       range1 = doc.InsertText(table[0, 0].Range.Start, "Intézmény\n");
            CharacterProperties cp2    = doc.BeginUpdateCharacters(range1);

            cp2.Bold     = true;
            cp2.FontSize = 16;
            doc.EndUpdateCharacters(cp2);
            doc.Paragraphs[0].SpacingBefore   = 6;
            doc.Paragraphs[3].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

            doc.InsertText(table[0, 1].Range.Start, "  Pecsétszáma: " + doctorSealNumber);
            doc.InsertText(table[0, 1].Range.Start, "  Neve: " + doctorName + "\n");
            DocumentRange       range2 = doc.InsertText(table[0, 1].Range.Start, "Orvos\n");
            CharacterProperties cp3    = doc.BeginUpdateCharacters(range2);

            cp3.Bold     = true;
            cp3.FontSize = 16;
            doc.EndUpdateCharacters(cp3);
            doc.Paragraphs[4].SpacingBefore = 6;

            doc.InsertText(table[1, 0].Range.Start, "  Születési ideje: " + birthDate.ToString("yyyy. MMMM d.", new CultureInfo("hu-HU")));
            doc.InsertText(table[1, 0].Range.Start, "  Anyja neve: " + motherName + "\n");
            doc.InsertText(table[1, 0].Range.Start, "  Neve: " + patientName + "\n");
            DocumentRange       range3 = doc.InsertText(table[1, 0].Range.Start, "Páciens\n");
            CharacterProperties cp4    = doc.BeginUpdateCharacters(range3);

            cp4.Bold     = true;
            cp4.FontSize = 16;
            doc.EndUpdateCharacters(cp4);
            doc.Paragraphs[7].SpacingBefore    = 6;
            doc.Paragraphs[10].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

            doc.InsertText(table[1, 1].Range.Start, "\t" + patientAddress);
            doc.InsertText(table[1, 1].Range.Start, "  Lakcíme: " + patientZip + " " + patientSettlement + "\n");
            doc.InsertText(table[1, 1].Range.Start, "  TAJ száma: " + TAJ + "\n");
            DocumentRange       range4 = doc.InsertText(table[1, 1].Range.Start, "\n");
            CharacterProperties cp5    = doc.BeginUpdateCharacters(range4);

            cp5.Bold     = true;
            cp5.FontSize = 16;
            doc.EndUpdateCharacters(cp5);
            doc.Paragraphs[11].SpacingBefore = 6;

            if (Type)
            {
                DocumentRange       range5 = doc.AppendText("  Vizsgálat: ");
                CharacterProperties cp6    = doc.BeginUpdateCharacters(range5);
                cp6.Bold     = true;
                cp6.FontSize = 16;
                doc.Paragraphs[15].SpacingBefore   = 6;
                doc.Paragraphs[15].LineSpacingType = ParagraphLineSpacing.Sesquialteral;

                DocumentRange       range6 = doc.AppendText(examination);
                CharacterProperties cp7    = doc.BeginUpdateCharacters(range6);
                cp7.Bold     = false;
                cp7.FontSize = 12;
            }
            doc.Paragraphs.Append();
            doc.Paragraphs[Type ? 16 : 15].SpacingBefore   = 0;
            doc.Paragraphs[Type ? 16 : 15].LineSpacingType = ParagraphLineSpacing.Single;
            doc.AppendText("          ");

            RangePermissionCollection rpc             = doc.BeginUpdateRangePermissions();
            RangePermission           rangePermission = new RangePermission(doc.Paragraphs[16].Range);

            rangePermission.UserName = "******";
            rpc.Add(rangePermission);

            doc.EndUpdateRangePermissions(rpc);

            doc.Protect("admin");

            using (MemoryStream ms = new MemoryStream())
            {
                reds.SaveDocument(ms, DocumentFormat.OpenXml);
                return(ms);
            }
        }