示例#1
0
        BusinessLogic()
        {
            Hourly emp1 = new Hourly();

            emp1.empId          = "146-00";
            emp1.empType        = empType.Hourly;
            emp1.firstName      = "John";
            emp1.lastName       = "Higginson";
            emp1.hourlyRate     = (Double)11.50;
            emp1.hoursWorked    = (Double)36;
            emp1.startDate      = "12/25/2012";
            emp1.departmentName = "Data Science";
            emp1.jobTitle       = "Data Scientist";
            //emp1.benefits
            emp1.availableCourses = allCourses.ToArray();
            //emp1.coursesTaken
            //emp1.credits
            //emp1.semesterGPA
            emp1.deleted = false;


            Salary emp2 = new Salary();

            emp2.empId          = "137-01";
            emp2.empType        = empType.Salary;
            emp2.firstName      = "Alyssa";
            emp2.lastName       = "Higginson";
            emp2.monthlySalary  = (Double)3333;
            emp2.startDate      = "05/15/2020";
            emp2.departmentName = "Spanish Oaks";
            emp2.jobTitle       = "Teacher";
            //emp2.benefits
            emp2.availableCourses = allCourses.ToArray();
            //emp2.coursesTaken
            //emp2.credits
            //emp2.semesterGPA
            emp2.deleted = false;

            Sales emp3 = new Sales();

            emp3.empId          = "188-02";
            emp3.empType        = empType.Sales;
            emp3.firstName      = "Winston";
            emp3.lastName       = "Koda";
            emp3.monthlySalary  = (Double)8000;
            emp3.commission     = (Double)400;
            emp3.grossSales     = (Double)800;
            emp3.startDate      = "10/22/2019";
            emp3.departmentName = "Custodial";
            emp3.jobTitle       = "Janitor";
            //emp3.benefits
            emp3.availableCourses = allCourses.ToArray();
            //emp3.coursesTaken
            //emp3.credits
            //emp3.semesterGPA
            emp3.deleted = false;

            Contract emp4 = new Contract();

            emp4.empId          = "166-03";
            emp4.empType        = empType.Contract;
            emp4.firstName      = "Max";
            emp4.lastName       = "Miles";
            emp4.contractWage   = (Double)650;
            emp4.startDate      = "01/01/2021";
            emp4.departmentName = "Planning Committee";
            emp4.jobTitle       = "Party Planner";
            //emp4.benefits
            emp4.availableCourses = allCourses.ToArray();
            //emp4.coursesTaken
            //emp4.credits
            //emp4.semesterGPA
            emp4.deleted = false;

            EmpDictData.Add(emp1.empId, emp1);
            EmpDictData.Add(emp2.empId, emp2);
            EmpDictData.Add(emp3.empId, emp3);
            EmpDictData.Add(emp4.empId, emp4);

            Course cs1400 = new Course();

            cs1400.courseId      = "CS1400";
            cs1400.courseName    = "Fundamentals of Programming";
            cs1400.courseCredits = 3;

            Course cs1410 = new Course();

            cs1410.courseId      = "CS1410";
            cs1410.courseName    = "Object Oriented Programming";
            cs1410.courseCredits = 3;

            Course cs2300 = new Course();

            cs2300.courseId      = "CS2300";
            cs2300.courseName    = "Discrete Mathematical Structures I";
            cs2300.courseCredits = 3;

            Course cs2420 = new Course();

            cs2420.courseId      = "CS2420";
            cs2420.courseName    = "Algorithms & Data Structures";
            cs2420.courseCredits = 3;

            Course cs2450 = new Course();

            cs2450.courseId      = "CS2450";
            cs2450.courseName    = "Software Engineering";
            cs2450.courseCredits = 3;

            Course cs2550 = new Course();

            cs2550.courseId      = "CS2550";
            cs2550.courseName    = "Web Programming I";
            cs2550.courseCredits = 3;

            Course cs2600 = new Course();

            cs2600.courseId      = "CS2600";
            cs2600.courseName    = "Computer Networks I";
            cs2600.courseCredits = 3;

            Course cs2810 = new Course();

            cs2810.courseId      = "CS2810";
            cs2810.courseName    = "Computer Architecture";
            cs2810.courseCredits = 3;

            Course cs3060 = new Course();

            cs3060.courseId      = "CS3060";
            cs3060.courseName    = "Operating Systems";
            cs3060.courseCredits = 3;

            Course cs3240 = new Course();

            cs3240.courseId      = "CS3240";
            cs3240.courseName    = "Discrete Mathematical Structures II";
            cs3240.courseCredits = 3;

            Course cs3260 = new Course();

            cs3260.courseId      = "CS3260";
            cs3260.courseName    = "C# Software Development";
            cs3260.courseCredits = 3;

            Course cs3370 = new Course();

            cs3370.courseId      = "CS3370";
            cs3370.courseName    = "C++ Software Development";
            cs3370.courseCredits = 3;

            Course cs3520 = new Course();

            cs3520.courseId      = "CS3520";
            cs3520.courseName    = "Database Theory";
            cs3520.courseCredits = 3;

            CourseDictData.Add(cs1400.courseId, cs1400);
            CourseDictData.Add(cs1410.courseId, cs1410);
            CourseDictData.Add(cs2300.courseId, cs2300);
            CourseDictData.Add(cs2420.courseId, cs2420);
            CourseDictData.Add(cs2450.courseId, cs2450);
            CourseDictData.Add(cs2550.courseId, cs2550);
            CourseDictData.Add(cs2600.courseId, cs2600);
            CourseDictData.Add(cs2810.courseId, cs2810);
            CourseDictData.Add(cs3060.courseId, cs3060);
            CourseDictData.Add(cs3240.courseId, cs3240);
            CourseDictData.Add(cs3260.courseId, cs3260);
            CourseDictData.Add(cs3370.courseId, cs3370);
            CourseDictData.Add(cs3520.courseId, cs3520);
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            delete_Button.Visible = true;
            int newEmpType = empTypeComboBox.SelectedIndex;

            if (firstNameTextBox.Text != "" && lastNameLabel.Text != "")
            {
                checkFieldsLabel.Text = "";
                if (newEmpType == 0)
                {
                    if (hourlyRateTextBox.Text != "" && hoursWorkedTextBox.Text != "")
                    {
                        Hourly newEmp = new Hourly();
                        newEmp.empType        = empType.Hourly;
                        newEmp.hourlyRate     = Double.Parse(hourlyRateTextBox.Text);
                        newEmp.hoursWorked    = Double.Parse(hoursWorkedTextBox.Text);
                        newEmp.firstName      = firstNameTextBox.Text;
                        newEmp.lastName       = lastNameTextBox.Text;
                        newEmp.startDate      = startDatePicker.Value.ToString();
                        newEmp.departmentName = departmentTextBox.Text;
                        newEmp.jobTitle       = jobTitleTextBox.Text;
                        newEmp.deleted        = false;
                        empList.Items.Clear();
                        if (!isEdit)
                        {
                            EmployeeList = businessLogic.AddEmployee(newEmp);
                        }
                        else
                        {
                            newEmp.empId = empIdTextBox.Text;
                            EmployeeList = businessLogic.EditEmployee(newEmp);
                            isEdit       = false;
                        }
                    }
                    else
                    {
                        checkFieldsLabel.Text = "Check Required Fields";
                    }
                    foreach (KeyValuePair <string, dynamic> pair in EmployeeList)
                    {
                        empList.Items.Add(pair.Value.firstName + " " + pair.Value.lastName + " - " + pair.Key);
                    }
                }
                else if (newEmpType == 1)
                {
                    if (monthlySalaryTextBox.Text != "")
                    {
                        Salary newEmp = new Salary();
                        newEmp.empType        = empType.Salary;
                        newEmp.monthlySalary  = Double.Parse(monthlySalaryTextBox.Text);
                        newEmp.firstName      = firstNameTextBox.Text;
                        newEmp.lastName       = lastNameTextBox.Text;
                        newEmp.startDate      = startDatePicker.Value.ToString();
                        newEmp.departmentName = departmentTextBox.Text;
                        newEmp.jobTitle       = jobTitleTextBox.Text;
                        newEmp.deleted        = false;
                        empList.Items.Clear();
                        if (!isEdit)
                        {
                            EmployeeList = businessLogic.AddEmployee(newEmp);
                        }
                        else
                        {
                            newEmp.empId = empIdTextBox.Text;
                            EmployeeList = businessLogic.EditEmployee(newEmp);
                            isEdit       = false;
                        }
                        foreach (KeyValuePair <string, dynamic> pair in EmployeeList)
                        {
                            empList.Items.Add(pair.Value.firstName + " " + pair.Value.lastName + " - " + pair.Key);
                        }
                    }
                    else
                    {
                        checkFieldsLabel.Text = "Check Required Fields";
                    }
                }
                else if (newEmpType == 2)
                {
                    if (monthlySalaryTextBox.Text != "" && commissionTextBox.Text != "" && grossSalesTextBox.Text != "")
                    {
                        Sales newEmp = new Sales();
                        newEmp.empType        = empType.Hourly;
                        newEmp.monthlySalary  = Double.Parse(monthlySalaryTextBox.Text);
                        newEmp.commission     = Double.Parse(commissionTextBox.Text);
                        newEmp.grossSales     = Double.Parse(grossSalesTextBox.Text);
                        newEmp.firstName      = firstNameTextBox.Text;
                        newEmp.lastName       = lastNameTextBox.Text;
                        newEmp.startDate      = startDatePicker.Value.ToString();
                        newEmp.departmentName = departmentTextBox.Text;
                        newEmp.jobTitle       = jobTitleTextBox.Text;
                        newEmp.deleted        = false;
                        empList.Items.Clear();
                        if (!isEdit)
                        {
                            EmployeeList = businessLogic.AddEmployee(newEmp);
                        }
                        else
                        {
                            newEmp.empId = empIdTextBox.Text;
                            EmployeeList = businessLogic.EditEmployee(newEmp);
                            isEdit       = false;
                        }
                        foreach (KeyValuePair <string, dynamic> pair in EmployeeList)
                        {
                            empList.Items.Add(pair.Value.firstName + " " + pair.Value.lastName + " - " + pair.Key);
                        }
                    }
                    else
                    {
                        checkFieldsLabel.Text = "Check Required Fields";
                    }
                }
                else if (newEmpType == 3)
                {
                    if (contractWageTextBox.Text != "")
                    {
                        Contract newEmp = new Contract();
                        newEmp.empType        = empType.Hourly;
                        newEmp.contractWage   = Double.Parse(contractWageTextBox.Text);
                        newEmp.firstName      = firstNameTextBox.Text;
                        newEmp.lastName       = lastNameTextBox.Text;
                        newEmp.startDate      = startDatePicker.Value.ToString();
                        newEmp.departmentName = departmentTextBox.Text;
                        newEmp.jobTitle       = jobTitleTextBox.Text;
                        newEmp.deleted        = false;
                        empList.Items.Clear();
                        if (!isEdit)
                        {
                            EmployeeList = businessLogic.AddEmployee(newEmp);
                        }
                        else
                        {
                            newEmp.empId = empIdTextBox.Text;
                            EmployeeList = businessLogic.EditEmployee(newEmp);
                            isEdit       = false;
                        }
                        foreach (KeyValuePair <string, dynamic> pair in EmployeeList)
                        {
                            empList.Items.Add(pair.Value.firstName + " " + pair.Value.lastName + " - " + pair.Key);
                        }
                    }
                    else
                    {
                        checkFieldsLabel.Text = "Check Required Fields";
                    }
                }

                clearHourly();
                clearSalary();
                clearSales();
                clearContract();
            }
            else
            {
                checkFieldsLabel.Text = "Check Required Fields";
            }
        }