PrintPlaceStickersForm.cs
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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();
}
}
}