소스 검색

Add print mode setting for select 12cpi, 10cpi or mixed cpi modes.

Andrew Klopper 7 년 전
부모
커밋
7e5ba7fcbf

+ 17 - 1
BulkPrinting/BulkPrinting/Migrations.cs

@@ -20,7 +20,7 @@ namespace BulkPrinting
20 20
                 throw new Exception(String.Format("Invalid migration value: {0}", result));
21 21
             }
22 22
 
23
-            if (startingMigration > 6)
23
+            if (startingMigration > 7)
24 24
             {
25 25
                 throw new Exception("Database is for a newer version of this application. Please upgrade and try again.");
26 26
             }
@@ -48,6 +48,10 @@ namespace BulkPrinting
48 48
             {
49 49
                 Migration6(db);
50 50
             }
51
+            if (startingMigration < 7)
52
+            {
53
+                Migration7(db);
54
+            }
51 55
             //Add further migration executions here - Migration = '1', '2', '3' etc
52 56
 
53 57
             return;
@@ -282,5 +286,17 @@ namespace BulkPrinting
282 286
                 "UPDATE Parameters SET Value='6' WHERE Key='Migration'"
283 287
             );
284 288
         }
289
+
290
+        public static bool Migration7(DBHelper db)
291
+        {
292
+            return ApplyMigrationQueries(
293
+                db, null,
294
+
295
+                "INSERT INTO Parameters (Key, Value) VALUES ('PrintMode', " + Utility.PrintMode.MixedCPI.ToString("d") + ")",
296
+
297
+                // IMPORTANT
298
+                "UPDATE Parameters SET Value='7' WHERE Key='Migration'"
299
+            );
300
+        }
285 301
     }
286 302
 }

+ 15 - 19
BulkPrinting/BulkPrinting/PrintAlignmentDialog.cs

@@ -1,6 +1,5 @@
1 1
 using System;
2 2
 using System.Data.SQLite;
3
-using System.Drawing;
4 3
 using System.Threading;
5 4
 using System.Windows.Forms;
6 5
 
@@ -58,31 +57,26 @@ namespace BulkPrinting
58 57
         private void btnAlignment_Click(object sender, EventArgs e)
59 58
         {
60 59
 
61
-            var PrinterInitString = Utility.GetPrinterInitString(Globals.DB);
62
-            int initJobID = Globals.MaxPrinter.Open("Printer_Init");
60
+            var printSettings = Utility.GetPrintSettings(Globals.DB);
61
+
62
+            int initJobID = Globals.MaxPrinter.Open("Alignment");
63 63
             if (initJobID == 0) return;
64
-            Globals.MaxPrinter.Print(PrinterInitString.ToString());
65
-            //Globals.MaxPrinter.Print(Printer.INITIALISE_PRINTER);
66
-            //Globals.MaxPrinter.Print(Printer.UNIDIRECTIONAL_OFF);
67
-            //Globals.MaxPrinter.Print(Printer.CHARPITCHELITE);
68
-            //Globals.MaxPrinter.Print(Printer.EMPHASISE_ON);
69
-            //Globals.MaxPrinter.Close();
64
+            Globals.MaxPrinter.Print(printSettings.InitCodes);
70 65
 
66
+            //string row = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\r\n";
71 67
 
72
-            //if (Globals.MaxPrinter.Open("Alignment")==0) return;
68
+            string row =
69
+                    "\r\n\n\n  " + printSettings.PinStartCodes +
70
+                    Utility.FormatPrintAlignmentRow(printSettings.PinCpi, "VOUCHER PIN") + printSettings.PinEndCodes + "\r\n\n  " +
71
+                    Utility.FormatPrintAlignmentRow(printSettings.VoucherCpi, "SERIAL NUMBER") + "\r\n  " +
72
+                    Utility.FormatPrintAlignmentRow(printSettings.VoucherCpi, "BATCH DETAILS") + "\r\n  " +
73
+                    Utility.FormatPrintAlignmentRow(printSettings.VoucherCpi, "DESCRIPTION") + "\r\n  " +
74
+                    Utility.FormatPrintAlignmentRow(printSettings.VoucherCpi, "VENDOR DETAILS") + "\r\n\n\n\n\n\n\n\n\n\n";
73 75
 
74 76
             string AlignmentPage ="";
75
-
76 77
             for (var i = 0; i < 8; i++) //Two full pages of vouchers
77 78
             {
78
-                //AlignmentPage += "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\r\n";
79
-                
80
-                AlignmentPage += "\r\n\n\n" +
81
-                "\x1B\x50[-VOUCHER PIN CODE-]     [-VOUCHER PIN CODE-]     [-VOUCHER PIN CODE-]      [-VOUCHER PIN CODE-]     [-VOUCHER PIN CODE-]\x1B\x4D\r\n\n" +
82
-                "[--VOUCHER SERIAL NUM--]      [--VOUCHER SERIAL NUM--]      [--VOUCHER SERIAL NUM--]       [--VOUCHER SERIAL NUM--]      [--VOUCHER SERIAL NUM--]\r\n" +
83
-                "[--BATCHNO/SEQNO/PAGE--]      [--BATCHNO/SEQNO/PAGE--]      [--BATCHNO/SEQNO/PAGE--]       [--BATCHNO/SEQNO/PAGE--]      [--BATCHNO/SEQNO/PAGE--]\r\n" +
84
-                "[--VOUCHERDESCRIPTION--]      [--VOUCHERDESCRIPTION--]      [--VOUCHERDESCRIPTION--]       [--VOUCHERDESCRIPTION--]      [--VOUCHERDESCRIPTION--]\r\n" +
85
-                "[--VENDOR          ID--]      [--VENDOR          ID--]      [--VENDOR          ID--]       [--VENDOR          ID--]      [--VENDOR          ID--]\r\n\n\n\n\n\n\n\n\n\n";
79
+                AlignmentPage += row;
86 80
             }
87 81
             
88 82
             Globals.MaxPrinter.Print(AlignmentPage);
@@ -174,11 +168,13 @@ namespace BulkPrinting
174 168
             dialog.InitString = Utility.GetSavedParameter(Globals.DB, "PrinterInitString");
175 169
             dialog.VendorName = Utility.GetSavedParameter(Globals.DB, "VendorName");
176 170
             dialog.EnableBoldPrinting = Utility.GetSavedParameterAsBoolean(Globals.DB, "EnableBoldPrinting");
171
+            dialog.PrintMode = (Utility.PrintMode)Enum.Parse(typeof(Utility.PrintMode), Utility.GetSavedParameter(Globals.DB, "PrintMode"));
177 172
             if (dialog.ShowDialog() == DialogResult.OK)
178 173
             {
179 174
                 Utility.UpdateSavedParameter(Globals.DB, "PrinterInitString", dialog.InitString);
180 175
                 Utility.UpdateSavedParameter(Globals.DB, "VendorName", dialog.VendorName);
181 176
                 Utility.UpdateSavedParameter(Globals.DB, "EnableBoldPrinting", dialog.EnableBoldPrinting);
177
+                Utility.UpdateSavedParameter(Globals.DB, "PrintMode", dialog.PrintMode.ToString("d"));
182 178
             }
183 179
         }
184 180
     }

+ 84 - 14
BulkPrinting/BulkPrinting/PrinterSettingsForm.Designer.cs

@@ -39,26 +39,32 @@
39 39
             this.panel1 = new System.Windows.Forms.Panel();
40 40
             this.printQualityFastRadioButton = new System.Windows.Forms.RadioButton();
41 41
             this.printQualityHighRadioButton = new System.Windows.Forms.RadioButton();
42
+            this.label4 = new System.Windows.Forms.Label();
43
+            this.panel2 = new System.Windows.Forms.Panel();
44
+            this.mixedCpiRadioButton = new System.Windows.Forms.RadioButton();
45
+            this.manual10CpiRadioButton = new System.Windows.Forms.RadioButton();
46
+            this.manual12CpiRadioButton = new System.Windows.Forms.RadioButton();
42 47
             this.panel1.SuspendLayout();
48
+            this.panel2.SuspendLayout();
43 49
             this.SuspendLayout();
44 50
             // 
45 51
             // label1
46 52
             // 
47 53
             this.label1.AutoSize = true;
48 54
             this.label1.ForeColor = System.Drawing.Color.White;
49
-            this.label1.Location = new System.Drawing.Point(13, 104);
55
+            this.label1.Location = new System.Drawing.Point(13, 190);
50 56
             this.label1.Name = "label1";
51 57
             this.label1.Size = new System.Drawing.Size(155, 17);
52
-            this.label1.TabIndex = 8;
58
+            this.label1.TabIndex = 10;
53 59
             this.label1.Text = "Printer Init String (Hex):";
54 60
             this.label1.Visible = false;
55 61
             // 
56 62
             // initStringTextBox
57 63
             // 
58
-            this.initStringTextBox.Location = new System.Drawing.Point(174, 104);
64
+            this.initStringTextBox.Location = new System.Drawing.Point(174, 190);
59 65
             this.initStringTextBox.Name = "initStringTextBox";
60 66
             this.initStringTextBox.Size = new System.Drawing.Size(475, 22);
61
-            this.initStringTextBox.TabIndex = 2;
67
+            this.initStringTextBox.TabIndex = 6;
62 68
             this.initStringTextBox.Visible = false;
63 69
             // 
64 70
             // resetButton
@@ -67,7 +73,7 @@
67 73
             this.resetButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
68 74
             this.resetButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
69 75
             this.resetButton.ForeColor = System.Drawing.Color.White;
70
-            this.resetButton.Location = new System.Drawing.Point(16, 73);
76
+            this.resetButton.Location = new System.Drawing.Point(13, 166);
71 77
             this.resetButton.Name = "resetButton";
72 78
             this.resetButton.Size = new System.Drawing.Size(137, 28);
73 79
             this.resetButton.TabIndex = 5;
@@ -82,7 +88,7 @@
82 88
             this.okButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
83 89
             this.okButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
84 90
             this.okButton.ForeColor = System.Drawing.Color.White;
85
-            this.okButton.Location = new System.Drawing.Point(446, 73);
91
+            this.okButton.Location = new System.Drawing.Point(443, 166);
86 92
             this.okButton.Name = "okButton";
87 93
             this.okButton.Size = new System.Drawing.Size(100, 28);
88 94
             this.okButton.TabIndex = 3;
@@ -96,7 +102,7 @@
96 102
             this.cancelButton.FlatAppearance.BorderColor = System.Drawing.Color.Black;
97 103
             this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
98 104
             this.cancelButton.ForeColor = System.Drawing.Color.White;
99
-            this.cancelButton.Location = new System.Drawing.Point(552, 73);
105
+            this.cancelButton.Location = new System.Drawing.Point(549, 166);
100 106
             this.cancelButton.Name = "cancelButton";
101 107
             this.cancelButton.Size = new System.Drawing.Size(100, 28);
102 108
             this.cancelButton.TabIndex = 4;
@@ -110,7 +116,7 @@
110 116
             this.label2.Location = new System.Drawing.Point(13, 13);
111 117
             this.label2.Name = "label2";
112 118
             this.label2.Size = new System.Drawing.Size(99, 17);
113
-            this.label2.TabIndex = 6;
119
+            this.label2.TabIndex = 7;
114 120
             this.label2.Text = "Vendor Name:";
115 121
             // 
116 122
             // vendorNameTextBox
@@ -125,10 +131,10 @@
125 131
             // 
126 132
             this.label3.AutoSize = true;
127 133
             this.label3.ForeColor = System.Drawing.Color.White;
128
-            this.label3.Location = new System.Drawing.Point(13, 43);
134
+            this.label3.Location = new System.Drawing.Point(13, 135);
129 135
             this.label3.Name = "label3";
130 136
             this.label3.Size = new System.Drawing.Size(89, 17);
131
-            this.label3.TabIndex = 7;
137
+            this.label3.TabIndex = 9;
132 138
             this.label3.Text = "Print Quality:";
133 139
             // 
134 140
             // panel1
@@ -136,14 +142,15 @@
136 142
             this.panel1.AutoSize = true;
137 143
             this.panel1.Controls.Add(this.printQualityFastRadioButton);
138 144
             this.panel1.Controls.Add(this.printQualityHighRadioButton);
139
-            this.panel1.Location = new System.Drawing.Point(174, 41);
145
+            this.panel1.Location = new System.Drawing.Point(174, 133);
140 146
             this.panel1.Name = "panel1";
141 147
             this.panel1.Size = new System.Drawing.Size(174, 24);
142
-            this.panel1.TabIndex = 1;
148
+            this.panel1.TabIndex = 2;
143 149
             // 
144 150
             // printQualityFastRadioButton
145 151
             // 
146 152
             this.printQualityFastRadioButton.AutoSize = true;
153
+            this.printQualityFastRadioButton.Checked = true;
147 154
             this.printQualityFastRadioButton.ForeColor = System.Drawing.Color.White;
148 155
             this.printQualityFastRadioButton.Location = new System.Drawing.Point(3, 0);
149 156
             this.printQualityFastRadioButton.Name = "printQualityFastRadioButton";
@@ -161,17 +168,73 @@
161 168
             this.printQualityHighRadioButton.Name = "printQualityHighRadioButton";
162 169
             this.printQualityHighRadioButton.Size = new System.Drawing.Size(106, 21);
163 170
             this.printQualityHighRadioButton.TabIndex = 1;
164
-            this.printQualityHighRadioButton.TabStop = true;
165 171
             this.printQualityHighRadioButton.Text = "High Quality";
166 172
             this.printQualityHighRadioButton.UseVisualStyleBackColor = true;
167 173
             // 
174
+            // label4
175
+            // 
176
+            this.label4.AutoSize = true;
177
+            this.label4.ForeColor = System.Drawing.Color.White;
178
+            this.label4.Location = new System.Drawing.Point(13, 48);
179
+            this.label4.Name = "label4";
180
+            this.label4.Size = new System.Drawing.Size(80, 17);
181
+            this.label4.TabIndex = 8;
182
+            this.label4.Text = "Print Mode:";
183
+            // 
184
+            // panel2
185
+            // 
186
+            this.panel2.Controls.Add(this.mixedCpiRadioButton);
187
+            this.panel2.Controls.Add(this.manual10CpiRadioButton);
188
+            this.panel2.Controls.Add(this.manual12CpiRadioButton);
189
+            this.panel2.Location = new System.Drawing.Point(174, 42);
190
+            this.panel2.Name = "panel2";
191
+            this.panel2.Size = new System.Drawing.Size(475, 85);
192
+            this.panel2.TabIndex = 1;
193
+            // 
194
+            // mixedCpiRadioButton
195
+            // 
196
+            this.mixedCpiRadioButton.AutoSize = true;
197
+            this.mixedCpiRadioButton.Checked = true;
198
+            this.mixedCpiRadioButton.ForeColor = System.Drawing.Color.White;
199
+            this.mixedCpiRadioButton.Location = new System.Drawing.Point(3, 60);
200
+            this.mixedCpiRadioButton.Name = "mixedCpiRadioButton";
201
+            this.mixedCpiRadioButton.Size = new System.Drawing.Size(221, 21);
202
+            this.mixedCpiRadioButton.TabIndex = 2;
203
+            this.mixedCpiRadioButton.TabStop = true;
204
+            this.mixedCpiRadioButton.Text = "Mixed CPI (EPSON mode only)";
205
+            this.mixedCpiRadioButton.UseVisualStyleBackColor = true;
206
+            // 
207
+            // manual10CpiRadioButton
208
+            // 
209
+            this.manual10CpiRadioButton.AutoSize = true;
210
+            this.manual10CpiRadioButton.ForeColor = System.Drawing.Color.White;
211
+            this.manual10CpiRadioButton.Location = new System.Drawing.Point(3, 32);
212
+            this.manual10CpiRadioButton.Name = "manual10CpiRadioButton";
213
+            this.manual10CpiRadioButton.Size = new System.Drawing.Size(208, 21);
214
+            this.manual10CpiRadioButton.TabIndex = 1;
215
+            this.manual10CpiRadioButton.Text = "10 CPI, manual printer setup";
216
+            this.manual10CpiRadioButton.UseVisualStyleBackColor = true;
217
+            // 
218
+            // manual12CpiRadioButton
219
+            // 
220
+            this.manual12CpiRadioButton.AutoSize = true;
221
+            this.manual12CpiRadioButton.ForeColor = System.Drawing.Color.White;
222
+            this.manual12CpiRadioButton.Location = new System.Drawing.Point(4, 4);
223
+            this.manual12CpiRadioButton.Name = "manual12CpiRadioButton";
224
+            this.manual12CpiRadioButton.Size = new System.Drawing.Size(208, 21);
225
+            this.manual12CpiRadioButton.TabIndex = 0;
226
+            this.manual12CpiRadioButton.Text = "12 CPI, manual printer setup";
227
+            this.manual12CpiRadioButton.UseVisualStyleBackColor = true;
228
+            // 
168 229
             // PrinterSettingsForm
169 230
             // 
170 231
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
171 232
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
172 233
             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(7)))), ((int)(((byte)(63)))), ((int)(((byte)(145)))));
173
-            this.ClientSize = new System.Drawing.Size(661, 109);
234
+            this.ClientSize = new System.Drawing.Size(661, 199);
174 235
             this.ControlBox = false;
236
+            this.Controls.Add(this.panel2);
237
+            this.Controls.Add(this.label4);
175 238
             this.Controls.Add(this.panel1);
176 239
             this.Controls.Add(this.label3);
177 240
             this.Controls.Add(this.vendorNameTextBox);
@@ -188,6 +251,8 @@
188 251
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PrinterSettingsForm_FormClosing);
189 252
             this.panel1.ResumeLayout(false);
190 253
             this.panel1.PerformLayout();
254
+            this.panel2.ResumeLayout(false);
255
+            this.panel2.PerformLayout();
191 256
             this.ResumeLayout(false);
192 257
             this.PerformLayout();
193 258
 
@@ -206,5 +271,10 @@
206 271
         private System.Windows.Forms.Panel panel1;
207 272
         private System.Windows.Forms.RadioButton printQualityFastRadioButton;
208 273
         private System.Windows.Forms.RadioButton printQualityHighRadioButton;
274
+        private System.Windows.Forms.Label label4;
275
+        private System.Windows.Forms.Panel panel2;
276
+        private System.Windows.Forms.RadioButton mixedCpiRadioButton;
277
+        private System.Windows.Forms.RadioButton manual10CpiRadioButton;
278
+        private System.Windows.Forms.RadioButton manual12CpiRadioButton;
209 279
     }
210 280
 }

+ 40 - 0
BulkPrinting/BulkPrinting/PrinterSettingsForm.cs

@@ -29,6 +29,46 @@ namespace BulkPrinting
29 29
             }
30 30
         }
31 31
 
32
+        public Utility.PrintMode PrintMode
33
+        {
34
+            get
35
+            {
36
+                if (manual12CpiRadioButton.Checked)
37
+                {
38
+                    return Utility.PrintMode.Manual12CPI;
39
+                }
40
+                else if (manual10CpiRadioButton.Checked)
41
+                {
42
+                    return Utility.PrintMode.Manual10CPI;
43
+                }
44
+                else if (mixedCpiRadioButton.Checked)
45
+                {
46
+                    return Utility.PrintMode.MixedCPI;
47
+                }
48
+                else
49
+                {
50
+                    throw new Exception("Print mode not selected");
51
+                }
52
+            }
53
+            set
54
+            {
55
+                switch(value)
56
+                {
57
+                    case Utility.PrintMode.Manual12CPI:
58
+                        manual12CpiRadioButton.Checked = true;
59
+                        break;
60
+                    case Utility.PrintMode.Manual10CPI:
61
+                        manual10CpiRadioButton.Checked = true;
62
+                        break;
63
+                    case Utility.PrintMode.MixedCPI:
64
+                        mixedCpiRadioButton.Checked = true;
65
+                        break;
66
+                    default:
67
+                        throw new Exception("Invalid print mode");
68
+                }
69
+            }
70
+        }
71
+
32 72
         public string InitString
33 73
         {
34 74
             get { return initStringTextBox.Text.Trim(); }

+ 1 - 1
BulkPrinting/BulkPrinting/Properties/AssemblyInfo.cs

@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
33 33
 // by using the '*' as shown below:
34 34
 // [assembly: AssemblyVersion("1.0.*")]
35 35
 [assembly: AssemblyVersion("1.0.*")]
36
-[assembly: AssemblyFileVersion("1.11")]
36
+[assembly: AssemblyFileVersion("1.12")]

+ 127 - 30
BulkPrinting/BulkPrinting/Utility.cs

@@ -21,6 +21,17 @@ namespace BulkPrinting
21 21
         [DllImport("user32.dll", SetLastError = true)]
22 22
         public static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
23 23
 
24
+        public enum PrintMode { Manual10CPI = 1, Manual12CPI = 2, MixedCPI = 3 }
25
+
26
+        public class PrintSettings
27
+        {
28
+            public string InitCodes;
29
+            public string PinStartCodes;
30
+            public string PinEndCodes;
31
+            public int PinCpi;
32
+            public int VoucherCpi;
33
+        }
34
+
24 35
         public static byte[] HexStringToBytes(string hex)
25 36
         {
26 37
             int numChars = hex.Length;
@@ -35,15 +46,59 @@ namespace BulkPrinting
35 46
             return bytes;
36 47
         }
37 48
 
38
-        public static string GetPrinterInitString(DBHelper db)
49
+        public static PrintSettings GetPrintSettings(DBHelper db)
39 50
         {
40
-            //var hex = GetSavedParameter(db, "PrinterInitString");
41
-            var hex = Globals.DefaultPrinterInitString;
51
+            string initCodes;
52
+
53
+            var printMode = (PrintMode)Enum.Parse(typeof(PrintMode), GetSavedParameter(Globals.DB, "PrintMode"));
54
+            
55
+            if (printMode == PrintMode.MixedCPI)
56
+            {
57
+                //var hex = GetSavedParameter(db, "PrinterInitString");
58
+                initCodes = Encoding.ASCII.GetString(HexStringToBytes(Globals.DefaultPrinterInitString));
59
+            }
60
+            else
61
+            {
62
+                initCodes = "";
63
+            }
64
+
42 65
             if (GetSavedParameterAsBoolean(db, "EnableBoldPrinting"))
43 66
             {
44
-                hex += "1B45"; // Emphasize on
67
+                initCodes += Printer.EMPHASISE_ON;
68
+            }
69
+
70
+            switch (printMode)
71
+            {
72
+                case PrintMode.Manual12CPI:
73
+                    return new PrintSettings
74
+                    {
75
+                        InitCodes = initCodes,
76
+                        PinCpi = 12,
77
+                        VoucherCpi = 12,
78
+                        PinStartCodes = "",
79
+                        PinEndCodes = ""
80
+                    };
81
+                case PrintMode.Manual10CPI:
82
+                    return new PrintSettings
83
+                    {
84
+                        InitCodes = initCodes,
85
+                        PinCpi = 10,
86
+                        VoucherCpi = 10,
87
+                        PinStartCodes = "",
88
+                        PinEndCodes = ""
89
+                    };
90
+                case PrintMode.MixedCPI:
91
+                    return new PrintSettings
92
+                    {
93
+                        InitCodes = initCodes,
94
+                        PinCpi = 10,
95
+                        VoucherCpi = 12,
96
+                        PinStartCodes = Printer.CHARPITCHPICO,
97
+                        PinEndCodes = Printer.CHARPITCHELITE
98
+                    };
99
+                default:
100
+                    throw new Exception("Invalid print mode");
45 101
             }
46
-            return Encoding.ASCII.GetString(HexStringToBytes(hex));
47 102
         }
48 103
 
49 104
         public static string TrimRepeats(string value, string substring)
@@ -431,6 +486,63 @@ namespace BulkPrinting
431 486
                 new SQLiteParameter("@Value", Convert.ToString(value))) > 0;
432 487
         }
433 488
 
489
+        public static string PadBoth(string value, int width)
490
+        {
491
+            if (value.Length >= width)
492
+            {
493
+                return value.Substring(0, width);
494
+            }
495
+            else
496
+            {
497
+                int remainder = width - value.Length;
498
+                int before = remainder / 2;
499
+                return new StringBuilder(width)
500
+                    .Append('-', before)
501
+                    .Append(value)
502
+                    .Append('-', remainder - before)
503
+                    .ToString();
504
+            }
505
+        }
506
+
507
+        public static string FormatVoucherColumn(int column, int cpi, string contents)
508
+        {
509
+            string spacer = column == 3 ? " " : "";
510
+            if (cpi == 12)
511
+            {
512
+                return String.Format("{0}{1}      ", spacer, contents.PadRight(24).Substring(0, 24));
513
+            }
514
+            else if (cpi == 10)
515
+            {
516
+                return String.Format("{0}{1}     ", spacer, contents.PadRight(20).Substring(0, 20));
517
+            }
518
+            throw new Exception("Invalid print CPI");
519
+        }
520
+
521
+        public static string FormatPrintAlignmentRow(int cpi, string contents)
522
+        {
523
+            string block;
524
+            if (cpi == 12)
525
+            {
526
+                block = PadBoth(contents, 22);
527
+            }
528
+            else if (cpi == 10)
529
+            {
530
+                block = PadBoth(contents, 18);
531
+            }
532
+            else
533
+            {
534
+                throw new Exception("Invalid print CPI");
535
+            }
536
+            block = "[" + block + "]";
537
+
538
+            string row = "";
539
+            for (int col = 0; col < 5; col++)
540
+            {
541
+                row += FormatVoucherColumn(col, cpi, block);
542
+            }
543
+            return row;
544
+        }
545
+
434 546
         public static void PrintVouchers(DBHelper db, int BatchId, int StartSeqNo, int EndSeqNo)
435 547
         {
436 548
 
@@ -438,7 +550,6 @@ namespace BulkPrinting
438 550
             int RowCount = 0;
439 551
             int PageCount = (int) Math.Ceiling(((decimal)StartSeqNo)/20);
440 552
             int TotalCount = 0;
441
-            string SerialNumberTrimmed;
442 553
             bool IsReprint;
443 554
 
444 555
             string VendorId = GetSavedParameter(db, "VendorName").Trim();
@@ -446,16 +557,12 @@ namespace BulkPrinting
446 557
             {
447 558
                 VendorId = Globals.SessionData.Credentials.Payload.Vendor.id.ToString();
448 559
             }
449
-            else if (VendorId.Length > 24)
450
-            {
451
-                VendorId = VendorId.Substring(0, 24);
452
-            }
453 560
 
454
-            var PrinterInitString = GetPrinterInitString(db);
561
+            var printSettings = GetPrintSettings(db);
562
+
455 563
             int initJobID = Globals.MaxPrinter.Open("Vouchers");
456 564
             if (initJobID == 0) return;
457
-            Globals.MaxPrinter.Print(PrinterInitString.ToString());
458
-            //Globals.MaxPrinter.Close();
565
+            Globals.MaxPrinter.Print(printSettings.InitCodes);
459 566
 
460 567
             List<EventLog> LogEvents = new List<EventLog>();
461 568
 
@@ -467,8 +574,6 @@ namespace BulkPrinting
467 574
             {
468 575
                 using (SQLiteDataReader read = Command.ExecuteReader())
469 576
                 {
470
-                    //int JobID = Globals.MaxPrinter.Open("Vouchers");
471
-                    //if (JobID == 0) return;
472 577
                     while (read.Read())
473 578
                     {
474 579
                         VoucherCount++;
@@ -491,40 +596,35 @@ namespace BulkPrinting
491 596
                         if (VoucherCount >= 5 || TotalCount == (EndSeqNo - StartSeqNo))
492 597
                         {
493 598
                             RowCount++;
494
-                            string PrintRow = "\r\n\n\n\x1B\x50  ";
599
+                            string PrintRow = "\r\n\n\n  " + printSettings.PinStartCodes;
495 600
                             for (int Column = 0; Column < VoucherRow.Count(); Column++)
496 601
                             {
497 602
                                 IndividualVoucher = VoucherRow[Column];
498
-                                PrintRow += (Column == 3 ? " " : "") + (IndividualVoucher.DecryptedPIN).PadRight(25, ' ');
603
+                                PrintRow += FormatVoucherColumn(Column, printSettings.PinCpi, IndividualVoucher.DecryptedPIN);
499 604
                             }
500
-                            PrintRow = PrintRow.TrimEnd() + "\x1B\x4D\r\n\n  ";
605
+                            PrintRow = PrintRow.TrimEnd() + printSettings.PinEndCodes + "\r\n\n  ";
501 606
                             for (int Column = 0; Column < VoucherRow.Count(); Column++)
502 607
                             {
503 608
                                 IndividualVoucher = VoucherRow[Column];
504
-                                SerialNumberTrimmed = IndividualVoucher.Serial;
505
-                                if (SerialNumberTrimmed.Length > 24)
506
-                                {
507
-                                    SerialNumberTrimmed = SerialNumberTrimmed.Substring(0, 24);
508
-                                }
509
-                                PrintRow += (Column == 3 ? " " : "") + SerialNumberTrimmed.PadRight(30, ' ');
609
+                                PrintRow += FormatVoucherColumn(Column, printSettings.VoucherCpi, IndividualVoucher.Serial);
510 610
                             }
511 611
                             PrintRow = PrintRow.TrimEnd() + "\r\n  ";
512 612
                             for (int Column = 0; Column < VoucherRow.Count(); Column++)
513 613
                             {
514 614
                                 IndividualVoucher = VoucherRow[Column];
515 615
                                 int CurrentPage = (int)Math.Ceiling(((decimal)IndividualVoucher.SequenceNumber) / 20);
516
-                                PrintRow += (Column == 3 ? " " : "") + String.Format("{0}/{1}/{2}", IndividualVoucher.BatchId, IndividualVoucher.SequenceNumber, PageCount).PadRight(30, ' ');
616
+                                PrintRow += FormatVoucherColumn(Column, printSettings.VoucherCpi, String.Format("{0}/{1}/{2}", IndividualVoucher.BatchId, IndividualVoucher.SequenceNumber, PageCount));
517 617
                             }
518 618
                             PrintRow = PrintRow.TrimEnd() + "\r\n  ";
519 619
                             for (int Column = 0; Column < VoucherRow.Count(); Column++)
520 620
                             {
521 621
                                 IndividualVoucher = VoucherRow[Column];
522
-                                PrintRow += (Column == 3 ? " " : "") + IndividualVoucher.Description.PadRight(30, ' ');
622
+                                PrintRow += FormatVoucherColumn(Column, printSettings.VoucherCpi, IndividualVoucher.Description);
523 623
                             }
524 624
                             PrintRow = PrintRow.TrimEnd() + "\r\n  ";
525 625
                             for (int Column = 0; Column < VoucherRow.Count(); Column++)
526 626
                             {
527
-                                PrintRow += (Column == 3 ? " " : "") + VendorId.PadRight(30, ' ');
627
+                                PrintRow += FormatVoucherColumn(Column, printSettings.VoucherCpi, VendorId);
528 628
                             }
529 629
 
530 630
                             PrintRow = PrintRow.TrimEnd() + "\r\n\n\n\n\n\n\n\n\n\n";
@@ -542,15 +642,12 @@ namespace BulkPrinting
542 642
                             VoucherCount = 0;
543 643
                             if (RowCount >= 4)
544 644
                             {
545
-                                //Globals.MaxPrinter.NewPage();
546 645
                                 PageCount++;
547 646
                                 RowCount = 0;
548
-                                //Globals.MaxPrinter.GetJobInfo(JobID);
549 647
                             }
550 648
                         }
551 649
                         TotalCount++;
552 650
                     }
553
-                    //Globals.MaxPrinter.Close();
554 651
                 }
555 652
             }
556 653
             Globals.MaxPrinter.Close();