void IJob.Execute()
        {
            Trace.WriteLine("Commission");
            var commissionemployees = from h in db.Employees//找出所有提成员工
                                      where h.Position == position.COMMISION
                                      select h;

            foreach (Employee e in commissionemployees.ToList())
            {
                decimal totalcommission = 0;

                var purchaseorders = from h in db.PurchaseOrders
                                     where h.EmployeeName == e.Email
                                     select h;

                foreach (PurchaseOrder po in purchaseorders)
                {
                    if (po.Date.Month == DateTime.Now.Month)//计算发薪日所在月份的销售总额
                    {
                        totalcommission += po.Total;
                    }
                }

                Trace.WriteLine(e.Email + ":" + (e.Salary + totalcommission * (decimal)e.CommisonRate - e.Deduction));
                ///*
                PayRoll p = new PayRoll();
                p.EmployeeName  = e.Email;
                p.Salary        = e.Salary + totalcommission * (decimal)e.CommisonRate - e.Deduction;
                p.PayDate       = DateTime.Now;
                p.PaymentMethod = e.PaymentMethod;
                if (e.PaymentMethod == paymentmethod.MAIL)
                {
                    p.MailAddress = e.MailAddress;
                }
                if (e.PaymentMethod == paymentmethod.TRANSFER)
                {
                    p.BankName    = e.BankName;
                    p.BankAccount = e.BankAccount;
                }
                db.PayRolls.Add(p);
                db.SaveChanges();
                //*/
                //如果员工标记为要删除,则付完薪水后删除
                if (e.isDeleted != null)
                {
                    db.Employees.Remove(e);
                    db.SaveChanges();
                }
            }
        }
        void IJob.Execute()
        {
            Trace.WriteLine("Salary");
            var salaryemployees = from h in db.Employees//找出所有普通员工
                                  where h.Position == position.SALARY
                                  select h;

            foreach (Employee e in salaryemployees.ToList())
            {
                Trace.WriteLine(e.Email + ":" + (e.Salary - e.Deduction));
                ///*
                PayRoll p = new PayRoll();
                p.EmployeeName  = e.Email;
                p.Salary        = e.Salary - e.Deduction;
                p.PayDate       = DateTime.Now;
                p.PaymentMethod = e.PaymentMethod;
                if (e.PaymentMethod == paymentmethod.MAIL)
                {
                    p.MailAddress = e.MailAddress;
                }
                if (e.PaymentMethod == paymentmethod.TRANSFER)
                {
                    p.BankName    = e.BankName;
                    p.BankAccount = e.BankAccount;
                }
                db.PayRolls.Add(p);
                db.SaveChanges();
                //*/
                //如果员工标记为要删除,则付完薪水后删除
                if (e.isDeleted != null)
                {
                    db.Employees.Remove(e);
                    db.SaveChanges();
                }
            }
        }
        void IJob.Execute()
        {
            Trace.WriteLine("Hour");
            var houremployees = from h in db.Employees//找出所有时工
                                where h.Position == position.HOUR
                                select h;

            List <string> datelist = new List <string>();

            for (int i = 0; i < 7; i++)
            {
                datelist.Add(weekstart.AddDays(i).ToString("yyyy-MM-dd"));
            }

            foreach (Employee e in houremployees.ToList())
            {
                decimal totalhour = 0;

                var timecards = from h in db.Timecards
                                where h.EmployeeName == e.Email
                                select h;
                timecards = timecards.Where(t => t.isSubmitted != null);

                foreach (Timecard t in timecards)
                {
                    foreach (string s in datelist)
                    {
                        if (t.Date.ToString("yyyy-MM-dd").Equals(s))
                        {
                            if (t.Hours <= 8)
                            {
                                totalhour += t.Hours;
                            }
                            else
                            {
                                totalhour += t.Hours * 1.5M;
                            }
                        }
                    }
                }

                Trace.WriteLine(e.Email + ":" + (totalhour * e.HourRate - e.Deduction));
                ///*
                PayRoll p = new PayRoll();
                p.EmployeeName  = e.Email;
                p.Salary        = totalhour * e.HourRate - e.Deduction;
                p.PayDate       = DateTime.Now;
                p.PaymentMethod = e.PaymentMethod;
                if (e.PaymentMethod == paymentmethod.MAIL)
                {
                    p.MailAddress = e.MailAddress;
                }
                if (e.PaymentMethod == paymentmethod.TRANSFER)
                {
                    p.BankName    = e.BankName;
                    p.BankAccount = e.BankAccount;
                }
                db.PayRolls.Add(p);
                db.SaveChanges();
                //*/
                //如果员工标记为要删除,则付完薪水后删除
                if (e.isDeleted != null)
                {
                    db.Employees.Remove(e);
                    db.SaveChanges();
                }
            }
        }