当用户超时的第二天超过生物识别读数时,我在获取结构化的第一个条目和最后一个条目时遇到问题。但是,如果进出时间是在同一天,我可以按照我想要的方式对其进行格式化..
这是我的代码:
IEnumerable<biometric> dtrs = new List<biometric>()
{
new biometric{Id = 1, InOut = 0, DateTime = new DateTime(2013,5,5,8,0,0)},
new biometric{Id = 2, InOut = 0, DateTime = new DateTime(2013,5,5,8,0,5)},
new biometric{Id = 3, InOut = 0, DateTime = new DateTime(2013,5,5,8,1,0)},
new biometric{Id = 4, InOut = 0, DateTime = new DateTime(2013,5,5,8,2,0)},
//here is my problem getting this paired to
new biometric{Id = 5, InOut = 0, DateTime = new DateTime(2013,5,5,18,0,0)},
new biometric{Id = 1, InOut = 1, DateTime = new DateTime(2013,5,5,18,0,0)},
new biometric{Id = 2, InOut = 1, DateTime = new DateTime(2013,5,5,17,5,5)},
new biometric{Id = 3, InOut = 1, DateTime = new DateTime(2013,5,5,17,5,10)},
new biometric{Id = 4, InOut = 1, DateTime = new DateTime(2013,5,5,17,10,0)},
//this Entry here
new biometric{Id = 5, InOut = 1, DateTime = new DateTime(2013,5,6,3,0,0)},
};
var asd = dtrs.GroupBy(x => new { x.Id, x.DateTime.Date }, (key, group) => new
{
Key1 = key.Date,
Key2 = key.Id,
Result = group.OrderBy(a => a.DateTime).ToList()
})
//checks if the grouping result has one timein and 1 timeout or more
.Where(a => a.Result.Where(z => z.InOut == 1).Count() >= 1 && a.Result.Where(z => z.InOut == 0).Count() >= 1)
.Select(a => new dtr() { employeeId = a.Key2, TimeIn = a.Result.FirstOrDefault(b => b.InOut == 1).DateTime, TimeOut = a.Result.LastOrDefault(c => c.InOut == 0).DateTime });
private class biometric
{
public int Id { get; set; }
public DateTime DateTime { get; set; }
public int InOut { get; set; }
}
private class dtr
{
public int employeeId { get; set; }
public DateTime TimeIn { get; set; }
public DateTime TimeOut { get; set; }
}
我想配对这个
新的生物识别{Id = 5, InOut = 0, DateTime = new DateTime(2013,5,5,18,0,0)},
到这个
新的生物特征{Id = 5, InOut = 1, DateTime = new DateTime(2013,5,6,3,0,0)},
任何解决方法或建议?