Jump to content


Photo
- - - - -

Sample Code: Create And Assign Csv Database


  • Please log in to reply
3 replies to this topic

#1 Shotaro I - Seagull Support

Shotaro I - Seagull Support

    Member

  • Moderators
  • 941 posts
  • LocationJapan

Posted 15 January 2012 - 07:37 PM

*
POPULAR

Asked how to print multiple record in single job by .net SDK.
I knew that's possible by using SetDatabaseConnection() method, however I haven't tried...
Thanks Jiji!

Created by BarTender 9.4SR3 + Visual C# 2005.

// Sample code to demonstrate How to dynamically create and assign text database in .net SDK
// This method come to handy when you need to print multiple record within single print job.
// Create a btw format with Text database (CSV) connection.
// (Please cosider to use Commander (Commander script / XML Script) to achieve same result too.)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CreateCSV_cs
{
    public partial class Form1 : Form
    {
        Seagull.BarTender.Print.Engine btEngine;
        Seagull.BarTender.Print.LabelFormatDocument btFormat;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Run BarTender
            btEngine = new Seagull.BarTender.Print.Engine();
            btEngine.Start();
            // Show BarTender UI for debugging purpose (Set "None" to hide)
            btEngine.Window.VisibleWindows = Seagull.BarTender.Print.VisibleWindows.All;
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            // Quit BarTender
            btEngine.Stop(Seagull.BarTender.Print.SaveOptions.DoNotSaveChanges);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Open format at same folder as executable
            btFormat = btEngine.Documents.Open(Application.StartupPath + @"\FMT1.btw");
            //btFormat.PrintSetup.PrinterName("Zebra TLP3844-Z"); // specify printer

            // Prepare data (you can be more creative.)
            string buf = "";
            buf += "\"FNAME\",\"LNAME\",\"DOB\"\r\n"; // header
            buf += "\"Steven\",\"Jobs\",\"1955/02/24\"\r\n"; //record 1
            buf += "\"Stephen\",\"Wozniak\",\"1950/08/11\"\r\n";
            buf += "\"John\",\"Sculley\",\"1939/04/06\"\r\n";
            buf += "\"Gilbert\",\"Amerio\",\"1943/03/01\"\r\n";

            // Create text database as a temporary file
            string tmpFile = Path.GetTempFileName();
            File.WriteAllText(tmpFile, buf);

            // Assign the text database to curtent format's primary database
            Seagull.BarTender.Print.Database.TextFile tf = new Seagull.BarTender.Print.Database.TextFile(btFormat.DatabaseConnections[0].Name);
            tf.FileName = tmpFile;
            btFormat.DatabaseConnections.SetDatabaseConnection(tf);
            btFormat.PrintSetup.ReloadTextDatabaseFields = true; // Fix when field order is different from design time

            // Print
            btFormat.Print();

            // Delete text database
            File.Delete(tmpFile);

        }
    }
}


#2 frederm

frederm

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 11 June 2015 - 08:20 AM

.



#3 frederm

frederm

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 11 June 2015 - 08:39 AM

.

 

Mike



#4 dillinger69

dillinger69

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 06 September 2016 - 11:23 PM

is this applicable for BarTender 6.12? thanks for positive reponse.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users