using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SQLite; namespace BulkPrinting { public partial class ReprintForm : Form { public ReprintForm() { InitializeComponent(); } public string PrintDescription; public DateTime BatchOrderDate; public int UnprintedVouchers; public int TotalVouchers; public string FaceValue; public string VoucherTypeName; public string NetworkName; public int BatchID; private Boolean CanReprintThisSession; private int MinSeqNo; private int MaxSeqNo; private void ReprintForm_Load(object sender, EventArgs e) { CanReprintThisSession = ((Globals.SessionMode == SessionModes.Online && Utility.CheckUserAccess(Utility.UserPermissions.CanReprintOnline)) || (Globals.SessionMode == SessionModes.Offline && Utility.CheckUserAccess(Utility.UserPermissions.CanReprintOffline))); lblPrintDescription.Text = PrintDescription; lblBatchNumber.Text = BatchID.ToString(); lblBatchOrderDate.Text = BatchOrderDate.Date.ToString("dd/MM/yyyy"); lblTotalVouchers.Text = TotalVouchers.ToString(); lblFaceValue.Text = FaceValue; lblVoucherType.Text = VoucherTypeName; lblNetwork.Text = NetworkName; SQLiteCommand Command = new SQLiteCommand("SELECT MIN(v.SequenceNumber), MAX(v.SequenceNumber) 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", Globals.DBConnection); Command.Parameters.Add(new SQLiteParameter("@batchid", BatchID)); Command.Parameters.Add(new SQLiteParameter("@eventtype", VendorEvent.VendorEventType.PrintVoucher)); SQLiteDataReader read = Command.ExecuteReader(); read.Read(); MinSeqNo = int.Parse(read.GetValue(0).ToString()); MaxSeqNo = int.Parse(read.GetValue(1).ToString()); numFirstSeqNum.Minimum = MinSeqNo; numFirstSeqNum.Maximum = MaxSeqNo; numLastSeqNum.Minimum = MinSeqNo; numLastSeqNum.Maximum = MaxSeqNo; lblMinSeqNo.Text = MinSeqNo.ToString(); lblMaxSeqNo.Text = MaxSeqNo.ToString(); } private void btnCancel_Click(object sender, EventArgs e) { Globals.OpenBatches.Remove(BatchID); this.Close(); } private void btnNext_Click(object sender, EventArgs e) { int SelectedRangeStart = 0; int SelectedRangeEnd = 0; string Sql; SQLiteCommand Command; decimal VoucherCount; if (rdoRange.Checked) { if (numFirstSeqNum.Value < MinSeqNo || numLastSeqNum.Value > MaxSeqNo) { MessageBox.Show(String.Format("Valid sequence numbers are from {0} to {1}", MinSeqNo.ToString(), MaxSeqNo.ToString()), "Invalid print value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (numFirstSeqNum.Value > numLastSeqNum.Value) { MessageBox.Show("The first sequence number in the range must be less than or equal to the last.", "Invalid range", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (numLastSeqNum.Value > TotalVouchers) { MessageBox.Show("You have a final sequence number higher than the available vouchers to print. Please reduce the last sequence number to equal to or below the total number of vouchers.", "Cannot print that many vouchers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } SelectedRangeStart = (int)numFirstSeqNum.Value; SelectedRangeEnd = (int)numLastSeqNum.Value; } else if (rdoSerial.Checked) { Sql = "SELECT Count(*) FROM Logs l left join Voucher v on l.VoucherId=v.id WHERE v.Serial=@serialnum and l.EventType=@eventtype and Retry=0"; Command = new SQLiteCommand(Sql, Globals.DBConnection); Command.Parameters.Add(new SQLiteParameter("@serialnum", txtSerialNum.Text)); Command.Parameters.Add(new SQLiteParameter("@eventtype", VendorEvent.VendorEventType.PrintVoucher)); int PrintCount = int.Parse(Command.ExecuteScalar().ToString()); if (PrintCount == 0) { MessageBox.Show("No voucher with that serial number was found to have been printed. Please provide a previously printed voucher number or use the 'Print' function to print new vouchers.", "Cannot find printed voucher", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } Sql = "SELECT FaceValue FROM Batch WHERE Id=@id"; Command = new SQLiteCommand(Sql, Globals.DBConnection); Command.Parameters.Add(new SQLiteParameter("@id", BatchID)); VoucherCount = SelectedRangeEnd - SelectedRangeStart + 1; decimal VoucherFaceValue = (decimal)Command.ExecuteScalar(); int UnprintedVouchersInRange = Utility.GetNumberOfUnprintedVouchersInRange((int)numFirstSeqNum.Value, (int)numLastSeqNum.Value, BatchID); decimal PrintedVoucherValue = (VoucherCount - UnprintedVouchersInRange) * VoucherFaceValue; decimal UnprintedVoucherValue = UnprintedVouchersInRange * VoucherFaceValue; if (Globals.SessionMode == SessionModes.Online) { if (!Utility.IsValueWithinRemainingUserLimit(UserLimits.UserLimitTypes.OnlinePrint, UnprintedVoucherValue)) { MessageBox.Show("You have selected more vouchers than your permissions allow you to print today.", "Cannot print that many vouchers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!Utility.IsValueWithinRemainingUserLimit(UserLimits.UserLimitTypes.OnlineReprint, PrintedVoucherValue)) { MessageBox.Show("You have selected more previously printed vouchers than your permissions allow you to reprint today.", "Cannot print that many vouchers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (Globals.SessionMode == SessionModes.Offline) { if (!Utility.IsValueWithinRemainingUserLimit(UserLimits.UserLimitTypes.OfflinePrint, UnprintedVoucherValue)) { MessageBox.Show("You have selected more vouchers than your permissions allow you to print today.", "Cannot print that many vouchers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!Utility.IsValueWithinRemainingUserLimit(UserLimits.UserLimitTypes.OfflineReprint, PrintedVoucherValue)) { MessageBox.Show("You have selected more previously printed vouchers than your permissions allow you to reprint today.", "Cannot print that many vouchers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (Globals.MaxPrinter.ChoosePrinter()) { PrintAlignmentDialog printdialog = new PrintAlignmentDialog(); printdialog.PrintDescription = PrintDescription; printdialog.BatchID = BatchID; printdialog.BatchOrderDate = BatchOrderDate; printdialog.FaceValue = FaceValue; printdialog.VoucherTypeName = VoucherTypeName; printdialog.NetworkName = NetworkName; printdialog.NumVouchers = null; printdialog.FirstSeqNo = (int)numFirstSeqNum.Value; printdialog.LastSeqNo = (int)numLastSeqNum.Value; printdialog.Show(); this.Close(); } } private void txtSerialNum_TextChanged(object sender, EventArgs e) { } } }