Ejemplo n.º 1
0
        // Saving Invoice at DataBase
        public void InvoiceSave()
        {
            MemoryStream rtfStream = new MemoryStream();
            MemoryStream pdfStream = new MemoryStream();

            ASPxRichEdit1.SaveCopy(rtfStream, DocumentFormat.Rtf);
            ASPxRichEdit1.ExportToPdf(pdfStream);

            RichEditDocumentServer docServer = new RichEditDocumentServer();

            docServer.LoadDocument(rtfStream, DocumentFormat.Rtf);

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

                    cmd.CommandText = @"update Invoices set InvoiceRtf = @InvoiceRtf, InvoicePdf = @InvoicePdf
                                        where OrderID = @OrderID";

                    cmd.Parameters.AddWithValue("@OrderID", HiddenInvoiceId.Value);
                    cmd.Parameters.AddWithValue("@InvoiceRtf", SqlDbType.VarBinary).Value = rtfStream.ToArray();
                    cmd.Parameters.AddWithValue("@InvoicePdf", SqlDbType.VarBinary).Value = pdfStream.ToArray();

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }
    protected void ASPxRichEdit1_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
    {
        MemoryStream memoryStream = new MemoryStream();

        ASPxRichEdit1.SaveCopy(memoryStream, DocumentFormat.Rtf);
        memoryStream.Position = 0;

        var server = new RichEditDocumentServer();

        server.LoadDocument(memoryStream, DocumentFormat.Rtf);
        var pos = server.Document.CreatePosition(Convert.ToInt32(e.Parameter));

        server.Document.InsertRtfText(pos, rtf);

        memoryStream = new MemoryStream();
        server.SaveDocument(memoryStream, DocumentFormat.Rtf);
        ASPxRichEdit1.Open(Guid.NewGuid().ToString(), DocumentFormat.Rtf, () =>
        {
            return(memoryStream.ToArray());
        });
    }