/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.tag model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update td_tag set "); strSql.Append(" title = @title , "); strSql.Append(" category_id = @category_id , "); strSql.Append(" add_time = @add_time "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@category_id", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.title; parameters[2].Value = model.category_id; parameters[3].Value = model.add_time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int _id) { BLL.tag bll = new BLL.tag(); Model.tag model = bll.GetModel(_id); ddlCategoryId.SelectedValue = model.category_id.ToString(); txt_title.Text = model.title; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.tag model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into td_tag("); strSql.Append("title,category_id,add_time"); strSql.Append(") values ("); strSql.Append("@title,@category_id,@add_time"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@category_id", SqlDbType.Int, 4), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.title; parameters[1].Value = model.category_id; parameters[2].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private bool DoEdit(int _id) { bool result = false; BLL.tag bll = new BLL.tag(); Model.tag model = bll.GetModel(_id); model.title = txt_title.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); if (bll.Update(model)) { //AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改用户信息:" + model.user_name); //记录日志 result = true; } return(result); }
private bool DoAdd() { bool result = false; BLL.tag bll = new BLL.tag(); Model.tag model = new Model.tag(); model.title = txt_title.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.add_time = DateTime.Now; if (bll.Add(model) > 0) { //AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加用户:" + model.user_name); //记录日志 result = true; } return result; }
private bool DoAdd() { bool result = false; BLL.tag bll = new BLL.tag(); Model.tag model = new Model.tag(); model.title = txt_title.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.add_time = DateTime.Now; if (bll.Add(model) > 0) { //AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加用户:" + model.user_name); //记录日志 result = true; } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.tag GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, title, category_id, add_time "); strSql.Append(" from td_tag "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.tag model = new Model.tag(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].ToString(); if (ds.Tables[0].Rows[0]["category_id"].ToString() != "") { model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.tag model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.tag model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.tag GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select id, title, category_id, add_time "); strSql.Append(" from td_tag "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.tag model=new Model.tag(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["id"].ToString()!="") { model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.title= ds.Tables[0].Rows[0]["title"].ToString(); if(ds.Tables[0].Rows[0]["category_id"].ToString()!="") { model.category_id=int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString()); } if(ds.Tables[0].Rows[0]["add_time"].ToString()!="") { model.add_time=DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } return model; } else { return null; } }