Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Action_Tire_Payment_Processor
{
    public partial class CardInfoForm : Form
    {
        public string CardType;
        public string CardTypeGroup;
        public string TransactionType;
        public string CardHolder;

        public bool CardSwiped = false;
        public bool Searching = false;

        public CardInfoForm()
        {
            InitializeComponent();
            updatePanels();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (TransactionType.Equals("sale") && !rbTTROA.Checked && tbOrderNumber.Text.Length != 9)
            {
                MessageBox.Show("An invalid Order # has been entered.");
                tbOrderNumber.Focus();
                return;
            }

            if (!TransactionType.Equals("refund"))
            {
                if (tbCardNumber.Text.Equals(""))
                {
                    MessageBox.Show("Invalid Card Number");
                    tbCardNumber.Focus();
                    return;
                }
                if (tbAmount.Text.Equals("") || tbAmount.Text.Equals(".00"))
                {
                    MessageBox.Show("Amount is required to process payment.");
                    tbAmount.Focus();
                    return;
                }
                if (tbFirstName.Text.Equals(""))
                {
                    MessageBox.Show("First Name is required to process payment.");
                    tbFirstName.Focus();
                    return;
                }
                if (tbLastName.Text.Equals(""))
                {
                    MessageBox.Show("Last Name is required to process payment.");
                    tbLastName.Focus();
                    return;
                }
                if (!CardSwiped && (tbAddress.Text.Equals("") || tbCity.Text.Equals("") || tbState.Text.Equals("") || tbZip.Text.Equals("")))
                {
                    MessageBox.Show("Address, City, State, and Zip are required to process manual payment.");
                    return;
                }
                if (tbState.Text.Length > 2)
                {
                    MessageBox.Show("Please use a two-letter abbreviation for the state.");
                    tbState.Focus();
                    return;
                }
                if (tbPhone.Text.Equals(""))
                {
                    MessageBox.Show("Phone # is required to process payment.");
                    tbPhone.Focus();
                    return;
                }
                if (tbExpirationDate.Text.Length < 5)
                {
                    MessageBox.Show("Invalid expiration date.");
                    tbExpirationDate.Focus();
                    return;
                }

                if (CardType == null)
                {
                    MessageBox.Show("Invalid card number.");
                    tbCardNumber.Focus();
                    return;
                }

                if (CardType.Equals("A") && tbCardNumber.Text.Length != 15)
                {
                    MessageBox.Show("Incorrect number of digits for American Express card type.");
                    tbCardNumber.Focus();
                    return;
                }
                if (CardTypeGroup.Equals("VMD") && tbCardNumber.Text.Length != 16)
                {
                    MessageBox.Show("Incorrect number of digits for " +
                        (CardType.Equals("V") ? "Visa" : "") +
                        (CardType.Equals("M") ? "MasterCard" : "") +
                        (CardType.Equals("D") ? "Discover" : "") +
                        " card type.");
                    tbCardNumber.Focus();
                    return;
                }
            }
            else // This is a refund
            {
                if (tbTransactionID.Text.Equals(""))
                {
                    MessageBox.Show("Transaction ID is required to process a refund.");
                    tbTransactionID.Focus();
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private bool invalidName = false;

        private void tbFirstName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.ShiftKey || e.KeyCode == Keys.Back || e.KeyCode == Keys.Space || e.KeyCode == Keys.ControlKey || e.Alt) return; 
            if (!(e.KeyCode <= Keys.Z && e.KeyCode >= Keys.A) &&
                (e.KeyCode != Keys.Oemcomma) &&
                (e.KeyCode != Keys.Back) &&
                (e.KeyCode != Keys.Shift))
            {
                invalidName = true;
            }
        }

        private void tbFirstName_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = invalidName;
            invalidName = false;
        }

        private void tbAmount_TextChanged(object sender, EventArgs e)
        {

        }
        
        private void rbTT_CheckedChanged(object sender, EventArgs e)
        {
            updatePanels();
        }

        public void updatePanels()
        {
            if (rbTTRefund.Checked)
            {
                TransactionType = "refund";
                pnlTransactionID.Visible = true;
                pnlPayment.Visible = false;
                this.Size = new Size(460, 300);
            }
            else
            {
                TransactionType = "sale";
                pnlTransactionID.Visible = false;
                pnlPayment.Visible = true;
                this.Size = new Size(460, 613);
            }
            if (rbTTROA.Checked)
            {
                lblOrderNumber.Text = "Customer #";
                lblOrderFormat.Text = "";
            }
            else
            {
                lblOrderNumber.Text = "Order #";
                lblOrderFormat.Text = "##-######";
            }
        }

        private void tbCardNumber_TextChanged(object sender, EventArgs e)
        {
            if (tbCardNumber.Text.Length < 1) return;
            char T = tbCardNumber.Text[0];
            if (T == '3') CardType = "A";
            if (T == '4') CardType = "V";
            if (T == '5') CardType = "M";
            if (T == '6') CardType = "D";

            if (CardType == "V" || CardType == "M" || CardType == "D") CardTypeGroup = "VMD";
            else CardTypeGroup = CardType;
        }

        private static string GetNumbers(string input)
        {
            return new string(input.Where(c => char.IsDigit(c)).ToArray());
        }

        private void tbAmount_Leave(object sender, EventArgs e)
        {
            if (tbAmount.Text.IndexOf('.') == -1) tbAmount.Text += ".00";
            if (tbAmount.Text.Length == 1 && tbAmount.Text[0] == '.') tbAmount.Text = "0" + tbAmount.Text;
            if (tbAmount.Text.Length >= 1 && tbAmount.Text[tbAmount.Text.Length - 1] == '.') tbAmount.Text += "00";
            if (tbAmount.Text.Length >= 3 && tbAmount.Text[tbAmount.Text.Length - 2] == '.') tbAmount.Text += "0";
        }

        private void tbCardNumber_Leave(object sender, EventArgs e)
        {
            tbCardNumber.Text = GetNumbers(tbCardNumber.Text);
        }

        private void tbExpirationDate_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

Commits for ChrisCompleteCodeTrunk/ATTP/Action Tire Payment Processor/CardInfoForm.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000