1
- /***********************************************************************
2
- b-PAC 3.0 Component Sample (TestPrint)
3
-
4
- (C)Copyright Brother Industries, Ltd. 2009
5
- ************************************************************************/
6
-
7
1
using System ;
8
- using System . Collections . Generic ;
9
- using System . ComponentModel ;
10
- using System . Data ;
11
- using System . Drawing ;
12
- using System . Text ;
13
2
using System . Windows . Forms ;
14
- using System . Runtime . InteropServices ;
15
- using bpac ;
16
3
17
- namespace BarcodePrint
4
+ namespace BpacBarcode
18
5
{
19
6
public partial class BarcodeForm : Form
20
7
{
@@ -30,53 +17,24 @@ private void Form1_Load(object sender, EventArgs e)
30
17
31
18
if ( args . GetLength ( 0 ) == 3 )
32
19
{
33
- doPrint ( args [ 1 ] , args [ 2 ] ) ;
20
+ ( new PrinterAPI ( args [ 1 ] , args [ 2 ] ) ) . print ( ) ;
34
21
Close ( ) ;
35
22
}
36
23
else if ( args . GetLength ( 0 ) == 4 )
37
24
{
38
- doPrint ( args [ 1 ] , args [ 2 ] , args [ 3 ] ) ;
25
+ ( new PrinterAPI ( args [ 1 ] , args [ 2 ] , args [ 3 ] ) ) . print ( ) ;
39
26
Close ( ) ;
40
27
}
41
28
else if ( args . GetLength ( 0 ) == 5 )
42
29
{
43
- doPrint ( args [ 1 ] , args [ 2 ] , args [ 3 ] , Int32 . Parse ( args [ 4 ] ) ) ;
30
+ ( new PrinterAPI ( args [ 1 ] , args [ 2 ] , args [ 3 ] , Int32 . Parse ( args [ 4 ] ) ) ) . print ( ) ;
44
31
Close ( ) ;
45
32
}
46
33
}
47
34
48
35
private void btnPrint_Click ( object sender , EventArgs e )
49
36
{
50
- doPrint ( txtTitle . Text , txtBarcode . Text , timestamp . Value , ( int ) cntCopies . Value ) ;
51
- }
52
-
53
- private void doPrint ( string title , string barcode , DateTime timestamp , int count = 1 )
54
- {
55
- doPrint ( title , barcode , timestamp . ToString ( "dd.MM.yyyy HH:mm" ) , count ) ;
56
- }
57
-
58
- private void doPrint ( string title , string barcode , string timestamp = "" , int count = 1 )
59
- {
60
- timestamp = timestamp . Equals ( "" ) ? System . DateTime . Now . ToString ( "dd.MM.yyyy HH:mm" ) : timestamp ;
61
-
62
- bpac . DocumentClass doc = new DocumentClass ( ) ;
63
- string templatePath = System . IO . Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) + "\\ " + doc . Printer . GetMediaId ( ) . ToString ( ) + ".lbx" ;
64
- if ( doc . Open ( templatePath ) != false )
65
- {
66
- doc . GetObject ( "title" ) . Text = title ;
67
- doc . GetObject ( "barcode" ) . Text = barcode ;
68
- doc . GetObject ( "timestamp" ) . Text = timestamp ;
69
-
70
- bpac . PrintOptionConstants printOptions = PrintOptionConstants . bpoAutoCut | PrintOptionConstants . bpoQuality ;
71
- doc . StartPrint ( "" , printOptions ) ;
72
- doc . PrintOut ( count , printOptions ) ;
73
- doc . EndPrint ( ) ;
74
- doc . Close ( ) ;
75
- }
76
- else
77
- {
78
- MessageBox . Show ( "Open() Error: " + doc . ErrorCode + "\n Media ID" + doc . Printer . GetMediaId ( ) . ToString ( ) ) ;
79
- }
37
+ ( new PrinterAPI ( txtTitle . Text , txtBarcode . Text , timestamp . Value . ToString ( ) , ( int ) cntCopies . Value ) ) . print ( ) ;
80
38
}
81
39
82
40
protected override bool ProcessCmdKey ( ref Message msg , Keys keyData )
@@ -88,7 +46,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
88
46
}
89
47
else if ( keyData == Keys . Enter )
90
48
{
91
- doPrint ( txtTitle . Text , txtBarcode . Text ) ;
49
+ ( new PrinterAPI ( txtTitle . Text , txtBarcode . Text , timestamp . Value . ToString ( ) , ( int ) cntCopies . Value ) ) . print ( ) ;
92
50
}
93
51
return base . ProcessCmdKey ( ref msg , keyData ) ;
94
52
}
0 commit comments