Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C#: Complete the coding in this project REQUIREMENT A transaction includes the f

ID: 3879266 • Letter: C

Question

C#: Complete the coding in this project

REQUIREMENT

A transaction includes the following information: when the transaction occurred, the amount of the transaction, the kind of transaction (deposit, withdrawal, service fee), and whether the transaction has cleared the bank.

1) The transaction amount should be tested to make sure it is a positive number.

2) The transaction date should also be tested to be sure a date has been entered, and the date is on or before today.

3) Each transaction must have a transaction type specified (deposit, service fee, withdrawal).

4) A withdrawal cannot cause the actual balance to be less than zero (a service fee can result in a negative balance).

NOTE: Two account balances need to be tracked: actual and processed (cleared). The actual account balance changes when a new transaction is created IF all of the requirements are met. The processed balance changes if all of the requirements are met AND the transaction is marked as processed.

5) Create a class-level two-dimensional string array to hold each transaction, and a class-level integer to track where in the array to assign the next transaction entry.

NOTE: The process button is to add a new transaction. If the entry is valid, use the class-level integer to assign the transaction values to the appropriate elements in the array. Also add the transaction information in the listbox as an item in the listbox and update the account balances.

The listbox on the included form should show all transactions. When a new transaction is created, add information about the transaction to the list box as a string (date, amount, type of transaction, and whether the transaction has been processed).

When an entry in the listbox is selected, display the data for that transaction in the appropriate controls.

The clear button sets up the form for entering a new transaction.

The exit button (coded) simply closes the form.

Explanation / Answer

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 WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double actualbal = 5000;

private void button1_Click(object sender, EventArgs e)
{
try
{
if (comboBox1.SelectedIndex != -1)
{
if (txtamt.Text != "")
{

int amount = Convert.ToInt16(txtamt.Text);
if (amount > 0)
{

if (txtdate.Text != " / /")
{
lblerr.Text = "";
if (DateTime.Parse(txtdate.Text) <= DateTime.Now.Date)
{

listBox1.Items.Add(txtdate.Text);
listBox1.Items.Add( txtamt.Text); listBox1.Items.Add(comboBox1.SelectedItem.ToString());

if (checkBox1.Checked==false)
{
txtactualbal.Text = (Convert.ToInt16(txtamt.Text) + actualbal).ToString();
}
else
{
txtbankbal.Text = (Convert.ToInt16(txtamt.Text) + actualbal).ToString();
}

  


comboBox1.Text = "";
txtamt.Text = "";
txtdate.Text = "";
}
else
{
lblerr.Text = "Transaction Date can not be after today";
txtdate.Text = "";
this.ActiveControl = txtdate;
}
}
else
{
lblerr.Text = "Please enter transaction date";
this.ActiveControl = txtdate;
txtdate.BackColor = System.Drawing.Color.Aqua;
}
}
else
{
lblerr.Text="Transaction Amount can not be negative";
txtamt.Text = "";
this.ActiveControl = txtamt;

}
}
else
{
lblerr.Text = "Please enter transaction amount";
this.ActiveControl = txtamt;
txtamt.BackColor = System.Drawing.Color.Aqua;
}
}
else
{
lblerr.Text = "Please select service type";
}
}

catch (Exception ee)
{
lblerr.Text = ee.Message;
}
}

private void txtamt_TextChanged(object sender, EventArgs e)
{
txtamt.BackColor = System.Drawing.Color.White;
}

private void txtdate_TextChanged(object sender, EventArgs e)
{
txtdate.BackColor = System.Drawing.Color.White;
}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
this.Controls.Clear();
InitializeComponent();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.Items.Clear();

}

private void Form1_Load(object sender, EventArgs e)
{
txtactualbal.Text = actualbal.ToString();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
  
if (listBox1.SelectedIndex == 2)
{
comboBox1.Text = listBox1.SelectedItem.ToString();
}
if (listBox1.SelectedIndex == 0)
{
txtdate.Text = listBox1.SelectedItem.ToString();
}
if (listBox1.SelectedIndex == 1)
{
txtamt.Text = listBox1.SelectedItem.ToString();
}

}
}
}

design

namespace WindowsFormsApplication8
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtamt = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label4 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.txtactualbal = new System.Windows.Forms.TextBox();
this.txtbankbal = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.lblerr = new System.Windows.Forms.Label();
this.txtdate = new System.Windows.Forms.MaskedTextBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"deposit",
"service fee",
"withdrawal"});
this.comboBox1.Location = new System.Drawing.Point(142, 90);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 97);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Type";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 127);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(43, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Amount";
//
// txtamt
//
this.txtamt.Location = new System.Drawing.Point(142, 127);
this.txtamt.Name = "txtamt";
this.txtamt.Size = new System.Drawing.Size(121, 20);
this.txtamt.TabIndex = 3;
this.txtamt.TextChanged += new System.EventHandler(this.txtamt_TextChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(286, 90);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(30, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Date";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(289, 129);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(175, 17);
this.checkBox1.TabIndex = 6;
this.checkBox1.Text = "Transaction processed by bank";
this.checkBox1.UseVisualStyleBackColor = true;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(19, 177);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(63, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Transaction";
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(22, 205);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(442, 95);
this.listBox1.TabIndex = 8;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(22, 318);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(53, 13);
this.label5.TabIndex = 9;
this.label5.Text = "actual bal";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(266, 318);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(49, 13);
this.label6.TabIndex = 10;
this.label6.Text = "Bank bal";
//
// txtactualbal
//
this.txtactualbal.Location = new System.Drawing.Point(82, 318);
this.txtactualbal.Name = "txtactualbal";
this.txtactualbal.Size = new System.Drawing.Size(100, 20);
this.txtactualbal.TabIndex = 11;
//
// txtbankbal
//
this.txtbankbal.Location = new System.Drawing.Point(336, 318);
this.txtbankbal.Name = "txtbankbal";
this.txtbankbal.Size = new System.Drawing.Size(100, 20);
this.txtbankbal.TabIndex = 12;
//
// button1
//
this.button1.Location = new System.Drawing.Point(82, 376);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 13;
this.button1.Text = "Process";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(200, 376);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 14;
this.button2.Text = "Clear";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(317, 376);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 15;
this.button3.Text = "Exit";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// lblerr
//
this.lblerr.AutoSize = true;
this.lblerr.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblerr.ForeColor = System.Drawing.Color.Red;
this.lblerr.Location = new System.Drawing.Point(23, 21);
this.lblerr.Name = "lblerr";
this.lblerr.Size = new System.Drawing.Size(0, 18);
this.lblerr.TabIndex = 16;
//
// txtdate
//
this.txtdate.Location = new System.Drawing.Point(322, 87);
this.txtdate.Mask = "00/00/0000";
this.txtdate.Name = "txtdate";
this.txtdate.Size = new System.Drawing.Size(100, 20);
this.txtdate.TabIndex = 17;
this.txtdate.ValidatingType = typeof(System.DateTime);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(488, 422);
this.Controls.Add(this.txtdate);
this.Controls.Add(this.lblerr);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtbankbal);
this.Controls.Add(this.txtactualbal);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtamt);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtamt;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtactualbal;
private System.Windows.Forms.TextBox txtbankbal;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label lblerr;
private System.Windows.Forms.MaskedTextBox txtdate;
}
}