字典库排序

有童鞋问到字典库的排序难点,那里差不离介绍三个新技巧。

     //按部门集中
            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);

多少字典使用情状:请假流程里的请假类型,有病假、事假、调休等。
定义数码字典,并且在流水生产线中采用SheetDropDownListSheetRadioButtonList展现由用户来选择,如图:

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

图片 1 

            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);

使用SheetDropDownList,并且安装该控件的属性MasterDataCategory为“请假类型”,其代码或者如下:

                //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;

<SheetControls:SheetDropDownListID=”SheetDropDownList1″runat=”server”DataField=”请假类型”MasterDataCategory=”请假类型”></SheetControls:SheetDropDownList>
在表单中显得的效率如下:

                //汇总全部人的突击总工程师作时间
                //item.WorkOvertime = workOvertime.Where(p =>
tempEmail.Contains(p.Key)).Sum(s => s.Value);

图片 2 

                //全勤人数
                item.QqingNumber = item.TotalNumber – summary.Where(s
=> s.IsNeedAttendance && s.DeptID == item.DeptID && s.AttendanceState
!= 9).Select(s => s.EmpID).Distinct().Count();//去重复
                //平常考勤时 item.WorkLeave

SheetDropDownList使用多少字典

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

表单设计器中使用

                reportlist.Add(item);
            }

图片 3 

            //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))
            //                                                    });

对于SheetDropDownListSheetCheckBoxList、SheetRadioButtonList控件,能够一直绑定数据字典突显选项。

                            //签到(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;
                            }

多少字典尽管方便,一相当大心就建多了,字典库多了用起来也是有点麻烦。

                         

图片 4 

上边教给我们1个简单实用的排序技能.
率先找到

 

\Portal\Admin\MvcDesigner\MvcDesignerService.ashx

 

下边包车型大巴那几个函数

 

#region 获取数据字典

   

        public void GetMasterDataCategory(HttpContext context)

        {

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

            Dictionary<string, string> table =
OThinker.H3.WorkSheet.AppUtility.Engine.MetadataRepository.GetCategoryTable();

            foreach (string key in
table.OrderBy(s=>s.Value).Select(x=>x.Key))

            {

                items.Add(table[key]);

            }

            context.Response.Write(JSSerializer.Serialize(items));

        }

   

        #endregion

 

把原本的 table.Keys 改成

 

table.OrderBy(s=>s.Value).Select(x=>x.Key)

 

能够任意改成喜欢的排序都得以。

相关文章