1.項目操作流程
2.2.描述項目操作流程動圖功能和步驟夸赫;
第一步:調(diào)試該程序然后彈出登錄界面菩帝;
第二步:輸入管理員賬號和密碼點擊登錄;
第三步:登錄成功后出現(xiàn)管理員登陸界面憔足;
第四步:點擊“統(tǒng)計部門考勤”出現(xiàn)統(tǒng)計部門考勤界面胁附;
3.管理員登陸統(tǒng)計部門考勤界面
點擊統(tǒng)計部門考勤后選擇所要統(tǒng)計的考勤時間后酒繁,點擊查詢會出現(xiàn)如下圖所示的信息
4.相關(guān)代碼
private void bt_Query_Click(object sender, EventArgs e)
{
String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
try
{
// 連接數(shù)據(jù)庫
sqlConn.Open();
// DataGridView數(shù)據(jù)綁定
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";//統(tǒng)計部門和遲到早退的人數(shù)
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)來標識數(shù)據(jù)庫的GOODS表
adp.Fill(ds, "Attendance");
// 指定DataGridView的數(shù)據(jù)源為DataSet的MyGoods表
this.dgv_Attendance.DataSource = ds.Tables["Attendance"];
}
catch (Exception exp)
{
MessageBox.Show("訪問數(shù)據(jù)庫錯誤:" + exp.Message);
}
finally
{
sqlConn.Close();
}
}