/// <summary> /// 增加一条数据 /// </summary> public int Add(lgk.Model.tb_userLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_userLog("); strSql.Append("UserName,LogTime,LogContent,LogIP)"); strSql.Append(" values ("); strSql.Append("@UserName,@LogTime,@LogContent,@LogIP)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@LogTime", SqlDbType.DateTime), new SqlParameter("@LogContent", SqlDbType.VarChar, 500), new SqlParameter("@LogIP", SqlDbType.VarChar, 50) }; parameters[0].Value = model.UserName; parameters[1].Value = model.LogTime; parameters[2].Value = model.LogContent; parameters[3].Value = model.LogIP; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(lgk.Model.tb_userLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_userLog set "); strSql.Append("UserName=@UserName,"); strSql.Append("LogTime=@LogTime,"); strSql.Append("LogContent=@LogContent,"); strSql.Append("LogIP=@LogIP"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar, 50), new SqlParameter("@LogTime", SqlDbType.DateTime), new SqlParameter("@LogContent", SqlDbType.VarChar, 500), new SqlParameter("@LogIP", SqlDbType.VarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.UserName; parameters[1].Value = model.LogTime; parameters[2].Value = model.LogContent; parameters[3].Value = model.LogIP; parameters[4].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public lgk.Model.tb_userLog GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,UserName,LogTime,LogContent,LogIP from tb_userLog "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; lgk.Model.tb_userLog model = new lgk.Model.tb_userLog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "") { model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString(); } if (ds.Tables[0].Rows[0]["LogTime"] != null && ds.Tables[0].Rows[0]["LogTime"].ToString() != "") { model.LogTime = DateTime.Parse(ds.Tables[0].Rows[0]["LogTime"].ToString()); } if (ds.Tables[0].Rows[0]["LogContent"] != null && ds.Tables[0].Rows[0]["LogContent"].ToString() != "") { model.LogContent = ds.Tables[0].Rows[0]["LogContent"].ToString(); } if (ds.Tables[0].Rows[0]["LogIP"] != null && ds.Tables[0].Rows[0]["LogIP"].ToString() != "") { model.LogIP = ds.Tables[0].Rows[0]["LogIP"].ToString(); } return(model); } else { return(null); } }