Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Mail Merge Server");
            string templateFileName;
            string outputFileName;

            switch (args.Length)
            {
            case 0:
                templateFileName = defaultTemplateFileName;
                outputFileName   = defaultOutputFileName;
                break;

            case 1:
                templateFileName = defaultTemplateFileName;
                outputFileName   = args[0];
                break;

            case 2:
                templateFileName = args[0];
                outputFileName   = args[1];
                break;

            default:
                throw new ArgumentException();
            }

            if (!File.Exists(templateFileName))
            {
                throw new FileNotFoundException("Template file not found", templateFileName);
            }
            Console.WriteLine("Template file: {0}", new FileInfo(templateFileName).FullName);
            Console.WriteLine("Target file:   {0}", new FileInfo(outputFileName).FullName);
            #region #ServerCode
            SnapDocumentServer server = new SnapDocumentServer();

            server.SnapMailMergeRecordStarted  += server_SnapMailMergeRecordStarted;
            server.SnapMailMergeRecordFinished += server_SnapMailMergeRecordFinished;

            server.LoadDocument(templateFileName);
            object dataSource = CreateDataSource();

            SnapMailMergeExportOptions options = server.Document.CreateSnapMailMergeExportOptions();
            options.DataSource = dataSource;
            Console.Write("Performing mail merge... ");
            server.SnapMailMerge(options, outputFileName, DocumentFormat.Rtf);
            #endregion #ServerCode
            Console.WriteLine("Ok!");
            Console.Write("Press any key...");
            Console.ReadKey();
            System.Diagnostics.Process.Start(outputFileName);
        }
        static void FilterData(SnapDocumentServer server)
        {
            #region #FilterData
            // Delete the document's content.
            server.LoadDocument("Template.snx");

            SnapList list = server.Document.FindListByName("Data Source 11");
            server.Document.ParseField(list.Field);
            list.BeginUpdate();
            // Apply filtering:
            const string filter = "[Discontinued] = False";
            if (!list.Filters.Contains(filter))
            {
                list.Filters.Add(filter);
            }

            list.EndUpdate();
            list.Field.Update();


            #endregion #FilterData
        }
Beispiel #3
0
 public static void ShowPrintPreview(IDocumentData documentData, IObjectSpace objectSpace, CriteriaOperator inPlaceCriteria)
 {
     using (SnapDocumentServer server = new SnapDocumentServer()) {
         SnapDocumentHelper helper = new SnapDocumentHelper(documentData, objectSpace, null, inPlaceCriteria);
         helper.LoadDocument(server.Document);
         // Mail Merge
         if (server.Document.DataSources.Count == 1 && server.Options.SnapMailMergeVisualOptions.DataSource == server.Document.DataSources[0].DataSource)
         {
             using (MemoryStream stream = new MemoryStream()) {
                 server.SnapMailMerge(stream, SnapDocumentFormat.Snap);
                 stream.Flush();
                 stream.Seek(0, SeekOrigin.Begin);
                 server.LoadDocument(stream, SnapDocumentFormat.Snap);
             }
         }
         using (PrintingSystem ps = new PrintingSystem()) {
             PrintableComponentLink link = new PrintableComponentLink(ps);
             link.Component = server;
             link.CreateDocument();
             link.ShowPreviewDialog();
         }
     }
 }