Question: What is wrong with my code? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace

What is wrong with my code?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace _3343_VazquezF_Lab01 { public partial class MainForm : Form { // declare List to store Employee objects

readonly List employeeList = new List();

public MainForm() { InitializeComponent(); } private void ListEmployeesBox_SelectedIndexChanged(object sender, EventArgs e) { // get index of the selected list item

int index = listEmployeesBox.SelectedIndex;

// ceate an instance of EmployeeDetailForm

EmployeeDetailsForm detailsForm = new EmployeeDetailsForm(); EmployeeDetailsForm(); // display employeee information

detailsForm.nameLabelBox = employeeList[index].Name; detailsForm.numberLabelBox.Text = employeeList[index].EmployeeID.ToString(); //detailsForm..numberLabelBox.Text = employeeList[index].ID.ToString(); //detailsForm.departmentLabelBox.Text = employeeList[index].Department; //detailsForm.positionLabelBox.Text = employeeList[index].Position;

// show details form

;detailsForm.Show(); }

private void EmployeeDetailsForm() {

}

private void AddButton_Click(object sender, EventArgs e) {

// create an object of Employee class

//Employee myEmployee = new Employee();

// use the propeties to assign values form text boxes //myEmployee.Name = nameTextBox.Text;

//myEmployee.Department = departmentTextBox.Text; //myEmployee.Position = positionTextBox.Text;

// add Employee object to the List

//employeeList.Add(myEmployee);

// add name field of myEmployee to list box

//listEmployeesBox.Items.Add(myEmployee.Name);

// clear input textboxes

//nameTextBox.Clear(); //numberIDTextBox.Clear(); //departmentTextBox.Clear(); //positionTextBox.Clear(); //nameTextBox.Focus();

// assigns value to name

string employeeName; int employeeID = 0; string department = ""; string position = "";

employeeName = nameTextBox.Text;

if (nameTextBox.Text !="") { // assigns value to name employeeName = nameTextBox.Text;

if(int.TryParse(numberIDTextBox.Text, out employeeID)) { if (employeeID > 0) { if (departmentTextBox.Text !="") { department = departmentTextBox.Text;

if (positionTextBox.Text != "") { position = positionTextBox.Text; } else { MessageBox.Show("Position cannot be left blank"); positionTextBox.Clear(); positionTextBox.Focus();

} } else { MessageBox.Show("Department cannot be left blank"); departmentTextBox.Clear(); departmentTextBox.Focus(); } // creates employee Objects

Employee myEmployee = new Employee {

// assigns values using Properties

_EmployeeName = employeeName, EmployeeID = employeeID, Department = department, Position = position };

// creates Employee Objects using the paramaterized constrcutor - Proporties not included

// Employee myEmployee = new Employee(employeeName, employeeID, department, position)

// add employee object to the List

employeeList.Add(myEmployee);

// add name field of the myEmployee object to the list box

_ = listEmployeesBox.Items.Add(myEmployee._EmployeeName);

// clear text box controls and set the focus nameTextBox.Clear(); numberIDTextBox.Clear(); departmentTextBox.Clear(); positionTextBox.Clear(); nameTextBox.Focus(); } else { MessageBox.Show("Number ID must be greater than 0."); numberIDTextBox.Clear(); numberIDTextBox.Focus();

} } else { MessageBox.Show("Number ID must be numeric."); numberIDTextBox.Clear(); numberIDTextBox.Focus(); } } else { MessageBox.Show("Name cannot be blank."); nameTextBox.Clear(); nameTextBox.Focus(); } }

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

private void ClearButton_Click(object sender, EventArgs e) { nameTextBox.Clear(); numberIDTextBox.Clear(); departmentTextBox.Clear(); positionTextBox.Clear(); listEmployeesBox.Items.Clear(); nameTextBox.Focus();

}

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!