考勤系统功能实现——统计

1.描述项目操作流程动图功能和步骤 【考勤系统功能实现——统计】第一步:调试该程序然后弹出登录界面;
第二步:输入管理员账号和密码点击登录;
第三步:登录成功后出现管理员登陆界面;
第四步:点击“统计部门考勤”出现统计部门考勤界面;
2.管理员登陆、统计部门考勤界面 考勤系统功能实现——统计
文章图片
统计.PNG 3.相关代码

private void bt_Query_Click(object sender, EventArgs e) { String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString; SqlConnection sqlConn = new SqlConnection(connStr); try { // 连接数据库 sqlConn.Open(); // DataGridView数据绑定 String sqlStr = @"select t4.department, count(*) as count from ( select t3.*, t.name, t.department from ( // 查询表中职员打卡时间的id和时间显示出来 select t1.employee_id, t1.date, datediff(n,t1.time,t2.time) as diff from record t1 inner join record t2 on t1.date = t2.date and t1.employee_id=t2.employee_id and t1.machine_id =1 and t2.machine_id =2 and t1.date>=@start and t1.date<=@end ) t3,employee t where t3.employee_id=t.id ) t4 where t4.diff<540 group by t4.department"; //统计部门和迟到早退的人数SqlCommand cmd = new SqlCommand(sqlStr, sqlConn); cmd.Parameters.Add(new SqlParameter("@start", this.start.Value.ToShortDateString())); cmd.Parameters.Add(new SqlParameter("@end", this.end.Value.ToShortDateString())); // 添加查询条件 // 将该查询过程绑定到DataAdapter SqlDataAdapter adp = new SqlDataAdapter(); adp.SelectCommand = cmd; // 将DataSet和DataAdapter绑定 DataSet ds = new DataSet(); // 自定义一个表(MyGoods)来标识数据库的GOODS表 adp.Fill(ds, "Attendance"); // 指定DataGridView的数据源为DataSet的MyGoods表 this.dgv_Attendance.DataSource = ds.Tables["Attendance"]; } catch (Exception exp) { MessageBox.Show("访问数据库错误:" + exp.Message); } finally { sqlConn.Close(); } }

    推荐阅读