コード例 #1
0
ファイル: frmPayoutByDenom.cs プロジェクト: kalkansa/stserver
        private void PayoutBtn_Click(object sender, EventArgs e)
        {
            bool payoutRequired = false;

            byte[] data           = new byte[9 * Hopper.NumberOfChannels]; // create to size of maximum possible
            byte   length         = 0;
            int    dataIndex      = 0;
            byte   denomsToPayout = 0;

            // For each denomination
            for (int i = 0; i < Hopper.NumberOfChannels; i++)
            {
                try
                {
                    // Check if there is input in the box
                    if (AmountToPayout[i].Text != "" && AmountToPayout[i].Text != "0")
                    {
                        // If textbox isn't blank then this denom is being paid out
                        denomsToPayout++;
                        length        += 9;    // 9 bytes per denom to payout (2 amount, 4 value, 3 currency)
                        payoutRequired = true; // need to do a payout as there is now > 0 denoms

                        // Number of this denomination to payout
                        UInt16 numToPayout = UInt16.Parse(AmountToPayout[i].Text);
                        byte[] b           = CHelpers.ConvertInt16ToBytes((short)numToPayout);
                        data[dataIndex++] = b[0];
                        data[dataIndex++] = b[1];

                        // Value of this denomination
                        ChannelData d = Hopper.UnitDataList[i];
                        b = CHelpers.ConvertInt32ToBytes(d.Value);
                        data[dataIndex++] = b[0];
                        data[dataIndex++] = b[1];
                        data[dataIndex++] = b[2];
                        data[dataIndex++] = b[3];

                        // Currency of this denomination
                        data[dataIndex++] = (Byte)d.Currency[0];
                        data[dataIndex++] = (Byte)d.Currency[1];
                        data[dataIndex++] = (Byte)d.Currency[2];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    payoutRequired = false; // don't payout on exception
                }
            }

            if (payoutRequired)
            {
                // Send payout command and shut this form
                Hopper.PayoutByDenomination(denomsToPayout, data, length, Output);
                base.Dispose();
            }
        }