Nessuna descrizione

BatchForm.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data.SQLite;
  5. using System.Drawing;
  6. using System.Globalization;
  7. using System.Security.Permissions;
  8. using System.Windows.Forms;
  9. namespace BulkPrinting
  10. {
  11. public partial class BatchForm : ObservedForm
  12. {
  13. private BatchDownloader BatchDownloader;
  14. private DownloadedLogSummariser DownloadedLogSummariser;
  15. public BatchForm()
  16. {
  17. InitializeComponent();
  18. }
  19. public void PopulateGrid()
  20. {
  21. bool CanOrder = Utility.CheckUserAccess(Utility.UserPermissions.BulkOrder);
  22. bool CanExport = Utility.CheckUserAccess(Utility.UserPermissions.BulkExport);
  23. dgvBatches.Rows.Clear();
  24. dgvBatches.Columns.Clear();
  25. dgvBatches.Columns.Add("Id", "ID");
  26. dgvBatches.Columns.Add("OrderDate", "Order Date");
  27. if (CanOrder) dgvBatches.Columns.Add("OrderReference", "Customer Reference");
  28. if (CanOrder) dgvBatches.Columns.Add("InternalReference", "Order Reference");
  29. dgvBatches.Columns.Add("NetworkName", "Network Name");
  30. dgvBatches.Columns.Add("ProductDescription", "Product Description");
  31. dgvBatches.Columns.Add("VoucherType", "Voucher Type");
  32. dgvBatches.Columns.Add("FaceValue", "Face Value");
  33. if (CanOrder) dgvBatches.Columns.Add("RequestedQuantity", "Quantity Ordered");
  34. dgvBatches.Columns.Add("DeliveredQuantity", "Quantity Delivered");
  35. if (CanOrder) dgvBatches.Columns.Add("ReadyForDownload", "Batch Ready for Download");
  36. dgvBatches.Columns.Add("Downloaded", "Downloaded");
  37. dgvBatches.Columns.Add("PrintedQuantity", "Quantity Printed");
  38. if (CanExport) dgvBatches.Columns.Add("Exported", "Exported Batch");
  39. var Sql = "Select Id,OrderDate,OrderReference,InternalReference,NetworkName,ProductDescription,VoucherType,FaceValue,RequestedQuantity,DeliveredQuantity,ReadyForDownload,Downloaded,PrintCount,ReprintCount,ExportCount,ReExportCount From Batch WHERE OrderDate BETWEEN @startdate AND @enddate";
  40. //Sql = "Select Id,OrderDate,OrderReference,InternalReference,NetworkName,ProductDescription,VoucherType,FaceValue,RequestedQuantity,DeliveredQuantity,ReadyForDownload,Downloaded,(SELECT COUNT(*) FROM Voucher WHERE Voucher.BatchId=Batch.Id) AS VoucherCount From Batch WHERE OrderDate BETWEEN @startdate AND @enddate";
  41. //dgvBatches.Columns.Add("VoucherCount", "Voucher Count");
  42. CultureInfo IVC = CultureInfo.InvariantCulture;
  43. using (var Command = Globals.DB.CreateCommand(Sql,
  44. new SQLiteParameter("@startdate", dtpFilterStartDate.Value.Date.ToString("yyyy-MM-dd 00:00:00", IVC)),
  45. new SQLiteParameter("@enddate", dtpFilterEndDate.Value.Date.ToString("yyyy-MM-dd 23:59:59", IVC))))
  46. {
  47. lblLoading.Hide();
  48. using (SQLiteDataReader read = Command.ExecuteReader())
  49. {
  50. while (read.Read())
  51. {
  52. int BatchId = int.Parse(read["Id"].ToString());
  53. int DeliveredQuantity = int.Parse(read["DeliveredQuantity"].ToString());
  54. int PrintCount = (int)read["PrintCount"];
  55. int ReprintCount = (int)read["ReprintCount"];
  56. int ExportCount = (int)read["ExportCount"];
  57. int ReExportCount = (int)read["ReExportCount"];
  58. //Filters to exclude rows that don't match
  59. if (rdoFilterPrinted.Checked)
  60. {
  61. if (PrintCount == 0)
  62. {
  63. continue;
  64. }
  65. }
  66. if (rdoFilterUnprinted.Checked)
  67. {
  68. if (PrintCount >= DeliveredQuantity)
  69. {
  70. continue;
  71. }
  72. }
  73. if (rdoFilterReprinted.Checked)
  74. {
  75. if (ReprintCount == 0)
  76. {
  77. continue;
  78. }
  79. }
  80. if (rdoFilterExported.Checked)
  81. {
  82. if (ExportCount == 0)
  83. {
  84. continue;
  85. }
  86. }
  87. else
  88. {
  89. if (ExportCount > 0)
  90. {
  91. continue;
  92. }
  93. }
  94. var BatchRow = new List<object>
  95. {
  96. BatchId,
  97. read["OrderDate"]
  98. };
  99. if (CanOrder)
  100. {
  101. BatchRow.Add(read["OrderReference"]);
  102. BatchRow.Add(read["InternalReference"]);
  103. }
  104. BatchRow.Add(read["NetworkName"].ToString());
  105. BatchRow.Add(read["ProductDescription"].ToString());
  106. BatchRow.Add(Enum.Parse(typeof(Vouchertype), read["VoucherType"].ToString()).ToString());
  107. BatchRow.Add("R" + ((decimal)read["FaceValue"]).ToString("0.##"));
  108. if (CanOrder)
  109. BatchRow.Add(read["RequestedQuantity"]);
  110. BatchRow.Add(read["DeliveredQuantity"]);
  111. if (CanOrder)
  112. BatchRow.Add(((bool)read["ReadyForDownload"] == true ? "Yes" : "No"));
  113. BatchRow.Add((bool)read["Downloaded"] ? "Yes" : "No");
  114. BatchRow.Add(PrintCount);
  115. if (CanExport)
  116. BatchRow.Add(ExportCount > 0 ? "Exported" : "");
  117. //BatchRow.Add(read["VoucherCount"]);
  118. dgvBatches.Rows.Add(BatchRow.ToArray());
  119. }
  120. dgvBatches.Sort(dgvBatches.Columns["OrderDate"], ListSortDirection.Descending);
  121. }
  122. }
  123. }
  124. private void BatchForm_Load(object sender, EventArgs e)
  125. {
  126. List<Button> LeftButtonList = new List<Button>();
  127. List<Button> RightButtonList = new List<Button>();
  128. LeftButtonList.Add(this.btnLogout);
  129. LeftButtonList.Add(this.btnOrderReport);
  130. LeftButtonList.Add(this.btnOrder);
  131. LeftButtonList.Add(this.btnPrint);
  132. LeftButtonList.Add(this.btnExport);
  133. RightButtonList.Add(this.btnViewPINs);
  134. RightButtonList.Add(this.btnReExport);
  135. RightButtonList.Add(this.btnReprint);
  136. foreach (Button b in LeftButtonList) {
  137. b.Hide();
  138. }
  139. foreach (Button b in RightButtonList) {
  140. b.Hide();
  141. }
  142. if (Globals.SessionMode == SessionModes.Online)
  143. {
  144. if (!Utility.CheckUserAccess(Utility.UserPermissions.BulkOrder))
  145. LeftButtonList.Remove(this.btnOrder);
  146. if (!Utility.CheckUserAccess(Utility.UserPermissions.CanPrintOnline))
  147. LeftButtonList.Remove(this.btnPrint);
  148. if (!Utility.CheckUserAccess(Utility.UserPermissions.CanReprintOnline)) {
  149. RightButtonList.Remove(this.btnReprint);
  150. rdoFilterReprinted.Hide();
  151. }
  152. }
  153. else if (Globals.SessionMode == SessionModes.Offline)
  154. {
  155. LeftButtonList.Remove(this.btnOrder);
  156. if (!Utility.CheckUserAccess(Utility.UserPermissions.CanPrintOffline))
  157. LeftButtonList.Remove(this.btnPrint);
  158. if (!Utility.CheckUserAccess(Utility.UserPermissions.CanReprintOffline)) {
  159. RightButtonList.Remove(this.btnReprint);
  160. rdoFilterReprinted.Hide();
  161. }
  162. }
  163. if (!Utility.CheckUserAccess(Utility.UserPermissions.BulkExport)) {
  164. LeftButtonList.Remove(this.btnExport);
  165. RightButtonList.Remove(this.btnReExport);
  166. rdoFilterExported.Hide();
  167. }
  168. if (!Utility.CheckUserAccess(Utility.UserPermissions.BulkViewPins))
  169. RightButtonList.Remove(this.btnViewPINs);
  170. int ButtonX = btnLogout.Location.X;
  171. int ButtonY = btnLogout.Location.Y;
  172. int ButtonSpacing = btnOrderReport.Location.X - ButtonX;
  173. foreach (Button b in LeftButtonList)
  174. {
  175. b.Location = new Point(ButtonX, ButtonY);
  176. b.Show();
  177. ButtonX += ButtonSpacing;
  178. }
  179. ButtonX = btnReprint.Location.X;
  180. RightButtonList.Reverse();
  181. foreach (Button b in RightButtonList)
  182. {
  183. b.Location = new Point(ButtonX, ButtonY);
  184. b.Show();
  185. ButtonX -= ButtonSpacing;
  186. }
  187. lblLoading.Show();
  188. dtpFilterStartDate.Value = DateTime.Now.AddMonths(-3);
  189. Globals.OpenBatches = new List<int>();
  190. var hwnd = new System.Runtime.InteropServices.HandleRef(this, Handle);
  191. BatchDownloader = new BatchDownloader(
  192. Globals.DB,
  193. () =>
  194. {
  195. // Refresh grid
  196. // DO NOT use Invoke as this can cause a deadlock if we are attempting to join the BatchDownloader after a cancel.
  197. // Also, use PostMessage rather than SendMessage as PostMessage doesn't wait for the message to be processed and
  198. // therefore won't block.
  199. Utility.PostMessage(hwnd, Utility.WM_USER, IntPtr.Zero, IntPtr.Zero);
  200. },
  201. () =>
  202. {
  203. // Trigger download log summarisation
  204. Utility.PostMessage(hwnd, Utility.WM_USER + 1, IntPtr.Zero, IntPtr.Zero);
  205. });
  206. BatchDownloader.Start();
  207. Utility.InitialiseUserLimits(Globals.DB);
  208. PopulateGrid();
  209. }
  210. [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  211. [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  212. protected override void WndProc(ref Message m)
  213. {
  214. if (m.Msg == Utility.WM_USER)
  215. {
  216. PopulateGrid();
  217. return;
  218. }
  219. else if (m.Msg == Utility.WM_USER + 1)
  220. {
  221. TriggerDownloadedLogSummarisation();
  222. return;
  223. }
  224. base.WndProc(ref m);
  225. }
  226. private void TriggerDownloadedLogSummarisation()
  227. {
  228. if (DownloadedLogSummariser == null)
  229. {
  230. var hwnd = new System.Runtime.InteropServices.HandleRef(this, Handle);
  231. DownloadedLogSummariser = new DownloadedLogSummariser(
  232. Globals.DB,
  233. () =>
  234. {
  235. // Refresh grid
  236. // DO NOT use Invoke as this can cause a deadlock if we are attempting to join the BatchDownloader after a cancel.
  237. // Also, use PostMessage rather than SendMessage as PostMessage doesn't wait for the message to be processed and
  238. // therefore won't block.
  239. Utility.PostMessage(hwnd, Utility.WM_USER, IntPtr.Zero, IntPtr.Zero);
  240. });
  241. DownloadedLogSummariser.Start();
  242. }
  243. }
  244. public void NewBatchAvailable()
  245. {
  246. BatchDownloader.CheckForNewBatches();
  247. }
  248. private void btnOrder_Click(object sender, EventArgs e)
  249. {
  250. OrderForm orderform = new OrderForm();
  251. orderform.SourceForm = this;
  252. orderform.Show();
  253. }
  254. private void btnPrint_Click(object sender, EventArgs e)
  255. {
  256. if (dgvBatches.SelectedRows.Count == 0)
  257. {
  258. MessageBox.Show("Please choose a batch to print.", "No batch selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  259. return;
  260. }
  261. if ((string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["Exported"].Index].Value != "")
  262. {
  263. MessageBox.Show("This batch has been exported previously. Exported batches cannot be printed.", "Cannot print batch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  264. return;
  265. }
  266. if (Utility.CheckUserAccess(Utility.UserPermissions.BulkOrder)) { //Only check for undownloaded vouchers if the user is able to see them
  267. if ((string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["ReadyForDownload"].Index].Value == "No") {
  268. MessageBox.Show("This batch is not fully downloaded and cannot be printed.\nPlease wait until \"Batch Ready For Download\" says Yes.\nThis may take several minutes depending on the size of\nthe order and available stock.", "Cannot print batch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  269. return;
  270. }
  271. }
  272. int BatchID = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["Id"].Index].Value;
  273. if (Globals.OpenBatches.Contains(BatchID)) {
  274. MessageBox.Show("A print dialog is already open for this batch","Cannot open print dialog",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
  275. return;
  276. }
  277. int DeliveredVoucherCount = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["DeliveredQuantity"].Index].Value;
  278. int DownloadedVoucherCount = Convert.ToInt32(Globals.DB.ExecuteScalar(
  279. "SELECT COUNT(*) FROM Voucher WHERE BatchId=@id",
  280. new SQLiteParameter("@id", BatchID)));
  281. if (DownloadedVoucherCount < DeliveredVoucherCount) {
  282. MessageBox.Show(string.Format("Batch {0} has not finished downloading.\nDownloaded {1} of {2} vouchers in batch.",BatchID,DownloadedVoucherCount,DeliveredVoucherCount), "Cannot open print dialog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  283. return;
  284. }
  285. this.BeginInvoke((Action)delegate {
  286. PrintForm PrintFormInstance = new PrintForm();
  287. Globals.OpenBatches.Add(BatchID);
  288. int TotalVouchers = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["DeliveredQuantity"].Index].Value;
  289. int VouchersPrinted = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["PrintedQuantity"].Index].Value;
  290. PrintFormInstance.PrintDescription=(string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["ProductDescription"].Index].Value;
  291. PrintFormInstance.BatchOrderDate=(DateTime)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["OrderDate"].Index].Value;
  292. PrintFormInstance.UnprintedVouchers= TotalVouchers-VouchersPrinted;
  293. PrintFormInstance.TotalVouchers=TotalVouchers;
  294. PrintFormInstance.FaceValue=(string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["FaceValue"].Index].Value;
  295. PrintFormInstance.VoucherTypeName=(string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["VoucherType"].Index].Value;
  296. PrintFormInstance.BatchID=BatchID;
  297. PrintFormInstance.NetworkName = (string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["NetworkName"].Index].Value;
  298. PrintFormInstance.Show();
  299. });
  300. }
  301. private void btnLogout_Click(object sender, EventArgs e)
  302. {
  303. this.Close();
  304. }
  305. private void pnlSplitGrids_Paint(object sender, PaintEventArgs e)
  306. {
  307. }
  308. private void BatchForm_FormClosing(object sender, FormClosingEventArgs e)
  309. {
  310. if (Globals.OpenBatches.Count > 0) {
  311. MessageBox.Show("There are printing jobs in progress - pelase wait for them to complete before logging out.", "Busy printing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  312. e.Cancel = true;
  313. return;
  314. }
  315. if (BatchDownloader != null)
  316. {
  317. BatchDownloader.Cancel();
  318. }
  319. if (DownloadedLogSummariser != null)
  320. {
  321. DownloadedLogSummariser.Cancel();
  322. }
  323. if (BatchDownloader != null)
  324. {
  325. BatchDownloader.Join();
  326. }
  327. if (DownloadedLogSummariser != null)
  328. {
  329. DownloadedLogSummariser.Join();
  330. }
  331. Utility.Logout();
  332. }
  333. private void LogoutTimer_Tick(object sender, EventArgs e)
  334. {
  335. Utility.Logout();
  336. }
  337. public void ResetTimer()
  338. {
  339. LogoutTimer.Stop();
  340. LogoutTimer.Start();
  341. }
  342. private void btnReExport_Click(object sender, EventArgs e)
  343. {
  344. MessageBox.Show("Please be aware that this function is used for exporting vouchers that have already been exported previously. Use this function with caution.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  345. ExportForm exportform = new ExportForm(ExportForm.ExportMode.Reexport);
  346. exportform.Show();
  347. }
  348. private void dtpFilterStartDate_CloseUp(object sender, EventArgs e)
  349. {
  350. PopulateGrid();
  351. }
  352. private void dtpFilterEndDate_CloseUp(object sender, EventArgs e)
  353. {
  354. PopulateGrid();
  355. }
  356. private void btnExport_Click(object sender, EventArgs e)
  357. {
  358. ExportForm exportform = new ExportForm(ExportForm.ExportMode.Export);
  359. exportform.Show();
  360. }
  361. private void dgvBatches_CellContentClick(object sender, DataGridViewCellEventArgs e)
  362. {
  363. }
  364. private void rdoFilterUnprinted_CheckedChanged(object sender, EventArgs e)
  365. {
  366. if (rdoFilterUnprinted.Checked)
  367. {
  368. PopulateGrid();
  369. btnPrint.Enabled = true;
  370. btnReprint.Enabled = false;
  371. }
  372. }
  373. private void rdoFilterPrinted_CheckedChanged(object sender, EventArgs e)
  374. {
  375. if (rdoFilterPrinted.Checked)
  376. {
  377. PopulateGrid();
  378. btnPrint.Enabled = false;
  379. btnReprint.Enabled = true;
  380. }
  381. }
  382. private void rdoFilterReprinted_CheckedChanged(object sender, EventArgs e)
  383. {
  384. if (rdoFilterReprinted.Checked)
  385. {
  386. PopulateGrid();
  387. btnPrint.Enabled = false;
  388. btnReprint.Enabled = true;
  389. }
  390. }
  391. private void rdoFilterExported_CheckedChanged(object sender, EventArgs e)
  392. {
  393. if (rdoFilterExported.Checked)
  394. {
  395. PopulateGrid();
  396. btnPrint.Enabled = false;
  397. btnReprint.Enabled = false;
  398. }
  399. }
  400. private void btnOrderReport_Click(object sender, EventArgs e)
  401. {
  402. OrderReport OrderReportForm = new OrderReport();
  403. OrderReportForm.Show();
  404. }
  405. private void btnReprint_Click(object sender, EventArgs e)
  406. {
  407. if (dgvBatches.SelectedRows.Count == 0) {
  408. MessageBox.Show("Please choose a batch to reprint.", "No batch selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  409. return;
  410. }
  411. MessageBox.Show("Please be aware that this function is used for reprinting vouchers that have already been printed previously. Use this function with caution.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Stop);
  412. int BatchID = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["Id"].Index].Value;
  413. if ((string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["Exported"].Index].Value != "")
  414. {
  415. MessageBox.Show("This batch has been exported previously. Exported batches cannot be printed.", "Cannot print batch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  416. return;
  417. }
  418. int PrintCount = int.Parse(Globals.DB.ExecuteScalar(
  419. "SELECT COUNT(*) FROM Voucher v LEFT JOIN Logs l ON v.Id = l.VoucherId AND l.EventType = @eventtype WHERE l.VoucherId IS NOT NULL AND v.BatchId=@batchid AND Retry=0",
  420. new SQLiteParameter("@batchid", BatchID),
  421. new SQLiteParameter("@eventtype", VendorEvent.VendorEventType.PrintVoucher)).ToString());
  422. if (PrintCount == 0) {
  423. MessageBox.Show("You can only use the Reprint feature for vouchers that have already been printed. Please choose a batch with previously printed vouchers.", "Cannot reprint batch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  424. return;
  425. }
  426. int DeliveredVoucherCount = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["DeliveredQuantity"].Index].Value;
  427. int DownloadedVoucherCount = Convert.ToInt32(Globals.DB.ExecuteScalar(
  428. "SELECT COUNT(*) FROM Voucher WHERE BatchId=@id",
  429. new SQLiteParameter("@id", BatchID)));
  430. if (DownloadedVoucherCount < DeliveredVoucherCount)
  431. {
  432. MessageBox.Show(string.Format("Batch {0} has not finished downloading.\nDownloaded {1} of {2} vouchers in batch.", BatchID, DownloadedVoucherCount, DeliveredVoucherCount), "Cannot open print dialog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  433. return;
  434. }
  435. if (Utility.CheckUserAccess(Utility.UserPermissions.BulkOrder))
  436. { //Only check for undownloaded vouchers if the user is able to see them
  437. if ((string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["ReadyForDownload"].Index].Value == "No")
  438. {
  439. MessageBox.Show("This batch is not ready to downloaded and cannot be printed.", "Cannot print batch", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  440. return;
  441. }
  442. }
  443. if (Globals.OpenBatches.Contains(BatchID))
  444. {
  445. MessageBox.Show("A print dialog is already open for this batch", "Cannot open print dialog", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  446. return;
  447. }
  448. this.BeginInvoke((Action)delegate {
  449. ReprintForm PrintFormInstance = new ReprintForm();
  450. Globals.OpenBatches.Add(BatchID);
  451. int TotalVouchers = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["DeliveredQuantity"].Index].Value;
  452. int VouchersPrinted = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["PrintedQuantity"].Index].Value;
  453. PrintFormInstance.PrintDescription = (string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["ProductDescription"].Index].Value;
  454. PrintFormInstance.BatchOrderDate = (DateTime)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["OrderDate"].Index].Value;
  455. PrintFormInstance.UnprintedVouchers = TotalVouchers - VouchersPrinted;
  456. PrintFormInstance.TotalVouchers = TotalVouchers;
  457. PrintFormInstance.FaceValue = (string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["FaceValue"].Index].Value;
  458. PrintFormInstance.VoucherTypeName = (string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["VoucherType"].Index].Value;
  459. PrintFormInstance.BatchID = BatchID;
  460. PrintFormInstance.NetworkName = (string)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["NetworkName"].Index].Value;
  461. PrintFormInstance.Show();
  462. });
  463. }
  464. private void btnViewPINs_Click(object sender, EventArgs e)
  465. {
  466. VoucherForm ViewPINs = new VoucherForm();
  467. if (dgvBatches.SelectedRows.Count == 0)
  468. {
  469. ViewPINs.BatchID = 0;
  470. }
  471. else
  472. {
  473. ViewPINs.BatchID = (int)dgvBatches.SelectedRows[0].Cells[dgvBatches.Columns["Id"].Index].Value;
  474. }
  475. ViewPINs.Show();
  476. }
  477. private void btn_Paint(object sender, PaintEventArgs e)
  478. {
  479. Button b = sender as Button;
  480. if (!b.Enabled)
  481. {
  482. e.Graphics.Clear(Color.Gray);
  483. //e.Graphics.DrawImage(b.BackgroundImage, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height);
  484. e.Graphics.DrawImage(b.BackgroundImage, b.ClientRectangle);
  485. }
  486. }
  487. }
  488. }