/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SLoginDiaryData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into SLoginDiary("); strSql.Append("empNo,empId,loginIp,loginDate,isLogined,mark)"); strSql.Append(" values ("); strSql.Append("@empNo,@empId,@loginIp,@loginDate,@isLogined,@mark)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@empNo", SqlDbType.NVarChar,20), new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@loginIp", SqlDbType.NVarChar,50), new SqlParameter("@loginDate", SqlDbType.DateTime), new SqlParameter("@isLogined", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.empNo; parameters[1].Value = model.empId; parameters[2].Value = model.loginIp; parameters[3].Value = model.loginDate == string.Empty ? null : model.loginDate; parameters[4].Value = model.isLogined; parameters[5].Value = model.mark; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SLoginDiaryData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update SLoginDiary set "); strSql.Append("empNo=@empNo,"); strSql.Append("empId=@empId,"); strSql.Append("loginIp=@loginIp,"); strSql.Append("loginDate=@loginDate,"); strSql.Append("isLogined=@isLogined,"); strSql.Append("mark=@mark"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@empNo", SqlDbType.NVarChar,20), new SqlParameter("@empId", SqlDbType.Int), new SqlParameter("@loginIp", SqlDbType.NVarChar,50), new SqlParameter("@loginDate", SqlDbType.DateTime), new SqlParameter("@isLogined", SqlDbType.Bit), new SqlParameter("@mark", SqlDbType.NVarChar,200) }; parameters[0].Value = model.id; parameters[1].Value = model.empNo; parameters[2].Value = model.empId; parameters[3].Value = model.loginIp; parameters[4].Value = model.loginDate == string.Empty ? null : model.loginDate; parameters[5].Value = model.isLogined; parameters[6].Value = model.mark; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// �õ�һ��model /// </summary> /// <param name="id">����ֵ</param> /// <returns>model</returns> public SLoginDiaryData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from SLoginDiary"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; SLoginDiaryData model = new SLoginDiaryData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["empNo"] != DBNull.Value) { model.empNo = Convert.ToString(row["empNo"]); } if (row["empId"] != DBNull.Value) { model.empId = Convert.ToInt32(row["empId"]); } if (row["loginIp"] != DBNull.Value) { model.loginIp = Convert.ToString(row["loginIp"]); } if (row["loginDate"] != DBNull.Value) { model.loginDate = Convert.ToString(row["loginDate"]); } if (row["isLogined"] != DBNull.Value) { model.isLogined = Convert.ToBoolean(row["isLogined"]); } if (row["mark"] != DBNull.Value) { model.mark = Convert.ToString(row["mark"]); } return model; } else { return null; } }
private void LoginDiary() { SLoginDiaryBB loginDiaryBB = new SLoginDiaryBB(); SLoginDiaryData loginDiaryData = new SLoginDiaryData(); try { loginDiaryData.empNo = this.txtUsername.Value.Trim(); if (Session["UserData"] != null) { loginDiaryData.empId = ((HEemployeeData)Session["UserData"]).empId; loginDiaryData.isLogined = true; } //获取客户端IP地址 string uip = ""; if (Request.ServerVariables["HTTP_VIA"] != null) { uip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); } else { uip = Request.ServerVariables["REMOTE_ADDR"].ToString(); } loginDiaryData.loginIp = uip; loginDiaryData.loginDate = DateTime.Now.ToString(); loginDiaryBB.AddRecord(loginDiaryData); } catch { } finally { loginDiaryBB.Dispose(); } }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SLoginDiaryData model) { return this.loginDiaryDB.ModifyRecord(model); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SLoginDiaryData model) { return this.loginDiaryDB.AddRecord(model); }