A thought

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 Exam2_sampleExam1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Application.Exit();

        }

        // Decides which form to display depending on choice
        private void buttonView_Click(object sender, EventArgs e)
        {
            try
            {

                if (radioButtonBranch.Checked == true)
                {
                    Form2 form2 = new Form2();
                    form2.ShowDialog();

                }
                else if (radioButtonProfitability.Checked == true)
                {
                    Form3 form3 = new Form3();
                    form3.ShowDialog();

                }
                else
                {
                    throw new
                        InvalidOperationException
                        (“You must select a radio button option.”);
                }
            }
            catch (InvalidOperationException ioEx)
            {
                MessageBox.Show(ioEx.Message, “Error”);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, “Error”);
            }
        }
    } // End class
} // End namespace

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 Exam2_sampleExam1
{
    public partial class Form2 : Form
    {
        // Declare a 2D Array to populate a table with Branch Details
        private string[,] branchDetails = new string[5, 5];

        private string[] branchNames =
        { “Cork”, “Dublin”, “Galway”, “Limerick”, “Waterford” };

        private string[] branchColumns = { “Sort Code”, “Address”,
                                             “Manager”, “Telephone No.”, “Fax No.” };

        public Form2()
        {
            InitializeComponent();
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();

        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                // declare variables for user input
                string sortCode = textBoxSortCode.Text;
                string address = textBoxBranchAddress.Text;
                string manager = textBoxManager.Text;
                string telephoneNo = textBoxTelephoneNo.Text;
                string faxNo = textBoxFaxNo.Text;

                //
                int branchNameIndex = listBoxBranch.SelectedIndex;

                // assign variables to the Indexes of listBoxBranch which will be
                // used to populate a table in the Details Textbox (i.e. textBoxDetails)
                branchDetails[branchNameIndex, 0] = sortCode;
                branchDetails[branchNameIndex, 1] = address;
                branchDetails[branchNameIndex, 2] = manager;
                branchDetails[branchNameIndex, 3] = telephoneNo;
                branchDetails[branchNameIndex, 4] = faxNo;
            }
            catch (FormatException fEx)
            {
                MessageBox.Show(fEx.Message, “Error”);
            }
            catch (NullReferenceException nEx)
            {
                MessageBox.Show(nEx.Message, “Error”);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, “Error”);
            } // End Try Catch

        }

        private void buttonDisplay_Click(object sender, EventArgs e)
        {
            textBoxDetails.Text = “”;
            textBoxDetails.Text = “\t\t”;

            int i =0;
            foreach (string column in branchColumns)
            {
                textBoxDetails.Text += column;
                if (i == 0 || i == 1 || i == 2)
                {
                    textBoxDetails.Text += “\t\t”;
                }
                else
                {
                    textBoxDetails.Text += “\t”;
                }
                i++;

            }

            textBoxDetails.Text += “\r\n”;

            for (int row = 0; row < 5; row++)
            {
                textBoxDetails.Text += branchNames[row];

                for (int column = 0; column < 5; column++)
                {
                    
                   textBoxDetails.Text += “\t\t”;
                    
                    textBoxDetails.Text += branchDetails[row, column];
                } // end inner ‘for’ Loop

                textBoxDetails.Text += “\r\n”;

            } // end outer ‘for’ Loop

        }

    } // End class
} // End namespace

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 Exam2_sampleExam1
{
    public partial class Form3 : Form
    {
        private string[,] profitabilityDetails = new string[5,5];

        private string[] branchNames = { “Cork”, “Dublin”, “Galway”, “Limerick”, “Waterford” };

        public Form3()
        {
            InitializeComponent();
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();

        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                // parsed out
                int parsedOutstandingLoans = int.Parse(textBoxOutstandingLoans.Text);
                int parsedUnperformingLoans = int.Parse(textBoxUnperformingLoans.Text);
                decimal parsedRevenue = decimal.Parse(textBoxRevenue.Text);
                decimal parsedProfit = decimal.Parse(textBoxProfitability.Text);
                int parsedNoCustomers = int.Parse(textBoxNoCustomers.Text);

                //
                string outstandingLoans = textBoxOutstandingLoans.Text;
                string unperformingLoans = textBoxUnperformingLoans.Text;
                string revenue = textBoxRevenue.Text;
                string profit = textBoxProfitability.Text;
                string noCustomers = textBoxNoCustomers.Text;
                int selectedBranch = listBoxBranchName.SelectedIndex;

                // assigns variables to values in listBox
                profitabilityDetails[selectedBranch, 0] = outstandingLoans;
                profitabilityDetails[selectedBranch, 1] = unperformingLoans;
                profitabilityDetails[selectedBranch, 2] = revenue;
                profitabilityDetails[selectedBranch, 3] = profit;
                profitabilityDetails[selectedBranch, 4] = noCustomers;
            }
            catch (FormatException fEx)
            {
                MessageBox.Show(fEx.Message, “Error”);
            }
            catch (NullReferenceException nrEx)
            {
                MessageBox.Show(nrEx.Message, “Error”);
            }

            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, “Error”);
            }
        }

        private void buttonDisplay_Click(object sender, EventArgs e)
        {
            // Displays user input in listView for each Branch’s profitability

            //Clears the ListView of any previous data
            listViewProfitability.Items.Clear();

            // **MORE EFFICIENT WAY OF DOING IT** <== as it’s done using a ListView
            for (int row = 0; row < 5; row++)
            {
                ListViewItem item = new ListViewItem();
                item = listViewProfitability.Items.Add(branchNames[row]);

                for (int column = 0; column < 5; column++)
                {
                    item.SubItems.Add(profitabilityDetails[row, column]);
                }

            }

        }
    } // End class
} // End namespace

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s