コード例 #1
0
ファイル: EmployeerController.cs プロジェクト: Iovezq/Puaa
        /// <summary>
        /// 根据员工id删除员工的方法
        /// </summary>
        /// <returns></returns>
        public ActionResult DelEmByID()
        {
            int  id                = Convert.ToInt32(Request["delid"]);
            bool isDelemp          = dal.DelEmployeerByID(id); //删除该员工
            bool isDelsalary       = false;                    //删除该员工的薪资
            bool isDelsalaryRecord = false;                    //删除该员工的薪资记录
            bool isDelCalendar     = false;                    //删除该员工的日程

            if (isDelemp)
            {
                //查询该员工有无薪资有则删除该员工的薪资
                Payroll emerpay = dal.SelEmployeerSalaryByID(id);
                if (emerpay != null)
                {
                    isDelsalary = dal.DelEmployeerSalaryByID(emerpay);
                    //查询该员工有无薪资记录有则删除该员工的薪资记录
                    PayrollDal          pdal   = new PayrollDal();
                    List <SalaryRecord> srlist = pdal.GetByID(id);
                    if (srlist.Count > 0 && isDelsalary == true)
                    {
                        isDelsalaryRecord = pdal.DelByID(srlist);
                    }
                    //查询该员工有无日程有则删除该员工的日程
                    CalendarsDal    cdal = new CalendarsDal();
                    List <Calendar> cal  = cdal.GetCalendarByID(id);
                    if (cal.Count > 0)
                    {
                        isDelCalendar = cdal.DelCalendarByID(cal);
                    }
                    if (isDelsalary && isDelsalaryRecord && isDelCalendar)
                    {
                        return(RedirectToAction("EmployeerList"));
                    }
                }
                else
                {
                    //查询该员工有无日程有则删除该员工的日程
                    CalendarsDal    cdal = new CalendarsDal();
                    List <Calendar> cal  = cdal.GetCalendarByID(id);
                    if (cal.Count > 0)
                    {
                        isDelCalendar = cdal.DelCalendarByID(cal);
                    }
                    if (isDelCalendar)
                    {
                        return(RedirectToAction("EmployeerList"));
                    }
                }
            }
            return(RedirectToAction("EmployeerList"));
        }