如何在登录时间,注销时间,总小时数,总日志中创建每日考勤报告 [英] How to create daily attendance report in login time, logout time, total hours, total logs

查看:68
本文介绍了如何在登录时间,注销时间,总小时数,总日志中创建每日考勤报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示每日出勤::: 

Iam创建表名tblattendance

创建 3 coulmns:
OrgId
UserId
DateOfTransaction

插入数据:
orgid useid DateOfTransaction
1 1 06-02-2016: 08 12
1 2 06-02 -2016: 08 20
1 3 06-02-2016: 08 30
1 1 06-02-2016: 15 43
1 1 06-02-2016: 15 45
1 2 06-02-2016: 15 43

evng time 1 3 用户ID仅打卡但不打用户ID 2

i想要显示每日出勤率

用户ID日期登录时间退出时间总小时总日志
1 06-02-2016 08 12 15 45 7 小时 12 分钟 3
2 06-02-2016 08 20 15 43 7 小时 10 分钟 2
3 06-02-2016 08 30 - - 1
2





我尝试了什么:



i只知道显示

从tblattendance中选择*其中tblattendance = 06-02-2016

此代码仅显示

orgid useid DateOfTransaction

1 1 06-02-2016:08:12

1 2 06-02-2016:08:20

.........



i希望显示ogin时间,退出时间,总小时数,总记录数

解决方案

I要去帮助您通过向您展示如何使用LINQ创建的用户名有组织的DataRows集合启动:<预LANG =C#>的使用系统;
使用 System.Collections.Generic;
使用 System.Data;
使用 System.Linq;

// 某些NameSpace中某些类的某些方法
var userIDGroups = dt.Rows.Cast< datarow>()
.GroupBy(row = > row [ 1 ])
。选择(grp = > grp.ToList ())ToList();

foreach var grp in userIDGroups)
{
Console.WriteLine( UserID:{0} ,grp [ 0 ]。ItemArray [ 1 ]);

foreach var row in grp)
{
Console.WriteLine( 日期:{0} ,row.ItemArray [ 2 ]);
}
}

此代码:



a。将DataRowCollecton转换为IEnumerable,以便我们可以使用Linq.



b。然后它使用'GroupBy来获取一组'组(实际上是行的IEnumerables ......一个'LookUp对象),由'UserID字段...行中的字段#2选择



c。然后我们选择每个组/ LookUp,并将其转换为DataRows列表



d。最后,我们将这个IEnumerable的DataRows列表转换为List。



在DataTable上执行此操作的结果如下所示:

 UserID :1 
日期:2/6/2016 8:12:00 AM
日期:2/6/2016 3:43:00 PM
日期:2016/2/6 3:45 :00 PM
用户ID:2
日期:2/6/2016 8:20:00 AM
日期:2016/2/6 3:43:00 PM
用户ID: 3
日期:2/6/2016 8:30:00 AM

如果您仔细研究此代码,您可以看到如何访问UserId组织的行中的任何字段;然后,您可以获得每组中的最小和最大日期,并计算经过的时间等。


i want to show daily attendance::: 

Iam Create table name tblattendance

Create 3 coulmns: 
OrgId
UserId
DateOfTransaction

inserted data :
orgid  useid   DateOfTransaction
1       1        06-02-2016:08:12
1       2        06-02-2016:08:20
1       3        06-02-2016:08:30
1       1        06-02-2016:15:43
1       1        06-02-2016:15:45
1       2        06-02-2016:15:43
 
evng time only 1 and 3 userids only punch but not punch userid 2

i want to show daily attendance output 

Userid   Date         Login Time   Logout Time	  Total Hours	    Total Logs
1        06-02-2016   08:12        15:45           7 hours 12 mins   3
2        06-02-2016   08:20        15:43           7 hours 10 mins   2
3        06-02-2016   08:30          -                 -             1
2        



What I have tried:

i know only show
Select * from tblattendance where tblattendance=06-02-2016
this code to only show
orgid useid DateOfTransaction
1 1 06-02-2016:08:12
1 2 06-02-2016:08:20
.........

i want to show ogin Time, Logout Time, Total Hours, Total logs

解决方案

I'm going to help you get started by showing you how to use Linq to create a collection of DataRows organized by UserID:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;

// in some Method in some Class in some NameSpace
var userIDGroups = dt.Rows.Cast<datarow>()
    .GroupBy(row => row[1])
    .Select(grp => grp.ToList()).ToList();

foreach (var grp in userIDGroups)
{
    Console.WriteLine("UserID: {0}", grp[0].ItemArray[1]);

    foreach (var row in grp)
    {
        Console.WriteLine("Date: {0}", row.ItemArray[2]);
    }
}

This code:

a. converts the DataRowCollecton to an IEnumerable so we can use Linq on it.

b. then it uses 'GroupBy to get a set of 'Groups (IEnumerables of Rows ... a 'LookUp object, actually), selected by the 'UserID field ... field #2 in the Row

c. then we select each group/LookUp, and turn it into a List of DataRows

d. finally, we turn this IEnumerable of Lists of DataRows into a List.

The result of executing this on your DataTable will look like this:

UserID: 1
Date: 2/6/2016 8:12:00 AM
Date: 2/6/2016 3:43:00 PM
Date: 2/6/2016 3:45:00 PM
UserID: 2
Date: 2/6/2016 8:20:00 AM
Date: 2/6/2016 3:43:00 PM
UserID: 3
Date: 2/6/2016 8:30:00 AM

If you study this code carefully you can see how you can access any field in the rows organized by UserId; you can then get the Min and Max Dates in each group and calculate time-elapsed, etc.


这篇关于如何在登录时间,注销时间,总小时数,总日志中创建每日考勤报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆