Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string displayEmployeeInfo(string input, bool shouldLog)
        {
            string ret = "";

            if (tryFindEmployee(input))
            {
                Employee emp = findEmployee(input);
                switch (emp.GetType().Name)
                {
                case "FulltimeEmployee":
                    return(FulltimeEmployee.display((FulltimeEmployee)emp, shouldLog));

                //break;
                case "ParttimeEmployee":
                    return(ParttimeEmployee.display((ParttimeEmployee)emp, shouldLog));

                //break;
                case "ContractEmployee":
                    return(ContractEmployee.display((ContractEmployee)emp, shouldLog));

                //break;
                case "SeasonalEmployee":
                    return(SeasonalEmployee.display((SeasonalEmployee)emp, shouldLog));

                //break;
                default:
                    break;
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
 private void FillPartTimeEmployee(ParttimeEmployee e)
 {
     type.InnerText       = "Part Time";
     doh.InnerText        = e.DateOfHire.ToShortDateString();
     dot.InnerText        = e.DateOfTermination.ToShortDateString();
     hourlyRate.InnerText = e.HourlyRate.ToString();
 }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Employee != null)
            {
                // fill base employee information
                FillBaseEmployee();

                // display
                if (Employee is FulltimeEmployee)
                {
                    FulltimeEmployee ft = Employee as FulltimeEmployee;
                    FillFullTimeEmployee(ft);
                }
                else if (Employee is ParttimeEmployee)
                {
                    ParttimeEmployee pt = Employee as ParttimeEmployee;
                    FillPartTimeEmployee(pt);
                }
                else if (Employee is SeasonalEmployee)
                {
                    SeasonalEmployee sn = Employee as SeasonalEmployee;
                    FillSeasonalEmployee(sn);
                }
                else if (Employee is ContractEmployee)
                {
                    ContractEmployee ct = Employee as ContractEmployee;
                    FillContractEmployee(ct);
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            EmployeeList list = new EmployeeList();
            Employee     fte1, fte2, fte3, pte1, pte2;

            fte1 = new FulltimeEmployee("张无忌", 3200, 45);
            fte2 = new FulltimeEmployee("杨过", 2000, 40);
            fte3 = new FulltimeEmployee("段誉", 2400, 38);
            pte1 = new ParttimeEmployee("洪七公", 80, 20);
            pte2 = new ParttimeEmployee("郭靖", 60, 18);

            list.addEmployee(fte1);
            list.addEmployee(fte2);
            list.addEmployee(fte3);
            list.addEmployee(pte1);
            list.addEmployee(pte2);


            Console.WriteLine("财务部 访问数据!");

            Department fadep = new FADepartment();

            list.accept(fadep);


            Console.WriteLine();
            Console.WriteLine("人力资源部 访问数据!");

            Department hrdep = new HRDepartment();

            list.accept(hrdep);


            Console.ReadLine();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Method Name: AddPartTimeEmployee
        /// This function is called to add the PartTimeEmployee object that is newly created from the data
        /// the user has put in.
        /// </summary>
        /// <returns>A boolean indicating whether the adding operation was successful</returns>
        public bool AddPartTimeEmployee(ParttimeEmployee pt)
        {
            bool result = AddEmployee(pt);

            // To do
            return(result);
        }
Ejemplo n.º 6
0
        public void ParttimeEmployeeTest_Success()
        {
            ParttimeEmployee partTimeEmp = new ParttimeEmployee("Ronnie", "Skowron", "123456789", DateTime.Parse("2004-08-17"), DateTime.Parse("2006-08-14"), DateTime.Parse("2010-11-12"), 17.95);
            bool             success     = partTimeEmp.Validate();

            Assert.IsTrue(success);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This method adds a new Part Time Employee to the database.
        /// </summary>
        /// <param name="fName">The first name of the Part Time Employee.</param>
        /// <param name="lName">The last name of the Part Time Employee.</param>
        /// <param name="SIN">The Social Insurance Number of the Part Time Employee.</param>
        /// <param name="dateOfBirth">The Date of Birth of the Part Time Employee.</param>
        /// <param name="dateOfHire">The Date that the Part Time Employee was hired.</param>
        /// <param name="dateOfTermination">The Date that the Part Time Employee was terminated.</param>
        /// <param name="hourlyRate">The amount paid to the Part Time Employee per hour of work.</param>
        /// <returns>A bool. true if employee was added, false otherwise.</returns>
        public static bool AddParttimeEmployee(string fName, string lName, string SIN, DateTime dateOfBirth, DateTime dateOfHire, DateTime dateOfTermination, double hourlyRate)
        {
            bool empAdded = false;

            try
            {
                //Check if an employee with that sin number already exists
                bool employeeExists = PE.Any(x => x.socialInsuranceNumber == SIN);
                if (employeeExists)
                {
                    throw new Exception(); //The employee exists, it can't be added
                }
                else
                {
                    ParttimeEmployee emp   = new ParttimeEmployee(fName, lName, SIN, dateOfBirth, dateOfHire, dateOfTermination, hourlyRate);
                    bool             valid = emp.Validate();
                    if (valid)
                    {
                        PE.Add(emp);
                        Logging logger = new Logging();
                        logger.Log(lName + ", " + fName + " SIN: " + SIN + " - ADDED", "Employees", "AddParttimeEmployee");
                        empAdded = true;
                    }
                }
            }

            catch (Exception)
            {
                empAdded = false;
            }

            return(empAdded);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            // 1. Employee
            {
                EmployeeList      list = new EmployeeList();
                Employee.Employee fte1, fte2, fte3, pte1, pte2;
                fte1 = new FulltimeEmployee("张无忌", 3200.00, 45);
                fte2 = new FulltimeEmployee("杨过", 2000.00, 40);
                fte3 = new FulltimeEmployee("段誉", 2400.00, 38);
                pte1 = new ParttimeEmployee("洪七公", 80.00, 20);
                pte2 = new ParttimeEmployee("郭靖", 60.00, 18);

                list.AddEmployee(fte1);
                list.AddEmployee(fte2);
                list.AddEmployee(fte3);
                list.AddEmployee(pte1);
                list.AddEmployee(pte2);

                string     visitorStr = ConfigurationManager.AppSettings["visitor"];
                Department department = (Department)Assembly.Load("ch24_Visitor").CreateInstance(visitorStr);
                list.Accept(department);
            }

            // 2. Cart
            //    goods
            //    Cashier, Customer
            //    Apple (Weighing, Price), Book(Price)

            // 3. Award Check
            //    Teacher (){ Paper>10=>ResearchAward; Rating>90=>ExcellenceAward}
            //    Student (){ Paper>2=>ResearchAward; AvgScore>90=>ExcellenceAward}

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 实现财务部对兼职员工的访问
        /// </summary>
        /// <param name="employee"></param>
        public override void Visit(ParttimeEmployee employee)
        {
            int     workTime = employee.WorkTime;
            Decimal hourWage = employee.HourWage;

            Console.WriteLine("临时工{0}实际工资为:{1}元。",
                              employee.Name,
                              workTime * hourWage);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// \brief <b>Description</b>
        /// \details This function adds an employee to the collection given all the values
        /// of a valid Fulltime, Parttime, or Contract Employee
        /// </summary>
        /// <param name="type">the type of employee (Fulltime, Parttime, or Contract)</param>
        /// <param name="firstName"> - first name of the employee</param>
        /// <param name="lastName"> - last name of the employee</param>
        /// <param name="dob"> - Date of birth of the employee</param>
        /// <param name="sin"> - Social Insurance Number of the employee</param>
        /// <param name="startDate"> - Date of Hire of the employee</param>
        /// <param name="stopDate"> - Date of termination of the employee</param>
        /// <param name="payAmount"> - Annual salary of the employee</param>
        /// <returns>True if the employee was added successfully</returns>
        public bool addEmployee(EmployeeType type, string fName, string lName, DateTime dob, string sin,
                                DateTime startDate, DateTime?stopDate, double payAmount)
        {
            bool     retCode = false;
            Employee emp     = null;

            switch (type)
            {
            case EmployeeType.FT:
                if (retCode = FulltimeEmployee.validate(fName, lName, dob, sin, startDate, stopDate, payAmount))
                {
                    emp = new FulltimeEmployee(fName, lName, dob, sin, startDate, stopDate, payAmount);
                }
                break;

            case EmployeeType.PT:
                if (retCode = ParttimeEmployee.validate(fName, lName, dob, sin, startDate, stopDate, payAmount))
                {
                    emp = new ParttimeEmployee(fName, lName, dob, sin, startDate, stopDate, payAmount);
                }
                break;

            case EmployeeType.CT:
                if (stopDate != null)
                {
                    if (retCode = ContractEmployee.validate(lName, dob, sin, startDate, (DateTime)stopDate, payAmount))
                    {
                        emp = new ContractEmployee(lName, dob, sin, startDate, (DateTime)stopDate, payAmount);
                    }
                }
                break;

            default:
                break;
            }
            if (retCode)
            {
                if (EmployeeList.ContainsKey(emp.SIN))
                {
                    retCode = false;
                }
                else
                {
                    EmployeeList.Add(emp.SIN, emp);
                    Logging.Log("[Container.AddEmployee] Employee Added - " + emp.LastName + ", "
                                + emp.FirstName + " (" + emp.SIN + ") - VALID");
                }
            }
            return(retCode);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// \brief <b>Description</b>
        /// \details this Method contatinates all records in the employeelist and add's them to the Container
        /// </summary>
        /// <returns></returns>
        public List <string> concatAllRecords()
        {
            List <string> container = new List <string>();
            EmployeeType  type      = EmployeeType.Default;
            int           i         = 0;

            foreach (Employee currentEmployee in EmployeeList.Values)
            {
                type = getType(currentEmployee);
                switch (type)
                {
                case EmployeeType.FT:
                    container.Add(FulltimeEmployee.join((FulltimeEmployee)currentEmployee));
                    break;

                case EmployeeType.PT:
                    container.Add(ParttimeEmployee.join((ParttimeEmployee)currentEmployee));
                    break;

                case EmployeeType.CT:
                    container.Add(ContractEmployee.join((ContractEmployee)currentEmployee));
                    break;

                case EmployeeType.SN:
                    container.Add(SeasonalEmployee.join((SeasonalEmployee)currentEmployee));
                    break;

                default:
                    break;
                }
                i++;
            }

            container.Insert(0, "");
            for (i = 0; i < commentList.Count; i++)
            {
                KeyValuePair <int, string> item = commentList.ElementAt(i);
                if (item.Key > container.Count)
                {
                    commentList.Remove(item.Key);
                    commentList.Add(container.Count, item.Value);
                    i--;
                }
                else
                {
                    container.Insert(item.Key, item.Value);
                }
            }
            return(container);
        }
Ejemplo n.º 12
0
        public void ValidateOverloadedNormalTestCase()
        {
            bool     expected          = true;
            bool?    actual            = null;
            string   firstName         = "Jody";
            string   lastName          = "Markic";
            DateTime dob               = DateTime.Parse("1993-08-24");
            string   sin               = "123456782";
            DateTime dateOfHire        = DateTime.Parse("2012-04-12");
            DateTime dateOfTermination = DateTime.Parse("2015-06-04");
            double   hourlyRate        = 20.50;

            actual = ParttimeEmployee.validate(firstName, lastName, dob, sin, dateOfHire, dateOfTermination, hourlyRate);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void ValidateNormalTestCase()
        {
            bool             expected   = true;
            bool?            actual     = null;
            ParttimeEmployee ptEmployee = new ParttimeEmployee();

            ptEmployee.FirstName         = "Jody";
            ptEmployee.LastName          = "Markic";
            ptEmployee.DOB               = DateTime.Parse("1993-08-24");
            ptEmployee.SIN               = "123456782";
            ptEmployee.DateOfHire        = DateTime.Parse("2012-04-12");
            ptEmployee.DateOfTermination = DateTime.Parse("2015-06-04");
            ptEmployee.HourlyRate        = 20.50;

            actual = ParttimeEmployee.validate(ptEmployee);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// \brief <b>Description</b>
        /// \details This function adds an employee to the collection
        /// </summary>
        /// <param name="emp">This is the employee that will be added</param>
        /// <returns>True if the employee was added successfully</returns>
        public bool addEmployee(Employee emp)
        {
            bool retCode = false;

            switch (getType(emp))
            {
            case EmployeeType.FT:
                retCode = FulltimeEmployee.validate((FulltimeEmployee)emp);
                break;

            case EmployeeType.PT:
                retCode = ParttimeEmployee.validate((ParttimeEmployee)emp);
                break;

            case EmployeeType.CT:
                retCode = ContractEmployee.validate((ContractEmployee)emp);
                break;

            case EmployeeType.SN:
                retCode = SeasonalEmployee.validate((SeasonalEmployee)emp);
                break;

            default:
                break;
            }

            if (retCode)
            {
                if (EmployeeList.ContainsKey(emp.SIN))
                {
                    retCode = false;
                }
                else
                {
                    EmployeeList.Add(emp.SIN, emp);
                    Logging.Log("[Container.AddEmployee] Employee Added - " + emp.LastName + ", "
                                + emp.FirstName + " (" + emp.SIN + ") - VALID");
                }
            }
            return(retCode);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Fills full time employee
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private ParttimeEmployee FillPartTimeEmployee(SqlDataReader reader)
        {
            float            hourlyRate = 0;
            DateTime         doh;
            DateTime         dot;
            ParttimeEmployee pt = EmployeeFactory.CreatePartTimeEmployee();

            FillBaseEmployee(pt, reader);

            if (DateTime.TryParse(reader["dateOfHire"].ToString(), out doh))
            {
                pt.DateOfHire = doh;
            }
            else
            {
                pt.DateOfHire = DateTime.MinValue;
            }

            if (DateTime.TryParse(reader["dateOfTermination"].ToString(), out dot))
            {
                pt.DateOfTermination = dot;
            }
            else
            {
                pt.DateOfTermination = DateTime.MinValue;
            }

            if (float.TryParse(reader["hourly_rate"].ToString(), out hourlyRate))
            {
                pt.HourlyRate = hourlyRate;
            }
            else
            {
                pt.HourlyRate = null;
            }


            return(pt);
        }
Ejemplo n.º 16
0
 public abstract void Visit(ParttimeEmployee employee);
Ejemplo n.º 17
0
        protected void btnModify_Click(object sender, EventArgs e)
        {
            bool             isAllValid      = true;
            ParttimeEmployee pt              = new ParttimeEmployee();
            FulltimeEmployee ft              = new FulltimeEmployee();
            SeasonalEmployee sl              = new SeasonalEmployee();
            ContractEmployee ct              = new ContractEmployee();
            List <string>    normalUpdates   = new List <string>();
            List <string>    specificUpdates = new List <string>();
            string           updateString    = "UPDATE tb_Emp SET";
            string           updateSpecific  = "UPDATE tb_";
            int    empID   = 0;
            string empType = Session["type"].ToString();

            if (empType == "FT")
            {
                updateSpecific += "Ft";
            }
            else if (empType == "PT")
            {
                updateSpecific += "Pt";
            }
            else if (empType == "SL")
            {
                updateSpecific += "Sl";
            }
            else if (empType == "CT")
            {
                updateSpecific += "Ct";
            }

            updateSpecific += "Emp SET ";

            string endUpdate = " OUTPUT INSERTED.empID WHERE socialInsNumber=" + Session["sin"] + " and firstName='" + Session["fname"] + "' and lastName='" + Session["lname"] + "' and companyName='" + Session["company"] + "';";

            //string updateSpecificString = "UPDATE " +

            //for fulltime
            if (ftfName.Text != "")
            {
                if (!ft.SetFirstName(ftfName.Text))
                {
                    ftfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + ftfName.Text + "'");
            }
            if (ftlName.Text != "")
            {
                if (!ft.SetLastName(ftlName.Text))
                {
                    ftlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + ftlName.Text + "'");
            }
            if (ftSin.Text != "")
            {
                if (!ft.SetSIN(ftSin.Text.Replace(" ", "")))
                {
                    ftSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ftSin.Text);
            }
            if (ftDOB.Text != "")
            {
                if (!ft.SetDOB(ftDOB.Text.Replace(" ", "")))
                {
                    ftDOBError.Text += "<b>Date Of Hire</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth'" + ftDOB.Text + "'");
            }
            if (ftDateHire.Text != "")
            {
                if (!ft.SetDateOfHire(ftDateHire.Text.Replace(" ", "")))
                {
                    ftDateHireError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfHire='" + ftDateHire.Text + "'");
            }
            if (ftDateTerm.Text != "")
            {
                if (!ft.SetDateOfTermination(ftDateTerm.Text.Replace(" ", "")) && ftDateTerm.Text != "")
                {
                    ftDateTermError.Text += "<b>Date Of Termination</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfTermination='" + ftDateTerm.Text + "'");
            }
            if (ftSalary.Text != "")
            {
                if (!ft.SetSalary(ftSalary.Text.Replace(" ", "")) && ftSalary.Text != "")
                {
                    ftSalaryError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid          = false;
                }
                specificUpdates.Add("salary=" + ftSalary.Text + "");
            }

            //for part time
            if (ptfName.Text != "")
            {
                if (!pt.SetFirstName(ptfName.Text))
                {
                    ptfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + ptfName.Text + "'");
            }
            if (ptlName.Text != "")
            {
                if (!pt.SetLastName(ptlName.Text) || ptlName.Text == "")
                {
                    ptlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + ptlName.Text + "'");
            }
            if (ptSin.Text != "")
            {
                if (!pt.SetSIN(ptSin.Text.Replace(" ", "")))
                {
                    ptSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ptSin.Text);
            }
            if (ptDOB.Text != "")
            {
                if (!pt.SetDOB(ptDOB.Text.Replace(" ", "")))
                {
                    ptDOBError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + ptDOB.Text + "'");
            }
            if (ptDateHire.Text != "")
            {
                if (!pt.SetDateOfHire(ptDateHire.Text.Replace(" ", "")))
                {
                    ptDateHireError.Text += "<b>Date Of Hire</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfHire='" + ptDateHire.Text + "'");
            }
            if (ptDateTerm.Text != "")
            {
                if (!pt.SetDateOfTermination(ptDateTerm.Text.Replace(" ", "")) && ptDateTerm.Text != "")
                {
                    ptDateTermError.Text += "<b>Date Of Termination</b> should have valid date format";
                    isAllValid            = false;
                }
                specificUpdates.Add("dateOfTermination='" + ptDateTerm.Text + "'");
            }
            if (ptWage.Text != "")
            {
                if (!pt.SetHourlyRate(ptWage.Text.Replace(" ", "")) && ptWage.Text != "")
                {
                    ptWageError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid        = false;
                }
                specificUpdates.Add("hourlyRate=" + ptWage.Text);
            }

            //for seasonal
            if (slfName.Text != "")
            {
                if (!sl.SetFirstName(slfName.Text) || slfName.Text == "")
                {
                    slfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("firstName='" + slfName.Text + "'");
            }
            if (sllName.Text != "")
            {
                if (!sl.SetLastName(sllName.Text) || sllName.Text == "")
                {
                    sllNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid         = false;
                }
                normalUpdates.Add("lastName='" + sllName.Text + "'");
            }
            if (slSin.Text != "")
            {
                if (!sl.SetSIN(slSin.Text.Replace(" ", "")))
                {
                    slSinError.Text += "<b>SIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber=" + ftfName.Text);
            }
            if (slDOB.Text != "")
            {
                if (!sl.SetDOB(slDOB.Text.Replace(" ", "")))
                {
                    slDOBError.Text += "<b>Date Of Birth</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + slDOB.Text + "'");
            }
            if (slSeason.Text != "" && Session["type"].ToString() == "SL")
            {
                if (!sl.SetSeason(slSeason.Text.Replace(" ", "")) && slSeason.Text != "")
                {
                    slSeasonError.Text += "<b>Season</b> must be valid. It should not be possible to get this error. Look at you, you little hacker";
                    isAllValid          = false;
                }
                specificUpdates.Add("season='" + slSeason.Text + "'");
            }
            if (slPcPay.Text != "")
            {
                if (!sl.SetPiecePay(slPcPay.Text.Replace(" ", "")) && slPcPay.Text != "")
                {
                    slPcPayError.Text += "<b>Salary</b> should be a number higher than 0";
                    isAllValid         = false;
                }
                specificUpdates.Add("piecePay='" + slPcPay.Text + "'");
            }

            //for contract
            if (ctName.Text != "")
            {
                if (!ct.SetLastName(ctName.Text))
                {
                    ctNameError.Text += "<b>Company Name</b> can only contain the following characters: [A-Za-z. -]\n";
                    isAllValid        = false;
                }
                normalUpdates.Add("lastName='" + ctName.Text + "'");
            }
            if (ctBin.Text != "")
            {
                if (!ct.SetSIN(ctBin.Text.Replace(" ", "")))
                {
                    ctBinError.Text += "<b>BIN</b> should be 9-digit number";
                    isAllValid       = false;
                }
                normalUpdates.Add("socialInsNumber='" + ctBin.Text + "'");
            }
            if (ctDOI.Text != "")
            {
                if (!ct.SetDOB(ctDOI.Text.Replace(" ", "")))
                {
                    ctDOIError.Text += "<b>Date Of Incorporation</b> should have valid date format";
                    isAllValid       = false;
                }
                normalUpdates.Add("dateOfBirth='" + ctDOI.Text + "'");
            }
            if (ctStart.Text != "")
            {
                if (!ct.SetContractStartDate(ctStart.Text.Replace(" ", "")))
                {
                    ctStartError.Text += "<b>Contract Start Date</b> must be valid. It should not be possible to get this error. Look at you, you little hacker";
                    isAllValid         = false;
                }
                specificUpdates.Add("dateStart='" + ctStart.Text + "'");
            }
            if (ctEnd.Text != "")
            {
                if (!ct.SetContractEndDate(ctEnd.Text.Replace(" ", "")))
                {
                    ctEndError.Text += "<b>Contract End Date</b> should have valid date format";
                    isAllValid       = false;
                }
                specificUpdates.Add("dateStop='" + ctEnd.Text + "'");
            }
            if (ctAmt.Text != "")
            {
                if (!ct.SetFixedContractAmt(ctAmt.Text.Replace(" ", "")))
                {
                    ctAmtError.Text += "<b>Contract Amount</b> should be a number higher than 0";
                    isAllValid       = false;
                }
                specificUpdates.Add("fixedCtAmt='" + ctAmt.Text + "'");
            }
            if (isAllValid)
            {
                int emp = 0;
                int.TryParse(Session["empID"].ToString(), out emp);
                bool first = true;
                if (normalUpdates.Count < 1)
                {
                    normalUpdates.Add("lastName='" + Session["lname"] + "'");
                }
                foreach (string s in normalUpdates)
                {
                    if (first)
                    {
                        updateString += " " + s;
                        first         = false;
                    }
                    else
                    {
                        updateString += ", " + s;
                    }
                    string fieldValue = s.Substring(0, s.IndexOf('='));
                    string oldVal     = sup.GetPreviousValue(conString, emp, @s, "");
                    string newVal     = s;
                    newVal = newVal.Replace(fieldValue + @"='", "");
                    sup.CreateAudit(conString, userName, emp.ToString(), fieldValue, oldVal, newVal);
                }
                updateString += endUpdate;

                first = true;
                foreach (string s in specificUpdates)
                {
                    if (first)
                    {
                        updateSpecific += " " + s;
                        first           = false;
                    }
                    else
                    {
                        updateSpecific += ", " + s;
                    }
                    string oldVal = sup.GetPreviousValue(conString, emp, @s, empID.ToString());
                }


                try
                {
                    using (SqlConnection connect = new SqlConnection(conString))
                    {
                        connect.Open();
                        using (SqlCommand changeCmd = new SqlCommand())
                        {
                            changeCmd.Connection  = connect;
                            changeCmd.CommandType = CommandType.Text;
                            changeCmd.CommandText = updateString;
                            empID = (Int32)changeCmd.ExecuteScalar();
                            changeCmd.Dispose();
                        }
                        updateSpecific += " WHERE empID=" + empID;
                        using (SqlCommand changeCmd = new SqlCommand())
                        {
                            changeCmd.Connection  = connect;
                            changeCmd.CommandType = CommandType.Text;
                            changeCmd.CommandText = updateSpecific;
                            changeCmd.ExecuteNonQuery();
                            changeCmd.Dispose();
                        }
                    }
                }
                catch (Exception exce)
                {
                }
            }
        }
Ejemplo n.º 18
0
 public void ParttimeEmployeeTest_Exception()
 {
     ParttimeEmployee pEmp = new ParttimeEmployee("David", "Pitters", "123456789", DateTime.Parse("1996-02-18"), DateTime.Parse("2001-05-20"), DateTime.Parse("2012-12-21"), -1.00);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Method Name: LoadContainer
        /// The function is called to populate the container object with the data from the database file
        /// </summary>
        /// <param name="fileName">the Name of the database file</param>
        /// <returns>A boolean indicating whether the operation was successful</returns>
        public bool LoadContainer()
        {
            bool result = true;

            string[] fileContents; // create string to hold file contents
            string[] input;
            Int32    validCount = 0;
            Int32    lineCount  = 0;
            Int32    entryCount = 0;
            Employee e          = new Employee();
            bool     duplicate  = false;

            fileContents = dbFile.dBaseOpen_R(); // fill the string with file contents
            container.Clear();
            Console.Clear();
            foreach (string s in fileContents)
            {
                lineCount++;
                if (s != "")
                {
                    input = s.Split('|');
                    if (s[0] == 'F')
                    {
                        entryCount++;
                        FulltimeEmployee f = new FulltimeEmployee();
                        if (!f.SetLastName(input[1]) || !f.SetFirstName(input[2]) || !f.SetSIN(input[3]) || !f.SetDOB(input[4]) || !f.SetDateOfHire(input[5]) || !f.SetDateOfTermination(input[6]) || !f.SetSalary(input[7]))
                        {
                            log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == f.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(f);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'P')
                    {
                        entryCount++;
                        ParttimeEmployee p = new ParttimeEmployee();
                        if (!p.SetLastName(input[1]) || !p.SetFirstName(input[2]) || !p.SetSIN(input[3]) || !p.SetDOB(input[4]) || !p.SetDateOfHire(input[5]) || !p.SetDateOfTermination(input[6]) || !p.SetHourlyRate(input[7]))
                        {
                            log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == p.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(p);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'C')
                    {
                        entryCount++;
                        ContractEmployee c = new ContractEmployee();
                        if (!c.SetLastName(input[1]) || !c.SetFirstName(input[2]) || !c.SetSIN(input[3]) || !c.SetDOB(input[4]) || !c.SetContractStartDate(input[5]) || !c.SetContractEndDate(input[6]) || !c.SetFixedContractAmt(input[7]))
                        {
                            log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == c.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(c);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                    else if (s[0] == 'S')
                    {
                        entryCount++;
                        SeasonalEmployee n = new SeasonalEmployee();
                        if (!n.SetLastName(input[1]) || !n.SetFirstName(input[2]) || !n.SetSIN(input[3]) || !n.SetDOB(input[4]) || !n.SetSeason(input[5]) || !n.SetPiecePay(input[6]))
                        {
                            log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                            result = false;
                        }
                        else
                        {
                            foreach (Object o in container)
                            {
                                e = (Employee)o;
                                if (e.GetSIN() == n.GetSIN())
                                {
                                    duplicate = true;
                                }
                            }
                            if (duplicate == false)
                            {
                                container.Add(n);
                                validCount++;
                            }
                            else
                            {
                                log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED"));
                                duplicate = false;
                                result    = false;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("\n\n>>>>>>>>>>>>>>>> TOTAL LINES READ           : " + lineCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL ENTRIES FOUND        : " + entryCount);
            Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL VALID ENTRIES LOADED : " + validCount);
            return(result);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// 实现人力资源部对兼职员工的访问
 /// </summary>
 /// <param name="employee"></param>
 public override void Visit(ParttimeEmployee employee)
 {
     Console.WriteLine("临时工{0}实际工作时间为:{1}小时。",
                       employee.Name,
                       employee.WorkTime);
 }
Ejemplo n.º 21
0
        public void addPtEmp()
        {
            ParttimeEmployee pt         = new ParttimeEmployee();
            bool             isAllValid = true;

            ptfNameError.Text    = "";
            ptlNameError.Text    = "";
            ptSinError.Text      = "";
            ptDateHireError.Text = "";
            ptDOBError.Text      = "";
            ptDateTermError.Text = "";
            ptWageError.Text     = "";

            if (!pt.SetFirstName(ptfName.Text) && ptfName.Text != "")
            {
                ptfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n";
                isAllValid         = false;
            }
            if (!pt.SetLastName(ptlName.Text) && ptlName.Text != "")
            {
                ptlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n";
                isAllValid         = false;
            }
            if (!pt.SetSIN(ptSin.Text.Replace(" ", "")) && ptSin.Text != "")
            {
                ptSinError.Text += "<b>SIN</b> should be 9-digit number";
                isAllValid       = false;
            }
            if (!pt.SetDOB(ptDOB.Text.Replace(" ", "")) && ptDOB.Text != "")
            {
                ptDOBError.Text += "<b>Date Of Birth</b> should have valid date format";
                isAllValid       = false;
            }
            if (!pt.SetDateOfHire(ptDateHire.Text.Replace(" ", "")) && ptDateHire.Text != "")
            {
                ptDateHireError.Text += "<b>Date Of Hire</b> should have valid date format";
                isAllValid            = false;
            }
            if ((!pt.SetDateOfTermination(ptDateTerm.Text.Replace(" ", "")) && ptDateTerm.Text != "") || (ptReason.Text == "" && ptDateTerm.Text != ""))
            {
                ptDateTermError.Text += "<b>Date Of Termination</b> should have valid date format and needs Reason for leaving";
                isAllValid            = false;
            }
            if (!pt.SetHourlyRate(ptWage.Text.Replace(" ", "")) && ptWage.Text != "")
            {
                ptWageError.Text += "<b>Salary</b> should be a number higher than 0";
                isAllValid        = false;
            }
            if (isAllValid)
            {
                string activity = "0";
                if (ptDateHire.Text != "" && ptWage.Text != "" && ptDOB.Text != "" && ptSin.Text != "")
                {
                    activity = "1";
                    if (ptReason.Text != "")
                    {
                        activity = "2";
                    }
                }
                if (addEmpDB("PT", ptCompany.Text, ptfName.Text, ptlName.Text, ptSin.Text, ptDOB.Text, activity))
                {
                    addPtEmpDB(returnID, ptDateHire.Text, ptDateTerm.Text, ptWage.Text);
                    sucessLbl.Text = ptfName.Text + " Has been succesfully added";
                }
            }
        }