一个用于C#开发 sql server 作为数据的考勤系统 可以通过码枪扫描条形码或者指纹识别记录考勤信息 #region 输入条形码
private void WorkerID_TextChanged(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == Convert.ToChar(13))
{
string empNo;
DataSet DSSelect = new DataSet();
string sel = "select 员工号 from 员工表 where 条形码='" this.WorkerID.Text.Trim() "'";
this.CMD.CommandText = sel;
this.CMD.Connection = this.SC;
this.SDA.SelectCommand = this.CMD;
this.SC.Open();
this.SDA.Fill(DSSelect);
this.SC.Close();
if (DSSelect.Tables[0].Rows.Count > 0)
{
empNo = DSSelect.Tables[0].Rows[0][0].ToString();
}
else
{
this.WorkerID.Text = "";
return;
}
string CMDStr = "select 上班时间,下班时间, 出勤表.员工号 from 出勤表 left join 员工表 on 员工表.员工号 = 出勤表.员工号 where 员工表.条形码=" "'" this.WorkerID.Text.ToString().Trim() "'" " order by 上班时间 desc";
DSSelect.Clear();
this.CMD.CommandText = CMDStr;
this.CMD.Connection = this.SC;
this.SDA.SelectCommand = this.CMD;
this.SC.Open();
this.SDA.Fill(DSSelect);
this.SC.Close();
if (DSSelect.Tables[0].Rows.Count > 0&&DSSelect.Tables[0].Rows[0]["下班时间"].ToString() == "")
{
string stj1 = DSSelect.Tables[0].Rows[0]["上班时间"].ToString();
DateTime Check = Convert.ToDateTime(stj1);
/*int CheckHour = (Convert.ToInt32(DateTime.Now.Hour.ToString()) - Convert.ToInt32(Check.Hour.ToString())) * 3600;
int CheckMinute = (Convert.ToInt32(DateTime.Now.Minute.ToString()) - Convert.ToInt32(Check.Minute.ToString())) * 60;
int CheckSecond = (Convert.ToInt32(DateTime.Now.Second.ToString()) - Convert.ToInt32(Check.Second.ToString()));
int CheckTime = CheckHour CheckMinute CheckSecond;*/
int CheckTime = Convert.ToInt32(DiffDate(Check, DateTime.Now));
if (CheckTime < 3)
{
this.WorkerID.Text = "";
return;
}
else
{
//string stj=DateTime.Compare(DateTime.Now,Convert.ToDateTime(DSSelect.Tables[0].Rows[0][0])).ToString();
/* DateTime GoWorkTime = Convert.ToDateTime(stj1);
int HourDispersion = (Convert.ToInt32(DateTime.Now.Hour.ToString()) - Convert.ToInt32(GoWorkTime.Hour.ToString())) * 60;
int MinuteDispersion = (Convert.ToInt32(DateTime.Now.Minute.ToString()) - Convert.ToInt32(GoWorkTime.Minute.ToString()));
int TimeDispersion = HourDispersion MinuteDispersion;*/
int TimeDispersion = CheckTime / 60;
if (TimeDispersion > 20)
//if (TimeDispersion > 0)
{
string WorkTime = DateDiff(DateTime.Now, Convert.ToDateTime(DSSelect.Tables[0].Rows[0]["上班时间"])).ToString();
string str = "update 出勤表 set 下班时间=" "'" DateTime.Now.ToString().Trim() "'" ",工作时间='" WorkTime "' where 员工号=" "'" empNo "'" "and 上班时间=" "'" stj1 "'";
this.CMD.Connection = this.SC;
this.CMD.CommandText = str;
this.SC.Open();
if (this.CMD.ExecuteNonQuery() > 0)
{
this.WorkerID.Text = "";
this.SC.Close();
//GetOutWorkTable(sender, e);
GetOutWorkTable();
}
}
else
{
string DelStr = "delete from 出勤表 where 员工号=" "'" empNo "'" "and 上班时间=" "'" stj1 "'";
this.CMD.CommandText = DelStr;
this.CMD.Connection = this.SC;
this.SC.Open();
if (this.CMD.ExecuteNonQuery() > 0)
{
this.SC.Close();
//GetInWorkTable(sender, e);
GetInWorkTable();
//GetOutWorkTable(sender, e);
GetOutWorkTable();
this.WorkerID.Text = "";
}
}
}
}
else
{
string s = DateTime.Now.ToString();
string str = "insert into 出勤表 (员工号,上班时间) values('" empNo "','" DateTime.Now.ToString().Trim() "')";
this.CMD.Connection = this.SC;
this.CMD.CommandText = str;
this.SC.Open();
if (this.CMD.ExecuteNonQuery() > 0)
{
this.WorkerID.Text = "";
this.SC.Close();
//GetInWorkTable(sender, e);
// GetOutWorkTable(sender, e);
GetInWorkTable();
GetOutWorkTable();
}
}
}
}
catch
{
this.WorkerID.Text = "";
return;
}
}
#endregion
评论