PrintPlaceStickersForm.cs 2.57 KB
using MoyaAdminLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MoyaAdminUI
{
    public partial class PrintPlaceStickersForm : Form
    {
        private string placeLabel = "paikkatarra.lbx";
        private List<ComputerPlace> places;

        public PrintPlaceStickersForm(List<ComputerPlace> places)
        {
            InitializeComponent();

            this.places = places;
        }

        private void printButton_Click(object sender, EventArgs e)
        {

            if (!File.Exists(placeLabel))
            {
                MessageBox.Show("Cannot find print template");
                return;
            }
            foreach (ComputerPlace place in places)
            {
                bpac.DocumentClass doc = null;
                try
                {
                    doc = new bpac.DocumentClass();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not print place label. Place: " + place.Name);
                    Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
                    return;
                }
                //doc.SetPrinter(Objects.Conf.BoxLabelPrinter, false);
                if (doc != null)
                {
                    //doc.Open(Path.Combine(Properties.Settings.Default.dd, cloakroomLabel));
                    doc.Open(placeLabel);

                    doc.GetObject("place").Text = place.Name;
                    if(showNickCheckBox.Checked && place.User != null)
                        doc.GetObject("group").Text = place.User.Nick;
                    else
                        doc.GetObject("group").Text = "";
                    //if(showCodeCheckBox.Checked)

                    doc.GetObject("code").Text = "";



                    doc.StartPrint("", bpac.PrintOptionConstants.bpoDefault);

                    if(!doc.PrintOut(1, bpac.PrintOptionConstants.bpoDefault))
                    {
                        Console.WriteLine("Error occurred: " + doc.ErrorCode.ToString());
                    }
                    doc.EndPrint();

                    doc.Close();

                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}