/// <summary>对象实体绑定数据 /// /// </summary> public Nikita.Assist.Note.Model.BseUrl ReaderBind(IDataReader dataReader) { Nikita.Assist.Note.Model.BseUrl model = new Nikita.Assist.Note.Model.BseUrl(); object ojb; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = int.Parse(ojb.ToString()); } model.Type = dataReader["Type"].ToString(); model.UrlTitle = dataReader["UrlTitle"].ToString(); model.Url = dataReader["Url"].ToString(); model.UrlContent = dataReader["UrlContent"].ToString(); model.Remark = dataReader["Remark"].ToString(); ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = int.Parse(ojb.ToString()); } ojb = dataReader["CreateDate"]; if (ojb != null && ojb != DBNull.Value) { model.CreateDate = DateTime.Parse(ojb.ToString()); } return(model); }
/// <summary>得到一个对象实体 /// /// </summary> public Nikita.Assist.Note.Model.BseUrl GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from BseUrl "); strSql.Append(" where Id=@Id "); IDbHelper h = GlobalHelp.GetDataAccessHelper(); h.CreateCommand(strSql.ToString()); h.AddParameter("@Id", Id); Nikita.Assist.Note.Model.BseUrl model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>根据条件得到一个对象实体 /// /// </summary> public Nikita.Assist.Note.Model.BseUrl GetModelByCond(string strCond) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from BseUrl "); if (!string.IsNullOrEmpty(strCond)) { strSql.Append(" where " + strCond); } IDbHelper h = GlobalHelp.GetDataAccessHelper(); h.CreateCommand(strSql.ToString()); Nikita.Assist.Note.Model.BseUrl model = null; using (IDataReader dataReader = h.ExecuteReader()) { if (dataReader.Read()) { model = ReaderBind(dataReader); } h.CloseConn(); } return(model); }
/// <summary>增加一条数据 /// /// </summary> public int Add(Nikita.Assist.Note.Model.BseUrl model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BseUrl("); strSql.Append("Type, UrlTitle, Url, UrlContent, Remark, Status, CreateDate )"); strSql.Append(" values ("); strSql.Append("@Type, @UrlTitle, @Url, @UrlContent, @Remark, @Status, @CreateDate )"); strSql.Append(";select @@IDENTITY"); IDbHelper h = GlobalHelp.GetDataAccessHelper(); h.CreateCommand(strSql.ToString()); if (model.Type == null) { h.AddParameter("@Type", DBNull.Value); } else { h.AddParameter("@Type", model.Type); } if (model.UrlTitle == null) { h.AddParameter("@UrlTitle", DBNull.Value); } else { h.AddParameter("@UrlTitle", model.UrlTitle); } if (model.Url == null) { h.AddParameter("@Url", DBNull.Value); } else { h.AddParameter("@Url", model.Url); } if (model.UrlContent == null) { h.AddParameter("@UrlContent", DBNull.Value); } else { h.AddParameter("@UrlContent", model.UrlContent); } if (model.Remark == null) { h.AddParameter("@Remark", DBNull.Value); } else { h.AddParameter("@Remark", model.Remark); } if (model.Status == null) { h.AddParameter("@Status", DBNull.Value); } else { h.AddParameter("@Status", model.Status); } if (model.CreateDate == null) { h.AddParameter("@CreateDate", DBNull.Value); } else { h.AddParameter("@CreateDate", model.CreateDate); } int intResult; string obj = h.ExecuteScalar(); if (!int.TryParse(obj, out intResult)) { return(0); } return(intResult); }
/// <summary>更新一条数据 /// /// </summary> public bool Update(Nikita.Assist.Note.Model.BseUrl model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BseUrl set "); strSql.Append("Type=@Type, UrlTitle=@UrlTitle, Url=@Url, UrlContent=@UrlContent, Remark=@Remark, Status=@Status, CreateDate=@CreateDate "); strSql.Append(" where Id=@Id "); IDbHelper h = GlobalHelp.GetDataAccessHelper(); h.CreateCommand(strSql.ToString()); if (model.Id == null) { h.AddParameter("@Id", DBNull.Value); } else { h.AddParameter("@Id", model.Id); } if (model.Type == null) { h.AddParameter("@Type", DBNull.Value); } else { h.AddParameter("@Type", model.Type); } if (model.UrlTitle == null) { h.AddParameter("@UrlTitle", DBNull.Value); } else { h.AddParameter("@UrlTitle", model.UrlTitle); } if (model.Url == null) { h.AddParameter("@Url", DBNull.Value); } else { h.AddParameter("@Url", model.Url); } if (model.UrlContent == null) { h.AddParameter("@UrlContent", DBNull.Value); } else { h.AddParameter("@UrlContent", model.UrlContent); } if (model.Remark == null) { h.AddParameter("@Remark", DBNull.Value); } else { h.AddParameter("@Remark", model.Remark); } if (model.Status == null) { h.AddParameter("@Status", DBNull.Value); } else { h.AddParameter("@Status", model.Status); } if (model.CreateDate == null) { h.AddParameter("@CreateDate", DBNull.Value); } else { h.AddParameter("@CreateDate", model.CreateDate); } return(h.ExecuteNonQuery()); }