/// <summary>更新一条数据 /// /// </summary> public bool Update(Nikita.Assist.Logger.Model.LocalLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update LocalLog set "); strSql.Append("Date=@Date, Level=@Level, Logger=@Logger, Message=@Message "); strSql.Append(" where id=@id "); IDbHelper h = DbHelper.GetDbHelper(SqlType.SQLite, GlobalHelp.Connection); h.CreateCommand(strSql.ToString()); if (model.Date == null) { h.AddParameter("@Date", DBNull.Value); } else { h.AddParameter("@Date", model.Date.ToString("s")); } if (model.Level == null) { h.AddParameter("@Level", DBNull.Value); } else { h.AddParameter("@Level", model.Level); } if (model.Logger == null) { h.AddParameter("@Logger", DBNull.Value); } else { h.AddParameter("@Logger", model.Logger); } if (model.Message == null) { h.AddParameter("@Message", DBNull.Value); } else { h.AddParameter("@Message", model.Message); } h.AddParameter("@id", model.id); return(h.ExecuteNonQuery()); }
/// <summary>对象实体绑定数据 /// /// </summary> public Nikita.Assist.Logger.Model.LocalLog ReaderBind(IDataReader dataReader) { Nikita.Assist.Logger.Model.LocalLog model = new Nikita.Assist.Logger.Model.LocalLog(); object ojb; ojb = dataReader["id"]; if (ojb != null && ojb != DBNull.Value) { model.id = int.Parse(ojb.ToString()); } ojb = dataReader["Date"]; if (ojb != null && ojb != DBNull.Value) { model.Date = DateTime.Parse(ojb.ToString()); } model.Level = dataReader["Level"].ToString(); model.Logger = dataReader["Logger"].ToString(); model.Message = dataReader["Message"].ToString(); return(model); }
/// <summary>得到一个对象实体 /// /// </summary> public Nikita.Assist.Logger.Model.LocalLog GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from LocalLog "); strSql.Append(" where id=@id "); IDbHelper h = DbHelper.GetDbHelper(SqlType.SQLite, GlobalHelp.Connection); h.CreateCommand(strSql.ToString()); h.AddParameter("@id", id); Nikita.Assist.Logger.Model.LocalLog model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>根据条件得到一个对象实体 /// /// </summary> public Nikita.Assist.Logger.Model.LocalLog GetModelByCond(string cond) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from LocalLog "); if (!string.IsNullOrEmpty(cond)) { strSql.Append(" where " + cond); } strSql.Append(" limit 1"); IDbHelper h = DbHelper.GetDbHelper(SqlType.SQLite, GlobalHelp.Connection); h.CreateCommand(strSql.ToString()); Nikita.Assist.Logger.Model.LocalLog model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>增加一条数据 /// /// </summary> public int Add(Exception objectEx, string Logger) { Nikita.Assist.Logger.Model.LocalLog model = new Nikita.Assist.Logger.Model.LocalLog(); model.Date = DateTime.Now; model.Logger = Logger; model.Message = objectEx.ToString(); model.Level = "1"; StringBuilder strSql = new StringBuilder(); strSql.Append("insert into LocalLog("); strSql.Append("Date, Level, Logger, Message )"); strSql.Append(" values ("); strSql.Append("@Date, @Level, @Logger, @Message )"); IDbHelper h = DbHelper.GetDbHelper(SqlType.SQLite, GlobalHelp.Connection); h.CreateCommand(strSql.ToString()); if (model.Date == null) { h.AddParameter("@Date", DBNull.Value); } else { h.AddParameter("@Date", model.Date.ToString("s")); } if (model.Level == null) { h.AddParameter("@Level", DBNull.Value); } else { h.AddParameter("@Level", model.Level); } if (model.Logger == null) { h.AddParameter("@Logger", DBNull.Value); } else { h.AddParameter("@Logger", model.Logger); } if (model.Message == null) { h.AddParameter("@Message", DBNull.Value); } else { h.AddParameter("@Message", model.Message); } h.ExecuteNonQuery(); string sql2 = "select max(id) from LocalLog"; h.CreateCommand(sql2); int result; string obj = h.ExecuteScalar(); if (!int.TryParse(obj, out result)) { return(0); } return(result); }