程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> List IEnumerable,listienumerable

List IEnumerable,listienumerable

編輯:C#入門知識

List IEnumerable,listienumerable


     //按部門匯總
            IEnumerable<WeekReportWithDepartmentInfo> report = summary
            .GroupBy(x => new
            {
                x.DeptID,
                x.DeptName
            }).Select(g => new WeekReportWithDepartmentInfo
            {
                DeptID = g.Key.DeptID,
                DeptName = g.Key.DeptName,
                TotalNumber = g.Count(),
                WorkOvertime = g.Sum(a => a.WorkOverHours),
                WorkLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.WorkHours),
                PersonalLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.PersonalLeave),
                PaidLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.PaidLeave),
                LateAndLeavingEarly = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.LateAndLeavingEarly)
            }).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);

            //總行數
            int rows = summary
            .GroupBy(x => new
            {
                x.DeptID,
                x.DeptName
            }).Count();

            List<WeekReportWithDepartmentInfo> reportlist = new List<WeekReportWithDepartmentInfo>();
            IEnumerable<string> tempEmail;
            foreach (WeekReportWithDepartmentInfo item in report)
            {
                //找到當前部門的所有人
                tempEmail = employees.Where(e => e.DeptID == item.DeptID).Select(s => s.Email);
                item.TotalNumber = summary.Where(e => e.DeptID == item.DeptID).GroupBy(x => new {x.EmpID}).Count();
                ////匯總所有人的事假
                //item.PersonalLeave = personalLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);

                ////匯總所有人的帶薪假總工時
                //item.PaidLeave = paidLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);

                //double jialeave=JiaLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);
                ////遲到早退工時
                //item.LateAndLeavingEarly = item.LateAndLeavingEarly - jialeave;
                //item.LateAndLeavingEarly = item.LateAndLeavingEarly < 0 ? 0 : item.LateAndLeavingEarly;

                //匯總所有人的加班總工時
                //item.WorkOvertime = workOvertime.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);

                //全勤人數
                item.QqingNumber = item.TotalNumber - summary.Where(s => s.IsNeedAttendance && s.DeptID == item.DeptID && s.AttendanceState != 9).Select(s => s.EmpID).Distinct().Count();//去重復
                //正常考勤時 item.WorkLeave

                //缺勤率
                item.BsenteeismRatio = (item.LateAndLeavingEarly + item.PersonalLeave + item.PaidLeave) / item.WorkLeave * 100;
                //加班率
                item.OvertimeRatio = item.WorkOvertime / item.WorkLeave * 100;

                reportlist.Add(item);
            }



            //IEnumerable<KeyValue<string, double>> JiaLeave = leaveWithWeek.Where(l => l.TypeName != LeaveType.加班
            //                                                               && l.TypeName != LeaveType.補打卡)
            //                                                    .GroupBy(x => new { x.Email })
            //                                                    .Select(g => new KeyValue<string, double>
            //                                                    {
            //                                                        Key = g.Key.Email,
            //                                                        Value = g.Sum(a => (a.AskLeaveHour))
            //                                                    });


                            //簽到(9:00-12:00)
                            tempAtdRec = attendances.Where(a => a.EmpID == emp.EmpID && a.RecDateTime > workDay.GetInTime().AddHours(-4) && a.RecDateTime < workDay.GetOutTime()).OrderBy(a => a.RecDateTime);
                            if (tempAtdRec.Count() > 0)
                            {
                                info.SigninTime = tempAtdRec.First().RecTime;
                                info.SigninDateTime = tempAtdRec.First().RecDateTime;
                            }
                            //簽退(13:30-18:00)
                            tempAtdRec = attendances.Where(a => a.EmpID == emp.EmpID && a.RecDateTime > workDay.GetInTime() && a.RecDateTime < workDay.GetInTime().AddDays(1).AddHours(-4)).OrderByDescending(a => a.RecDateTime);
                            if (tempAtdRec.Count() > 0)
                            {
                                info.SignoutTime = tempAtdRec.First().RecTime;
                                info.SignoutDateTime = tempAtdRec.First().RecDateTime;
                            }

                         

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved