/// <summary> /// 更新一条数据 /// </summary> public bool UpdateEmployeeLogin(EmployeeLoginEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("update T_EmployeeLogin set "); strSql.Append("Flag=@Flag,"); strSql.Append("CurrentTime=@CurrentTime"); strSql.Append(" where LoginId=@LoginId"); SqlParameter[] parameters = { new SqlParameter("@Flag", SqlDbType.Bit, 1), new SqlParameter("@CurrentTime", SqlDbType.SmallDateTime), new SqlParameter("@LoginId", SqlDbType.Int, 4) }; parameters[0].Value = model.Flag; parameters[1].Value = model.CurrentTime; parameters[2].Value = model.LoginId; int rows = SqlHelper.ExecuteSql(SqlHelper.LocalSqlServer, strSql.ToString( ), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int AddEmployeeLogin(EmployeeLoginEntity model) { StringBuilder strSql = new StringBuilder( ); strSql.Append("insert into T_EmployeeLogin("); strSql.Append("EmployeeId,IpAddress,MacAddress,LoginTime,Flag)"); strSql.Append(" values ("); strSql.Append("@EmployeeId,@IpAddress,@MacAddress,@LoginTime,@Flag)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EmployeeId", SqlDbType.VarChar, 50), new SqlParameter("@IpAddress", SqlDbType.VarChar, 50), new SqlParameter("@MacAddress", SqlDbType.VarChar, 50), new SqlParameter("@LoginTime", SqlDbType.SmallDateTime), new SqlParameter("@Flag", SqlDbType.Bit, 1) }; parameters[0].Value = model.EmployeeId; parameters[1].Value = model.IpAddress; parameters[2].Value = model.MacAddress; parameters[3].Value = model.LoginTime; parameters[4].Value = model.Flag; object obj = SqlHelper.GetSingle(SqlHelper.LocalSqlServer, strSql.ToString( ), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 由一行数据得到一个实体 /// </summary> private EmployeeLoginEntity GetModel(DataRow r) { EmployeeLoginEntity model = new EmployeeLoginEntity(); model.LoginId = SqlHelper.GetInt(r["LoginId"]); model.EmployeeId = SqlHelper.GetString(r["EmployeeId"]); model.IpAddress = SqlHelper.GetString(r["IpAddress"]); model.MacAddress = SqlHelper.GetString(r["MacAddress"]); model.LoginTime = SqlHelper.GetDateTime(r["LoginTime"]); model.Flag = SqlHelper.GetBool(r["Flag"]); model.CurrentTime = SqlHelper.GetDateTime(r["CurrentTime"]); model.LogoutTime = SqlHelper.GetDateTime(r["LogoutTime"]); return(model); }
/// <summary> /// 用户登出 /// </summary> public bool EmployeeLogout(EmployeeLoginEntity model) { return(dal.EmployeeLogout(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool UpdateEmployeeLogin(EmployeeLoginEntity model) { return(dal.UpdateEmployeeLogin(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int AddEmployeeLogin(EmployeeLoginEntity model) { return(dal.AddEmployeeLogin(model)); }
private void btnLogin_Click(object sender, EventArgs e) { try { CommonBLL.SetLocalSystemDateTime( ); bool flag = false; string strUser = txtUserNo.Text.Trim( ); string strPassword = txtPassword.Text.Trim( ); if (strUser.Length == 0) { MessageBox.Show("工号不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question); this.txtUserNo.Focus( ); return; } if (strPassword.Length == 0) { MessageBox.Show("密码不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question); this.txtPassword.Focus( ); return; } flag = bll.EmployeeExists(strUser); if (!flag) { MessageBox.Show("工号输入错误!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question); txtUserNo.Select(0, txtUserNo.Text.Trim( ).Length); this.txtUserNo.Focus( ); return; } flag = bll.ValidateEmployee(strUser, strPassword); if (!flag) { MessageBox.Show("密码输入错误!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question); txtPassword.Select(0, txtPassword.Text.Trim( ).Length); this.txtPassword.Focus( ); return; } DataSet dsEmployeeInfo = elBLL.GetDsEmployeeInfo(strUser); if (dsEmployeeInfo.Tables[0].Rows.Count > 0) { UserId = dsEmployeeInfo.Tables[0].Rows[0]["EmployeeId"].ToString( ); } elBLL.DeleteEmployeeLogin(UserId, StrIP); //将非法退出的记录进行删除 DataTable dt = elBLL.GetEmployeeLoginByEmployeeId(UserId).Tables[0]; DateTime curDT = DateTime.Parse(CommonBLL.GetDate("yyyy-MM-dd HH:mm:ss")); bool flag1 = false; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { if (bool.Parse(row["Flag"].ToString( ))) { DateTime tempdt = DateTime.Parse(row["CurrentTime"].ToString( )); if (curDT > tempdt) { TimeSpan ts = curDT - tempdt; //ts.TotalSeconds //DateTime diffDT = curDT.Subtract(tempdt); if (ts.TotalSeconds >= 0 && ts.TotalSeconds <= 60) { flag1 = true; } } else { flag1 = true; } } else { DateTime tempdt = DateTime.Parse(row["LoginTime"].ToString( )); if (curDT > tempdt) { TimeSpan ts = curDT - tempdt; //ts.TotalSeconds //DateTime diffDT = curDT.Subtract(tempdt); if (ts.TotalSeconds >= 0 && ts.TotalSeconds <= 60) { flag1 = true; } } else { flag1 = true; } } } } if (flag1) { MessageBox.Show("该用户正在登陆系统,该系统不允许重复登陆!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Question); this.Dispose( ); Application.Exit( ); return; } else { EmployeeLoginEntity elEntity = new EmployeeLoginEntity( ); StrMAC = "1111111111111111111"; elEntity.EmployeeId = UserId; elEntity.IpAddress = StrIP; elEntity.MacAddress = StrMAC; elEntity.LoginTime = DateTime.Parse(CommonBLL.GetDate("yyyy-MM-dd HH:mm:ss")); elEntity.Flag = false; LoginId = elBLL.AddEmployeeLogin(elEntity); FrmMain main = new FrmMain( ); this.Hide( ); main.Show( ); return; } //FrmMain main = new FrmMain(); //this.Hide(); //main.Show(); } catch (Exception Err) { MessageBox.Show("无法连接服务器,请联系管理员.\n" + Err.Message, "系统提示"); Environment.Exit(0); } }