Question
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 Homework5Solution { public partial class CheckingForm : Form
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 Homework5Solution { public partial class CheckingForm : Form { public CheckingForm() { InitializeComponent(); } enum TransactionTypes { Deposit, ServiceFee, Withdrawal }
private TransactionTypes tType; private decimal balance; struct Transaction { public decimal Amount; public DateTime TransactionDate; public TransactionTypes TransactionType; public string Payee; public string CheckNumber; public override string ToString() { return string.Format ("{0} {1} {2}", this.TransactionDate.ToShortDateString(), this.TransactionType.ToString(), this.Amount.ToString("c")); } } private Transaction[] myTransactions = new Transaction[20] ;
private void UpdateArray(int position) { myTransactions[position].Amount = decimal.Parse(txtAmount.Text); myTransactions[position].TransactionDate = DateTime.Parse(txtDate.Text); myTransactions[position].Payee = txtPayee.Text; myTransactions[position].CheckNumber = txtCheckNumber.Text; myTransactions[position].TransactionType = tType; } private void UpdateControls(int position) { txtCheckNumber.Text = myTransactions[position].CheckNumber; txtAmount.Text = myTransactions[position].Amount.ToString(); txtDate.Text = myTransactions[position].TransactionDate.ToShortDateString(); switch (myTransactions[position].TransactionType) { case TransactionTypes.Deposit: rbDeposit.Checked = true; break; case TransactionTypes.Withdrawal: rbWithdrawal.Checked = true; break; case TransactionTypes.ServiceFee: rbServiceFee.Checked = true; break; } txtPayee.Text = myTransactions[position].Payee; } private void PayeeControls(bool setting) { txtPayee.Enabled = setting; txtCheckNumber.Enabled = setting; } private void ClearForm() { txtAmount.Clear(); txtDate.Clear(); txtPayee.Clear(); txtCheckNumber.Clear(); rbDeposit.Checked = true; txtAmount.Focus(); } private void ShowBalance() { lblBalance.Text = balance.ToString("c"); if (balance < 0) lblBalance.ForeColor = Color.Red; else lblBalance.ForeColor = Color.Black; } private void AdjustBalance(decimal Amount, TransactionTypes type) { if (type == TransactionTypes.Deposit) balance += Amount; else balance -= Amount; } private void RemoveTransaction(int position) { if (position != -1) { int lastItem = lstTransactions.Items.Count-1; for (int counter = position; counter < lastItem; counter++) { myTransactions[counter] = myTransactions[counter + 1]; } myTransactions[lastItem] = new Transaction(); } } private bool CheckPayee(TransactionTypes type) { bool answer = true; if (type == TransactionTypes.Withdrawal) { if (txtPayee.Text == "") answer = false; } return answer;// others case return true } private bool CheckDate(string entry) { DateTime value; return DateTime.TryParse(entry, out value); } private decimal CheckAmount(string entry) { decimal value = 0; if (decimal.TryParse(entry, out value)) { if (value <=0) value = 0; } return value; } private decimal CheckEntries() { bool flag = true; errorProvider1.Clear(); if (!CheckPayee(tType)) { errorProvider1.SetError(txtPayee, "Payee is required for withdrawal"); txtPayee.Focus(); flag = false; } if (!CheckDate(txtDate.Text)) { errorProvider1.SetError(txtDate, "Date is required"); txtDate.Focus(); flag=false; } decimal answer = CheckAmount(txtAmount.Text); if (answer == 0) { errorProvider1.SetError(txtAmount, "Amount must be a number more than zero"); txtAmount.Focus(); flag = false; } if (!flag) answer = 0; return answer; } private void lstTransactions_SelectedIndexChanged(object sender, EventArgs e) { int index = lstTransactions.SelectedIndex; if (index != -1) { UpdateControls(index); } } private void CheckingForm_Load(object sender, EventArgs e) { rbDeposit.Tag = TransactionTypes.Deposit; rbServiceFee.Tag = TransactionTypes.ServiceFee; rbWithdrawal.Tag = TransactionTypes.Withdrawal; ClearForm(); } private void btnAdd_Click(object sender, EventArgs e) { decimal amount = CheckEntries(); if (amount > 0) { int index = lstTransactions.Items.Count; UpdateArray(index); AdjustBalance(amount, tType); lstTransactions.Items.Add(myTransactions[index].ToString()); ShowBalance(); if (lstTransactions.Items.Count - 1 == myTransactions.GetUpperBound(0)) btnAdd.Enabled = false; } } private void btnUpdate_Click(object sender, EventArgs e) { int position = lstTransactions.SelectedIndex; if (position != -1) { decimal amount = CheckEntries(); if (amount > 0) { decimal currentAmount = myTransactions[position].Amount; TransactionTypes currentType = myTransactions[position].TransactionType; AdjustBalance(-myTransactions[position].Amount, myTransactions[position].TransactionType); UpdateArray(position); AdjustBalance(amount, tType); lstTransactions.Items.RemoveAt(position); lstTransactions.Items.Insert(position, myTransactions[position]); lstTransactions.SelectedIndex = position; ShowBalance(); } else { MessageBox.Show("Please select transaction to update from list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } } private void btnDelete_Click(object sender, EventArgs e) { int index = lstTransactions.SelectedIndex; if (index != -1) { AdjustBalance(-myTransactions[index].Amount, myTransactions[index].TransactionType);// revised the account balance RemoveTransaction(index);// remove the transaction lstTransactions.Items.RemoveAt(index); ShowBalance();// show the new balance btnAdd.Enabled = true; } else// remind the user if they don't choose the transaction to delete in the list box { MessageBox.Show("Please select transaction to remove from list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } // this clear button prepares for the new transaction that user clear form method private void btnClear_Click(object sender, EventArgs e) { ClearForm(); } // close the form private void btnExit_Click(object sender, EventArgs e) { this.Close(); } // this method show the change based on the radio button private void typeRadioButtons_CheckedChanged(object sender, EventArgs e) { RadioButton rb = (RadioButton)sender; if (rb.Checked) tType = (TransactionTypes)rb.Tag; if (tType == TransactionTypes.Withdrawal)// if the user checked the withdrawal { PayeeControls(true); //use the payee control to ask the user the enter th value for payee text box txtPayee.Focus(); // move the focuse to the payee text box } else// others case { PayeeControls(false);// set the payee method is fail txtPayee.Text = tType.ToString();// display to payee entry txtCheckNumber.Clear();//clear the check number text box } }
} }
This is the code that I did last time. Could anyone help me with the project in C#? I'm using the Window Form Apps for Visual Studio.
This the requirements of the project:
This exercise takes the checking account project and applies classes. Your project will use a single form.
Create a class called Transaction. The class should have the following read/write properties: TransactionDate, TransactionType, TransactionAmount, Payee, and CheckNumber. Include a ToString method to display account information.
Include the following validation in your class:
A transaction must have at least a transaction date, a transaction amount, and a transaction type.
The transaction amount should be tested to make sure it is a positive number. Use a static function to provide this test.
Each transaction must have a transaction type specified as deposit, service fee, or withdrawal.
The value of Payee defaults to Deposit if the TransactionType is deposit; and defaults to Service Fee if it is a service fee. If a transaction is a withdrawal, an entry must be made in the payee textbox and stored in the Payee property.
Create a form with the following:
A variable to manage the Account Balance.
Radio buttons, labels and textboxes for entering data about each transaction (radio buttons for transaction type).
A listbox showing all transactions. When the user clicks on an item in the list box, information about that transaction should be displayed in the appropriate textboxes and option buttons.
Include a label for displaying the account balance. Notify the user if the account balance is less than zero (either by color, label, or messagebox).
A button to add a new transaction to the listbox and update the account balance label.
A button to remove a transaction from the listbox and display the revised account balance.
A button to clear textboxes and radio buttons for entering new transaction details.
A button to exit the application.
Create a class to store and access the account balance. Include a read-only property for the Balance, and a method to modify the balance.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started