private void Btn_Payment_Click(object sender, EventArgs e) { if (!double.TryParse(txt_payment.Text, out double payAmt)) { MessageBox.Show("Payment must be a valid number.", "Incorrect Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Math.Round(payAmt, 2) != payAmt) { MessageBox.Show("Cannot process fractions of a cent.", "Incorrect Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (payAmt < 0) { MessageBox.Show("Payment cannot be negative. If the balance must be changed, contact Accounting", "Incorrect Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (typeFlag) // flag: true = Accounts Payable { try { SQL.AcctPayPmt(idNum, payAmt); string type = "Inventory"; //sorry. I cheated here. Its the end of the project and we didnt get any deeper into the AcctPayables string particular = "Inventory Purchase of item #" + lbl_invoice.Text.Substring(4, 1) + " from Vendor " + vendor + " for Invoice # " + invoice; SQL.NewLedgerEntry(type, particular, -payAmt); MessageBox.Show("Payment of " + payAmt.ToString("$#.##") + " accepted.", "Payment Recorded", MessageBoxButtons.OK, MessageBoxIcon.Information); DisplayPayData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (!typeFlag) // flag : false = Accounts Rec { try { SQL.AccRecPmt(idNum, payAmt); string type = "AcctRec"; string particular = "Acct Rec Sales for Invoice#" + idNum; SQL.NewLedgerEntry(type, particular, -payAmt); MessageBox.Show("Payment of " + payAmt.ToString("$#.##") + " accepted.", "Payment Recorded", MessageBoxButtons.OK, MessageBoxIcon.Information); DisplayRecData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else // shouldn't be possible? But just in case something funky happens... { throw new Exception("Error: Contact IT (Error Code: NotPayRecFlag)"); } }