// This function calculates how the payout should be handled, it takes the input as a string // from the text box and converts it to a number to payout in the proper format. E.g. The user // enters "9.50", this is converted to 950 for payouts. Logic can then be performed on this number // to work out the best way of dispensing it E.g. 5.00 note dispensed from nv11 and 4.50 from hopper. private void CalculatePayout(string amount, string currency) { float payoutAmount = 0; try { // Parse amount to a number payoutAmount = float.Parse(amount) * 100; } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } // Now we have a number we have to work out which validator needs to process the payout // This section can be modified to payout in any way needed. Currently it pays out one // note and the rest from the hopper - this could be extended to payout multiple notes. // First work out if we need a note, if it's less than the value of the first channel (assuming channels are in value order) // then we know it doesn't need one if (payoutAmount < NV11.GetChannelValue(1)) { // So we can send the command straight to the hopper Hopper.PayoutAmount((int)payoutAmount, currency.ToCharArray(), textBox1); } else { // Otherwise we need to work out how to payout notes // Check what value the last note stored in the payout was int noteVal = NV11.GetLastNoteValue(); // If less or equal to payout, pay it out if (noteVal <= payoutAmount && noteVal > 0) { payoutAmount -= noteVal;// take the note off the total requested NV11.EnablePayout(); NV11.PayoutNextNote(textBox1); } // payout the remaining from the hopper if needed if (payoutAmount > 0) { Hopper.PayoutAmount((int)payoutAmount, currency.ToCharArray(), textBox1); } } }
// This function takes a string input from the text box and then converts it to a usable number // that the validator will understand. E.g. user enters "3.40", this gets translated to 340 to // pass to the hopper. private void CalculatePayout(string amount, char[] currency) { float payoutAmount = 0; try { // Parse it to a number payoutAmount = float.Parse(amount); } catch (Exception ex) { return; } // Pay it out Hopper.PayoutAmount((int)payoutAmount, currency, textBox1); }
private void CalculatePayout(string amount, char[] currency) { // Split string by decimal point string[] s = amount.Split('.'); string final = ""; int payoutAmount = 0; // If there was a decimal point if (s.Length > 1) { // Add a trailing zero if necessary if (s[1].Length == 1) { s[1] += "0"; } // If more than 2 decimal places, cull end else if (s[1].Length > 2) { s[1] = s[1].Substring(0, 2); } final += s[0] + s[1]; // Add to final result string } else { final += s[0] + "00"; // Add two zeros if there is no decimal point entered } try { // Parse it to a number payoutAmount = Int32.Parse(final); } catch (Exception ex) { return; } // Pay it out Hopper.PayoutAmount(payoutAmount, currency, textBox1); }
// This function shows a simple example of calculating a payout split between the SMART Payout and the // SMART Hopper. It works on a highest value split, first the notes are looked at, then any remainder // that can't be paid out with a note is paid from the SMART Hopper. private void CalculatePayout(string amount, char[] currency) { float payoutAmount; try { // Parse it to a number payoutAmount = float.Parse(amount) * 100; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } int payoutList = 0; // Obtain the list of sorted channels from the SMART Payout, this is sorted by channel value // - lowest first List <ChannelData> reverseList = new List <ChannelData>(Payout.UnitDataList); reverseList.Reverse(); // Reverse the list so the highest value is first // Iterate through each foreach (ChannelData d in reverseList) { ChannelData temp = d; // Don't overwrite real values // Keep testing to see whether we need to payout this note or the next note while (true) { // If the amount to payout is greater than the value of the current note and there is // some of that note available and it is the correct currency if (payoutAmount >= temp.Value && temp.Level > 0 && String.Equals(new String(temp.Currency), new String(currency))) { payoutList += temp.Value; // Add to the list of notes to payout from the SMART Payout payoutAmount -= temp.Value; // Minus from the total payout amount temp.Level--; // Take one from the level } else { break; // Don't need any more of this note } } } // Test the proposed payout values if (payoutList > 0) { // First test SP Payout.PayoutAmount(payoutList, currency, true); if (Payout.CommandStructure.ResponseData[0] != 0xF0) { DialogResult res = MessageBox.Show("Smart Payout unable to pay requested amount, attempt to pay all from Hopper?", "Error with Payout", MessageBoxButtons.YesNo); if (res == System.Windows.Forms.DialogResult.No) { return; } else { payoutAmount += payoutList; } } // SP is ok to pay Payout.PayoutAmount(payoutList, currency, false, textBox1); } // Now if there is any left over, request from Hopper if (payoutAmount > 0) { // Test Hopper first Hopper.PayoutAmount((int)payoutAmount, currency, true); if (Hopper.CommandStructure.ResponseData[0] != 0xF0) { MessageBox.Show("Unable to pay requested amount!"); return; } // Hopper is ok to pay Hopper.PayoutAmount((int)payoutAmount, currency, false, textBox1); } }