|
|
@@ -1,8 +1,9 @@
|
|
1
|
1
|
using System;
|
|
|
2
|
+using System.Drawing;
|
|
2
|
3
|
using System.Drawing.Printing;
|
|
3
|
4
|
using System.Windows.Forms;
|
|
4
|
5
|
using System.Runtime.InteropServices;
|
|
5
|
|
-using System.Text;
|
|
|
6
|
+using System.Collections.Generic;
|
|
6
|
7
|
|
|
7
|
8
|
namespace BulkPrinting
|
|
8
|
9
|
{
|
|
|
@@ -87,7 +88,7 @@ namespace BulkPrinting
|
|
87
|
88
|
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
|
|
88
|
89
|
|
|
89
|
90
|
[DllImport("winspool.drv", EntryPoint = "GetJobA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
|
|
90
|
|
- private static extern bool GetJob (IntPtr hPrinter, Int32 JobId, Int32 Level, out byte[] pJob, Int32 cbBuf, out Int32 pcbNeeded);
|
|
|
91
|
+ private static extern bool GetJob(IntPtr hPrinter, Int32 JobId, Int32 Level, out byte[] pJob, Int32 cbBuf, out Int32 pcbNeeded);
|
|
91
|
92
|
|
|
92
|
93
|
[DllImport("winspool.drv", EntryPoint = "SetJobA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
|
|
93
|
94
|
private static extern bool SetJob(IntPtr hPrinter, int JobId, int Level, out byte pJob, int Command_Renamed);
|
|
|
@@ -128,7 +129,8 @@ namespace BulkPrinting
|
|
128
|
129
|
return false;
|
|
129
|
130
|
}
|
|
130
|
131
|
|
|
131
|
|
- public bool GetJobInfo(int JobID) {
|
|
|
132
|
+ public bool GetJobInfo(int JobID)
|
|
|
133
|
+ {
|
|
132
|
134
|
//JOB_INFO_1 JobInfo = new JOB_INFO_1();
|
|
133
|
135
|
byte[] JobInfoByte;
|
|
134
|
136
|
int pcbNeeded;
|
|
|
@@ -186,9 +188,132 @@ namespace BulkPrinting
|
|
186
|
188
|
else return true;
|
|
187
|
189
|
}
|
|
188
|
190
|
|
|
189
|
|
- public void NewPage() {
|
|
|
191
|
+ public void NewPage()
|
|
|
192
|
+ {
|
|
190
|
193
|
EndPagePrinter(HandlePrinter);
|
|
191
|
194
|
StartPagePrinter(HandlePrinter);
|
|
192
|
195
|
}
|
|
|
196
|
+
|
|
|
197
|
+
|
|
|
198
|
+ /****************************************************************************************************************************/
|
|
|
199
|
+
|
|
|
200
|
+
|
|
|
201
|
+
|
|
|
202
|
+ private static PrintDocument pdoc = null;
|
|
|
203
|
+ private static List<OrderList> OrderReportList;
|
|
|
204
|
+ private static int ListLoc = 0;
|
|
|
205
|
+ private static int pages = 0;
|
|
|
206
|
+
|
|
|
207
|
+ public static void PrintOrderReport(List<OrderList> OrderPrintList)
|
|
|
208
|
+ {
|
|
|
209
|
+ ListLoc = 0;
|
|
|
210
|
+ pages = 0;
|
|
|
211
|
+ OrderReportList = OrderPrintList;
|
|
|
212
|
+ PrintDialog pd = new PrintDialog();
|
|
|
213
|
+ pd.UseEXDialog = true; //Required for AMD64 based processors
|
|
|
214
|
+ pdoc = new PrintDocument();
|
|
|
215
|
+ PrinterSettings ps = new PrinterSettings();
|
|
|
216
|
+ Font font = new Font("Courier New", 15);
|
|
|
217
|
+
|
|
|
218
|
+
|
|
|
219
|
+ PaperSize psize = new PaperSize("Custom", 100, 200);
|
|
|
220
|
+
|
|
|
221
|
+ pd.Document = pdoc;
|
|
|
222
|
+ pd.Document.DefaultPageSettings.PaperSize = psize;
|
|
|
223
|
+ pdoc.DefaultPageSettings.PaperSize.Height = 820;
|
|
|
224
|
+
|
|
|
225
|
+ pdoc.DefaultPageSettings.PaperSize.Width = 520;
|
|
|
226
|
+
|
|
|
227
|
+ pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
|
|
|
228
|
+ DialogResult result = pd.ShowDialog();
|
|
|
229
|
+ if (result == DialogResult.OK)
|
|
|
230
|
+ {
|
|
|
231
|
+ pdoc.DefaultPageSettings.PrinterSettings.PrintRange = pd.PrinterSettings.PrintRange;
|
|
|
232
|
+ /*
|
|
|
233
|
+ PrintPreviewDialog pp = new PrintPreviewDialog();
|
|
|
234
|
+ pp.Document = pdoc;
|
|
|
235
|
+ result = pp.ShowDialog();
|
|
|
236
|
+ if (result == DialogResult.OK)
|
|
|
237
|
+ {
|
|
|
238
|
+ */
|
|
|
239
|
+ pdoc.Print();
|
|
|
240
|
+ //}
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ class Columns
|
|
|
246
|
+ {
|
|
|
247
|
+ public static int OrderDate = 0;
|
|
|
248
|
+ public static int OrderReference = 70;
|
|
|
249
|
+ public static int User = 150;
|
|
|
250
|
+ public static int OrderItems = 250;
|
|
|
251
|
+ public static int QtyOrdered = 430;
|
|
|
252
|
+ public static int QtyDelivered = 500;
|
|
|
253
|
+ public static int Cost = 580;
|
|
|
254
|
+ public static int Balance = 630;
|
|
|
255
|
+ }
|
|
|
256
|
+
|
|
|
257
|
+ public static void pdoc_PrintPage(object sender, PrintPageEventArgs e)
|
|
|
258
|
+ {
|
|
|
259
|
+ //Header
|
|
|
260
|
+ Graphics graphics = e.Graphics;
|
|
|
261
|
+ Font font = new Font("Arial", 10);
|
|
|
262
|
+ float fontHeight = font.GetHeight();
|
|
|
263
|
+ int startX = 50;
|
|
|
264
|
+ int startY = 55;
|
|
|
265
|
+ int Offset = 40;
|
|
|
266
|
+
|
|
|
267
|
+ var a = Globals.SessionData.AccessToken;
|
|
|
268
|
+
|
|
|
269
|
+ graphics.DrawString("R-Group Order Report", new Font("Arial", 28), new SolidBrush(Color.Black), startX, startY + Offset);
|
|
|
270
|
+ graphics.DrawString(Globals.SessionData.Credentials.Payload.User.Account.Name, new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + 500, startY + Offset);
|
|
|
271
|
+ graphics.DrawString(Globals.SessionData.Credentials.Payload.User.FirstName + " " + Globals.SessionData.Credentials.Payload.User.Surname, new Font("Arial", 10), new SolidBrush(Color.Black), startX + 500, startY + Offset + 20);
|
|
|
272
|
+ graphics.DrawString(DateTime.Now.ToString(), new Font("Arial", 10), new SolidBrush(Color.Black), startX + 500, startY + Offset + 40);
|
|
|
273
|
+
|
|
|
274
|
+ Offset = Offset + 90;
|
|
|
275
|
+
|
|
|
276
|
+ graphics.DrawString("Date", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.OrderDate, startY + Offset);
|
|
|
277
|
+ graphics.DrawString("Reference", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.OrderReference, startY + Offset);
|
|
|
278
|
+ graphics.DrawString("User", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.User, startY + Offset);
|
|
|
279
|
+ graphics.DrawString("Items", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.OrderItems, startY + Offset);
|
|
|
280
|
+ graphics.DrawString("Ordered", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.QtyOrdered, startY + Offset);
|
|
|
281
|
+ graphics.DrawString("Delivered", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.QtyDelivered, startY + Offset);
|
|
|
282
|
+ graphics.DrawString("Cost", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.Cost, startY + Offset);
|
|
|
283
|
+ graphics.DrawString("Balance", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.Balance, startY + Offset);
|
|
|
284
|
+ graphics.DrawLine(new Pen(Color.Black, 2), new Point(startX, startY + Offset + 20), new Point(startX + 700, startY + Offset + 20));
|
|
|
285
|
+ Offset = Offset + 10;
|
|
|
286
|
+
|
|
|
287
|
+ while (ListLoc < OrderReportList.Count)
|
|
|
288
|
+ {
|
|
|
289
|
+ Offset = Offset + 40;
|
|
|
290
|
+
|
|
|
291
|
+ graphics.DrawString(OrderReportList[ListLoc].OrderDate, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.OrderDate, startY + Offset);
|
|
|
292
|
+ graphics.DrawString(OrderReportList[ListLoc].OrderReference, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.OrderReference, startY + Offset);
|
|
|
293
|
+ graphics.DrawString(OrderReportList[ListLoc].User, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.User, startY + Offset);
|
|
|
294
|
+
|
|
|
295
|
+ foreach (OrderReportLine OrderLine in OrderReportList[ListLoc].OrderLines)
|
|
|
296
|
+ {
|
|
|
297
|
+ graphics.DrawString(OrderLine.OrderItem, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.OrderItems, startY + Offset);
|
|
|
298
|
+ graphics.DrawString(OrderLine.QtyOrdered, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.QtyOrdered, startY + Offset);
|
|
|
299
|
+ graphics.DrawString(OrderLine.QtyDelivered, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.QtyDelivered, startY + Offset);
|
|
|
300
|
+ graphics.DrawString(OrderLine.Cost, new Font("Arial", 10), new SolidBrush(Color.Black), startX + Columns.Cost, startY + Offset);
|
|
|
301
|
+ Offset = Offset + 20;
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ graphics.DrawString("Total", new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.QtyDelivered, startY + Offset);
|
|
|
305
|
+ graphics.DrawString(OrderReportList[ListLoc].OrderCost, new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.Cost, startY + Offset);
|
|
|
306
|
+ graphics.DrawString(OrderReportList[ListLoc].Balance, new Font("Arial", 10, FontStyle.Bold), new SolidBrush(Color.Black), startX + Columns.Balance, startY + Offset);
|
|
|
307
|
+ ListLoc += 1;
|
|
|
308
|
+
|
|
|
309
|
+ if (Offset > 800)
|
|
|
310
|
+ {
|
|
|
311
|
+ Offset = 50;
|
|
|
312
|
+ e.HasMorePages = true;
|
|
|
313
|
+ continue;
|
|
|
314
|
+ }
|
|
|
315
|
+ }
|
|
|
316
|
+ }
|
|
193
|
317
|
}
|
|
|
318
|
+
|
|
194
|
319
|
}
|