/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.branch model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update td_branch set "); strSql.Append(" user_id = @user_id , "); strSql.Append(" title = @title , "); strSql.Append(" add_time = @add_time "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.id; parameters[1].Value = model.user_id; parameters[2].Value = model.title; parameters[3].Value = model.add_time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.branch model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into td_branch("); strSql.Append("user_id,title,add_time"); strSql.Append(") values ("); strSql.Append("@user_id,@title,@add_time"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 50), new SqlParameter("@add_time", SqlDbType.DateTime) }; parameters[0].Value = model.user_id; parameters[1].Value = model.title; parameters[2].Value = model.add_time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.branch GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, title, add_time "); strSql.Append(" from td_branch "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.branch model = new Model.branch(); 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()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].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 Model.branch GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, title, add_time "); strSql.Append(" from td_branch "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.branch model = new Model.branch(); 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()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } model.title = ds.Tables[0].Rows[0]["title"].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; } }
private void add_branch(HttpContext context) { string title = DTRequest.GetFormString("title"); Model.users model = new BasePage().GetUserInfo(); if (model == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"对不起,请重新登录!\"}"); return; } BLL.branch bll = new BLL.branch(); Model.branch branch_model = new Model.branch(); branch_model.user_id = model.id; branch_model.add_time = DateTime.Now; branch_model.title = title; if (bll.Add(branch_model) > 0) { context.Response.Write("{\"status\":\"1\", \"msg\":\"新增部门成功!\"}"); return; } else { context.Response.Write("{\"status\":\"0\", \"msg\":\"新增部门失败!\"}"); return; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.branch model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.branch model) { return(dal.Add(model)); }