Esempio n. 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 form1 = new Form1();

            BusinessRules.employeeList.Clear();
            Hourly temp = new Hourly("AA5", "Cheryl", "Kirk", "Cheryl Kirk", 3.98, 4);

            BusinessRules.AddEmployee(form1, temp);
            Contract hey = new Contract("L-1337", "John", "Chief", "John Chief", 5);

            BusinessRules.AddEmployee(form1, hey);
            Salary sup = new Salary("HAMBURGER", "Phil", "Hartman", "Phil Hartman", 7.896);

            BusinessRules.AddEmployee(form1, sup);
            Sales bro = new Sales("EMPLOYEE_ID", "David", "Lynch", "David Lynch", 4, 5.86, 387);

            BusinessRules.AddEmployee(form1, bro);
            BusinessRules.AddEmployee(form1, null);
            Application.Run(form1);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new employee object from data that has been entered into the forms
        /// </summary>
        /// <returns>Returns the employee object or a null reference</returns>

        public Employee createEmployee()
        {
            bool ifBegin = validateText();

            if (ifBegin)
            {
                Employee emp;
                string   firstN       = textBox1.Text;
                string   lastN        = textBox2.Text;
                Object   selectedItem = comboBox1.SelectedItem;
                string   type         = selectedItem.ToString();

                char   a            = firstN[0];
                char   b            = lastN[0];
                string id           = a + b + "-";
                Random random       = new Random();
                int    randomNumber = random.Next(0, 1000);
                id = id + randomNumber;
                string fullN = firstN + " " + lastN;
                if (type == "Hourly")
                {
                    double rate   = Double.Parse(textBox4.Text);
                    double worked = Double.Parse(textBox5.Text);
                    Hourly temp   = new Hourly(id, firstN, lastN, fullN, rate, worked);
                    emp = temp;
                    Employee.empCounter++;
                    return(temp);
                }
                else if (type == "Salary")
                {
                    double monthly = Double.Parse(textBox4.Text);
                    Salary temp    = new Salary(id, firstN, lastN, fullN, monthly);
                    emp = temp;
                    Employee.empCounter++;
                    return(temp);
                }
                else if (type == "Sales")
                {
                    double monthly = Double.Parse(textBox4.Text);
                    double comm    = Double.Parse(textBox5.Text);
                    double gross   = Double.Parse(textBox6.Text);
                    Sales  temp    = new Sales(id, firstN, lastN, fullN, monthly, comm, gross);
                    emp = temp;
                    Employee.empCounter++;
                    return(temp);
                }
                else if (type == "Contract")
                {
                    double   wage = Double.Parse(textBox4.Text);
                    Contract temp = new Contract(id, firstN, lastN, fullN, wage);
                    emp = temp;
                    Employee.empCounter++;
                    return(temp);
                }
                Employee.empCounter++;
                return(null);
            }
            else
            {
                Employee.empCounter++;
                return(null);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// List View selection event, that checks to see if another item has been selected into the list view to change what Employee's data to display
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     errorProvider1.SetError(labelError, null);
     if (listView1.SelectedItems.Count == 0)
     {
         return;
     }
     if (listView1.SelectedItems[0].Text.Contains("BLANK"))
     {
         textBox1.Text           = "NULL";
         textBox2.Text           = "NULL";
         textBox3.Text           = listView1.SelectedItems[0].Text;
         textBox4.Text           = "";
         textBox5.Text           = "";
         textBox6.Text           = "";
         textBox4.Visible        = false;
         label6.Visible          = false;
         textBox5.Visible        = false;
         label7.Visible          = false;
         textBox6.Visible        = false;
         label8.Visible          = false;
         comboBox1.SelectedIndex = -1;
     }
     else
     {
         foreach (KeyValuePair <string, Employee> worker in BusinessRules.employeeList)
         {
             try
             {
                 if (worker.Value.fullName == listView1.SelectedItems[0].Text)
                 {
                     Employee emp = worker.Value;
                     textBox1.Text = emp.firstName;
                     textBox2.Text = emp.lastName;
                     textBox3.Text = emp.empId;
                     if (emp.empType == "Hourly")
                     {
                         Hourly temp = (Hourly)emp;
                         textBox4.Visible       = true;
                         label6.Visible         = true;
                         textBox5.Visible       = true;
                         label7.Visible         = true;
                         textBox6.Visible       = false;
                         label8.Visible         = false;
                         textBox4.Text          = temp.hourlyRate.ToString();
                         textBox5.Text          = temp.hoursWorked.ToString();
                         comboBox1.SelectedItem = "Hourly";
                     }
                     else if (emp.empType == "Salary")
                     {
                         Salary temp = (Salary)emp;
                         textBox4.Visible       = true;
                         label6.Visible         = true;
                         textBox5.Visible       = false;
                         label7.Visible         = false;
                         textBox6.Visible       = false;
                         label8.Visible         = false;
                         textBox4.Text          = temp.monthlySalary.ToString();
                         comboBox1.SelectedItem = "Salary";
                     }
                     else if (emp.empType == "Sales")
                     {
                         Sales temp = (Sales)emp;
                         textBox4.Visible       = true;
                         label6.Visible         = true;
                         textBox5.Visible       = true;
                         label7.Visible         = true;
                         textBox6.Visible       = true;
                         label8.Visible         = true;
                         textBox4.Text          = temp.monthlySalary.ToString();
                         textBox5.Text          = temp.commission.ToString();
                         textBox6.Text          = temp.grossSales.ToString();
                         comboBox1.SelectedItem = "Sales";
                     }
                     else if (emp.empType == "Contract")
                     {
                         Contract temp = (Contract)emp;
                         textBox4.Visible       = true;
                         label6.Visible         = true;
                         textBox5.Visible       = false;
                         label7.Visible         = false;
                         textBox6.Visible       = false;
                         label8.Visible         = false;
                         textBox4.Text          = temp.contractWage.ToString();
                         comboBox1.SelectedItem = "Contract";
                     }
                 }
             }
             catch (NullReferenceException)
             {
                 continue;
             }
         }
     }
 }