소스 검색

Added Print Order Report functionality (graphical printing)
Added InternalReference functionality to allow several batches to be tied together in one order
Added new Migration plus extra Migration handler

Brett Credo 8 년 전
부모
커밋
42e0247500

+ 17 - 8
BulkPrinting/BulkPrinting/BatchForm.cs

@@ -72,7 +72,8 @@ namespace BulkPrinting
72 72
 
73 73
             dgvBatches.Columns.Add("Id", "ID");
74 74
             dgvBatches.Columns.Add("OrderDate", "Order Date");
75
-            if (CanOrder) dgvBatches.Columns.Add("OrderReference", "Order Reference");
75
+            if (CanOrder) dgvBatches.Columns.Add("OrderReference", "Customer Reference");
76
+            if (CanOrder) dgvBatches.Columns.Add("InternalReference", "Order Reference");
76 77
             dgvBatches.Columns.Add("NetworkName", "Network Name");
77 78
             dgvBatches.Columns.Add("ProductDescription", "Product Description");
78 79
             dgvBatches.Columns.Add("VoucherType", "Voucher Type");
@@ -82,7 +83,7 @@ namespace BulkPrinting
82 83
             if (CanOrder) dgvBatches.Columns.Add("ReadyForDownload", "Batch Ready for Download");
83 84
             dgvBatches.Columns.Add("PrintedQuantity", "Quantity Printed");
84 85
             if (CanExport) dgvBatches.Columns.Add("Exported", "Exported Batch");
85
-            Sql = "Select Id,OrderDate,OrderReference,NetworkName,ProductDescription,VoucherType,FaceValue,RequestedQuantity,DeliveredQuantity,ReadyForDownload From Batch WHERE OrderDate BETWEEN @startdate AND @enddate";
86
+            Sql = "Select Id,OrderDate,OrderReference,InternalReference,NetworkName,ProductDescription,VoucherType,FaceValue,RequestedQuantity,DeliveredQuantity,ReadyForDownload From Batch WHERE OrderDate BETWEEN @startdate AND @enddate";
86 87
 
87 88
 
88 89
 
@@ -104,6 +105,8 @@ namespace BulkPrinting
104 105
                         BatchEvents.Add(BatchId, new BatchEvent());
105 106
                     }
106 107
                     int DeliveredQuantity = int.Parse(read["DeliveredQuantity"].ToString());
108
+
109
+                    //Filters to exclude rows that don't match
107 110
                     if (rdoFilterPrinted.Checked)
108 111
                     {
109 112
                         if (BatchEvents[BatchId].PrintCount == 0)
@@ -136,15 +139,21 @@ namespace BulkPrinting
136 139
                             continue;
137 140
                         }
138 141
                     }
142
+
139 143
                     var BatchRow = new object[] {
140 144
                         BatchId,
141
-                        read["OrderDate"],
142
-                        read["OrderReference"],
143
-                        read["NetworkName"].ToString(),
144
-                        read["ProductDescription"].ToString(),
145
-                        Enum.Parse(typeof(Vouchertype), read["VoucherType"].ToString()).ToString(),
146
-                        "R" +((decimal)read["FaceValue"]).ToString("0.##")};
145
+                        read["OrderDate"] };
146
+                    if (CanOrder)
147
+                    {
148
+                        BatchRow = BatchRow.Concat(new[] { read["OrderReference"] }).ToArray();
149
+                        BatchRow = BatchRow.Concat(new[] { read["InternalReference"] }).ToArray();
150
+                    }
151
+                    BatchRow = BatchRow.Concat(new[] { read["NetworkName"].ToString() }).ToArray();
152
+                    BatchRow = BatchRow.Concat(new[] { read["ProductDescription"].ToString() }).ToArray();
153
+                    BatchRow = BatchRow.Concat(new[] { Enum.Parse(typeof(Vouchertype), read["VoucherType"].ToString()).ToString() }).ToArray();
154
+                    BatchRow = BatchRow.Concat(new[] { "R" + ((decimal)read["FaceValue"]).ToString("0.##") }).ToArray();
147 155
 
156
+                    
148 157
                     if (CanOrder)
149 158
                         BatchRow = BatchRow.Concat(new[] { read["RequestedQuantity"] }).ToArray();
150 159
 

+ 32 - 0
BulkPrinting/BulkPrinting/Migrations.cs

@@ -6,6 +6,22 @@ namespace BulkPrinting
6 6
 {
7 7
     class Migrations
8 8
     {
9
+        public static void CheckMigrations() {
10
+
11
+            string sql;
12
+            SQLiteCommand Command;
13
+            sql = "SELECT Value FROM Parameters WHERE Key = 'Migration'";
14
+            Command = new SQLiteCommand(sql, Globals.DBConnection);
15
+            var result = Command.ExecuteScalar();
16
+
17
+            if (result == null) {
18
+                Migration1();
19
+            }
20
+            //Add further migration executions here - Migration = '1', '2', '3' etc
21
+
22
+            return;
23
+        }
24
+
9 25
         public static bool InitialVersion() {
10 26
             string MaxDBPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Configuration.MaxDataPathName);
11 27
             string MaxDBFilePath = Path.Combine(MaxDBPath, Configuration.MaxDBFileName);
@@ -98,7 +114,23 @@ namespace BulkPrinting
98 114
 
99 115
             command = new SQLiteCommand(sql, Globals.DBConnection);
100 116
             command.ExecuteNonQuery();
117
+            
118
+            return true; //Initial Migration doesn't trigger any others, as a Migration check is performed later in the login
119
+        }
120
+
121
+        public static bool Migration1 (){
122
+            string sql = "ALTER TABLE Orders ADD COLUMN InternalReference VARCHAR(32)";
123
+            SQLiteCommand command = new SQLiteCommand(sql, Globals.DBConnection);
124
+            command.ExecuteNonQuery();
125
+
126
+            sql = "ALTER TABLE Batch ADD COLUMN InternalReference VARCHAR(32)";
127
+            command = new SQLiteCommand(sql, Globals.DBConnection);
128
+            command.ExecuteNonQuery();
101 129
 
130
+            //First Migration value - future values to be updated
131
+            sql = "INSERT INTO Parameters (Key, Value) VALUES ('Migration','1')";
132
+            command = new SQLiteCommand(sql, Globals.DBConnection);
133
+            command.ExecuteNonQuery();
102 134
 
103 135
             return true;
104 136
         }

+ 31 - 1
BulkPrinting/BulkPrinting/Models.cs

@@ -54,6 +54,9 @@ namespace BulkPrinting
54 54
 
55 55
         [JsonProperty("customerReference")]
56 56
         public string CustomerReference { get; set; }
57
+
58
+        [JsonProperty("internalReference")]
59
+        public string InternalReference { get; set; }
57 60
     }
58 61
 
59 62
     public class Warehouse
@@ -324,6 +327,9 @@ namespace BulkPrinting
324 327
         [JsonProperty("orderReference")]
325 328
         public string OrderReference { get; set; }
326 329
 
330
+        [JsonProperty("internalReference")]
331
+        public string InternalReference { get; set; }
332
+
327 333
         [JsonProperty("networkId")]
328 334
         public int NetworkId { get; set; }
329 335
 
@@ -501,8 +507,32 @@ namespace BulkPrinting
501 507
         public bool Retry { get; set; }
502 508
     }
503 509
 
504
-    public class RemoteVendorEventResponse {
510
+    public class RemoteVendorEventResponse
511
+    {
505 512
         [JsonProperty("lastVendorEventRemoteId")]
506 513
         public int LastVendorEventRemoteId { get; set; }
507 514
     }
515
+
516
+    public class InternalReferenceResponse
517
+    {
518
+        [JsonProperty("internalReference")]
519
+        public string InternalReference { get; set; }
520
+    }
521
+
522
+    public class OrderList
523
+    {
524
+        public string OrderDate;
525
+        public string OrderReference;
526
+        public string User;
527
+        public string OrderCost;
528
+        public string Balance;
529
+        public List<OrderReportLine> OrderLines;
530
+    }
531
+
532
+    public class OrderReportLine {
533
+        public string OrderItem;
534
+        public string QtyOrdered;
535
+        public string QtyDelivered;
536
+        public string Cost;
537
+    }
508 538
 }

+ 4 - 1
BulkPrinting/BulkPrinting/OrderForm.cs

@@ -118,12 +118,14 @@ namespace BulkPrinting
118 118
             OrderReviewMessage += "Would you like to proceed with the order?";
119 119
             DialogResult PlaceOrder = MessageBox.Show(OrderReviewMessage, "Proceed?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
120 120
             if (PlaceOrder == DialogResult.Yes) {
121
-                string Sql = "INSERT INTO Orders (UserId,UserName,OrderDate,OrderCost,BalanceAfterOrder) VALUES (@userid,@username,datetime('now'),@ordercost,@balanceafterorder)";
121
+                string InternalReference = Utility.GetNextInternalReference();
122
+                string Sql = "INSERT INTO Orders (UserId,UserName,OrderDate,OrderCost,BalanceAfterOrder,InternalReference) VALUES (@userid,@username,datetime('now'),@ordercost,@balanceafterorder,@internalreference)";
122 123
                 SQLiteCommand Command = new SQLiteCommand(Sql, Globals.DBConnection);
123 124
                 Command.Parameters.Add(new SQLiteParameter("@userid", Globals.SessionData.Credentials.Payload.User.Id));
124 125
                 Command.Parameters.Add(new SQLiteParameter("@username", Globals.SessionData.Credentials.Payload.User.FirstName + " " + Globals.SessionData.Credentials.Payload.User.Surname));
125 126
                 Command.Parameters.Add(new SQLiteParameter("@ordercost", TotalCost));
126 127
                 Command.Parameters.Add(new SQLiteParameter("@balanceafterorder", Globals.SessionData.Credentials.Payload.User.Account.Balance - TotalCost));
128
+                Command.Parameters.Add(new SQLiteParameter("@internalreference", InternalReference));
127 129
                 Command.ExecuteNonQuery();
128 130
 
129 131
                 Sql = "SELECT MAX(Id) FROM Orders";
@@ -160,6 +162,7 @@ namespace BulkPrinting
160 162
                         OrderData.ProductId = OrderedItem.ProductId;
161 163
                         OrderData.Quantity = OrderedItem.Quantity;
162 164
                         OrderData.CustomerReference = CustomerReference;
165
+                        OrderData.InternalReference = InternalReference;
163 166
                         BatchListing OrderedBatch = new BatchListing();
164 167
                         bool OrderResult = Utility.RESTRequest<OrderPlacementData, BatchListing>(OrderData, ref OrderedBatch, "/api/batches/");
165 168
                         //TODO: Handle failed order

+ 18 - 0
BulkPrinting/BulkPrinting/OrderReport.Designer.cs

@@ -35,6 +35,7 @@
35 35
             this.dtpEndDate = new System.Windows.Forms.DateTimePicker();
36 36
             this.dgvOrderReport = new System.Windows.Forms.DataGridView();
37 37
             this.btnSaveToCSV = new System.Windows.Forms.Button();
38
+            this.brn_Print = new System.Windows.Forms.Button();
38 39
             ((System.ComponentModel.ISupportInitialize)(this.dgvOrderReport)).BeginInit();
39 40
             this.SuspendLayout();
40 41
             // 
@@ -108,12 +109,28 @@
108 109
             this.btnSaveToCSV.UseVisualStyleBackColor = false;
109 110
             this.btnSaveToCSV.Click += new System.EventHandler(this.btnSaveToCSV_Click);
110 111
             // 
112
+            // brn_Print
113
+            // 
114
+            this.brn_Print.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
115
+            this.brn_Print.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(132)))), ((int)(((byte)(186)))));
116
+            this.brn_Print.FlatAppearance.BorderColor = System.Drawing.Color.Black;
117
+            this.brn_Print.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
118
+            this.brn_Print.ForeColor = System.Drawing.Color.White;
119
+            this.brn_Print.Location = new System.Drawing.Point(1056, 7);
120
+            this.brn_Print.Name = "brn_Print";
121
+            this.brn_Print.Size = new System.Drawing.Size(104, 23);
122
+            this.brn_Print.TabIndex = 3;
123
+            this.brn_Print.Text = "Print";
124
+            this.brn_Print.UseVisualStyleBackColor = false;
125
+            this.brn_Print.Click += new System.EventHandler(this.btnPrint_Click);
126
+            // 
111 127
             // OrderReport
112 128
             // 
113 129
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
114 130
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
115 131
             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(7)))), ((int)(((byte)(63)))), ((int)(((byte)(145)))));
116 132
             this.ClientSize = new System.Drawing.Size(1282, 616);
133
+            this.Controls.Add(this.brn_Print);
117 134
             this.Controls.Add(this.btnSaveToCSV);
118 135
             this.Controls.Add(this.dgvOrderReport);
119 136
             this.Controls.Add(this.dtpEndDate);
@@ -139,5 +156,6 @@
139 156
         private System.Windows.Forms.DateTimePicker dtpEndDate;
140 157
         private System.Windows.Forms.DataGridView dgvOrderReport;
141 158
         private System.Windows.Forms.Button btnSaveToCSV;
159
+        private System.Windows.Forms.Button brn_Print;
142 160
     }
143 161
 }

+ 61 - 6
BulkPrinting/BulkPrinting/OrderReport.cs

@@ -24,7 +24,7 @@ namespace BulkPrinting
24 24
         {
25 25
             dgvOrderReport.Rows.Clear();
26 26
             dgvOrderReport.Columns.Clear();
27
-            dgvOrderReport.Columns.Add("Id", "Order ID");
27
+            dgvOrderReport.Columns.Add("Reference", "Order Reference");
28 28
             dgvOrderReport.Columns.Add("UserId", "User ID");
29 29
             dgvOrderReport.Columns.Add("UserName", "User Name");
30 30
             dgvOrderReport.Columns.Add("OrderDate", "Order Date");
@@ -32,8 +32,10 @@ namespace BulkPrinting
32 32
             dgvOrderReport.Columns.Add("OrderCost", "Total Order Cost");
33 33
             dgvOrderReport.Columns.Add("BalanceAfterOrder", "Balance After Order");
34 34
             dgvOrderReport.Columns.Add("Cost", "Individual Product Cost");
35
-            dgvOrderReport.Columns.Add("Quantity", "Quantity of Vouchers");
36
-            string Sql = "Select o.Id,o.UserId,o.UserName,o.OrderDate,oi.Description,o.OrderCost,o.BalanceAfterOrder,oi.Cost,oi.Quantity From Orders o LEFT JOIN OrderedItems oi on oi.OrderId = o.Id WHERE o.OrderDate BETWEEN @startdate AND @enddate";
35
+            dgvOrderReport.Columns.Add("OrderedQuantity", "Ordered Quantity");
36
+            dgvOrderReport.Columns.Add("DeliveredQuantity", "Delivered Quantity");
37
+            string Sql = "Select o.Id,o.InternalReference,o.UserId,o.UserName,o.OrderDate,oi.Description,o.OrderCost,o.BalanceAfterOrder,oi.Cost,b.RequestedQuantity,b.DeliveredQuantity From Orders o LEFT JOIN OrderedItems oi on oi.OrderId = o.Id LEFT JOIN Batch b ON b.InternalReference = o.InternalReference AND b.ProductId = oi.ProductId WHERE o.OrderDate BETWEEN @startdate AND @enddate";
38
+
37 39
             SQLiteCommand Command = new SQLiteCommand(Sql, Globals.DBConnection);
38 40
             CultureInfo IVC = CultureInfo.InvariantCulture;
39 41
             Command.Parameters.Add(new SQLiteParameter("@startdate", dtpStartDate.Value.ToString("yyyy-MM-dd 00:00:00", IVC)));
@@ -44,7 +46,6 @@ namespace BulkPrinting
44 46
                 while (read.Read())
45 47
                 {
46 48
                     dgvOrderReport.Rows.Add(new object[] {
47
-                    read.GetValue(0).ToString(),
48 49
                     read.GetValue(1).ToString(),
49 50
                     read.GetValue(2).ToString(),
50 51
                     read.GetValue(3).ToString(),
@@ -53,6 +54,8 @@ namespace BulkPrinting
53 54
                     read.GetValue(6).ToString(),
54 55
                     read.GetValue(7).ToString(),
55 56
                     read.GetValue(8).ToString(),
57
+                    read.GetValue(9).ToString(),
58
+                    read.GetValue(10).ToString(),
56 59
                 });
57 60
                 }
58 61
             }
@@ -83,9 +86,13 @@ namespace BulkPrinting
83 86
             {
84 87
                 using (StreamWriter OutputStream = new StreamWriter(SFD.OpenFile()))
85 88
                 {
86
-                    for (int i = 0; i < dgvOrderReport.RowCount - 1; i++)
89
+                    for (int j = 0; j < 10; j++)
90
+                    {
91
+                        OutputStream.Write(dgvOrderReport.Columns[j].Name + ",");
92
+                    }
93
+                    for (int i = 0; i < dgvOrderReport.RowCount; i++)
87 94
                     {
88
-                        for (int j = 0; j < 9; j++) {
95
+                        for (int j = 0; j < 10; j++) {
89 96
                             OutputStream.Write(dgvOrderReport.Rows[i].Cells[j].Value.ToString() + ",");
90 97
                         }
91 98
                         OutputStream.Write("\n");
@@ -95,6 +102,54 @@ namespace BulkPrinting
95 102
             }
96 103
         }
97 104
 
105
+        private void btnPrint_Click(object sender, EventArgs e)
106
+        {
107
+            string Sql = "Select o.Id,o.OrderDate,o.InternalReference,o.UserName,o.OrderCost,o.BalanceAfterOrder,oi.Description,oi.Cost,b.RequestedQuantity,b.DeliveredQuantity From Orders o LEFT JOIN OrderedItems oi on oi.OrderId = o.Id LEFT JOIN Batch b ON b.InternalReference = o.InternalReference AND b.ProductId = oi.ProductId WHERE o.OrderDate BETWEEN @startdate AND @enddate ORDER BY o.Id";
108
+            SQLiteCommand Command = new SQLiteCommand(Sql, Globals.DBConnection);
109
+            CultureInfo IVC = CultureInfo.InvariantCulture;
110
+            Command.Parameters.Add(new SQLiteParameter("@startdate", dtpStartDate.Value.ToString("yyyy-MM-dd 00:00:00", IVC)));
111
+            Command.Parameters.Add(new SQLiteParameter("@enddate", dtpEndDate.Value.ToString("yyyy-MM-dd 23:59:59", IVC)));
112
+
113
+            int CurrentId;
114
+            int LastId = -1;
115
+            List<OrderList> Orders = new List<OrderList>();
116
+            OrderList IndividualOrder = new OrderList();
117
+            using (SQLiteDataReader read = Command.ExecuteReader())
118
+            {
119
+                while (read.Read())
120
+                {
121
+                    CurrentId = int.Parse(read.GetValue(0).ToString());
122
+                    if (CurrentId != LastId)
123
+                    {
124
+                        if (IndividualOrder.OrderReference != null)
125
+                        {
126
+                            Orders.Add(IndividualOrder);
127
+                        }
128
+                        IndividualOrder = new OrderList();
129
+                        IndividualOrder.OrderLines = new List<OrderReportLine>();
130
+                        IndividualOrder.OrderDate = read.GetValue(1).ToString();
131
+                        IndividualOrder.OrderDate = IndividualOrder.OrderDate.Substring(1, IndividualOrder.OrderDate.IndexOf(" "));
132
+                        IndividualOrder.OrderReference = read.GetValue(2).ToString();
133
+                        IndividualOrder.User = read.GetValue(3).ToString();
134
+                        IndividualOrder.OrderCost = read.GetValue(4).ToString();
135
+                        IndividualOrder.Balance = read.GetValue(5).ToString();
136
+                        LastId = CurrentId;
137
+                    }
138
+                    OrderReportLine OrderLine = new OrderReportLine();
139
+                    OrderLine.OrderItem = read.GetValue(6).ToString();
140
+                    OrderLine.Cost = read.GetValue(7).ToString();
141
+                    OrderLine.QtyOrdered = read.GetValue(8).ToString();
142
+                    OrderLine.QtyDelivered = read.GetValue(9).ToString();
143
+                    IndividualOrder.OrderLines.Add(OrderLine);
144
+                }
145
+                if (IndividualOrder.OrderReference != null)
146
+                {
147
+                    Orders.Add(IndividualOrder);
148
+                }
149
+            }
150
+            Printer.PrintOrderReport(Orders);
151
+        }
152
+
98 153
         private void label1_Click(object sender, EventArgs e)
99 154
         {
100 155
 

+ 129 - 4
BulkPrinting/BulkPrinting/Printer.cs

@@ -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
 }

+ 1 - 0
BulkPrinting/BulkPrinting/UserLoginForm.cs

@@ -127,6 +127,7 @@ namespace BulkPrinting
127 127
                             Globals.DBConnection.SetPassword(Globals.SessionDatabasePassword);
128 128
                             Globals.DBConnection.Open();
129 129
                         }
130
+                        Migrations.CheckMigrations();
130 131
                         Utility.SyncLogs(); //Perform log sync before any logging happens to ensure synchronicity with server
131 132
                     }
132 133
                 }

+ 11 - 2
BulkPrinting/BulkPrinting/Utility.cs

@@ -293,6 +293,14 @@ namespace BulkPrinting
293 293
             return RequestedBatch;
294 294
         }
295 295
 
296
+        public static string GetNextInternalReference()
297
+        {
298
+            InternalReferenceResponse InternalReferenceRequest = new InternalReferenceResponse();
299
+            bool OrderResult = Utility.RESTRequest<InternalReferenceResponse>(ref InternalReferenceRequest, "/api/vendors/nextinternalref");
300
+            return InternalReferenceRequest.InternalReference;
301
+        }
302
+
303
+
296 304
         public static void DownloadBatch(Batch BatchItem)
297 305
         {
298 306
             if (BatchItem == null) {
@@ -304,8 +312,8 @@ namespace BulkPrinting
304 312
             Command.Parameters.Add(new SQLiteParameter("@id", BatchItem.Id));
305 313
             Command.ExecuteNonQuery();
306 314
 
307
-            Sql = "INSERT INTO Batch (Id,OrderDate,OrderGuid,OrderReference,NetworkId,NetworkName,ProductId,ProductDescription ,VoucherType,FaceValue,DiscountPercentage,RequestedQuantity,DeliveredQuantity,Cost,ReadyForDownload)" +
308
-                  "VALUES (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n,@o)";
315
+            Sql = "INSERT INTO Batch (Id,OrderDate,OrderGuid,OrderReference,NetworkId,NetworkName,ProductId,ProductDescription ,VoucherType,FaceValue,DiscountPercentage,RequestedQuantity,DeliveredQuantity,Cost,ReadyForDownload,InternalReference)" +
316
+                  "VALUES (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n,@o,@p)";
309 317
             Command = new SQLiteCommand(Sql, Globals.DBConnection);
310 318
             Command.Parameters.Add(new SQLiteParameter("@a", BatchRefresh.Id));
311 319
             Command.Parameters.Add(new SQLiteParameter("@b", BatchRefresh.OrderDate));
@@ -322,6 +330,7 @@ namespace BulkPrinting
322 330
             Command.Parameters.Add(new SQLiteParameter("@m", BatchRefresh.DeliveredQuantity));
323 331
             Command.Parameters.Add(new SQLiteParameter("@n", BatchRefresh.Cost));
324 332
             Command.Parameters.Add(new SQLiteParameter("@o", BatchRefresh.ReadyForDownload));
333
+            Command.Parameters.Add(new SQLiteParameter("@p", BatchRefresh.InternalReference));
325 334
             Command.ExecuteNonQuery();
326 335
             if (BatchRefresh.ReadyForDownload == true)
327 336
             {