/// <summary> /// 增加一条数据 /// </summary> public bool Add(EnumInfoModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into enuminfo("); strSql.Append("SlnID,enumName,enumDescription,enumValueInfo)"); strSql.Append(" values ("); strSql.Append("@SlnID,@enumName,@enumDescription,@enumValueInfo)"); SqlParameter[] parameters = { new SqlParameter("@SlnID", SqlDbType.Int,4), new SqlParameter("@enumName", SqlDbType.VarChar,50), new SqlParameter("@enumDescription", SqlDbType.VarChar,200), new SqlParameter("@enumValueInfo", SqlDbType.VarChar,2000)}; parameters[0].Value = model.SlnID; parameters[1].Value = model.enumName; parameters[2].Value = model.enumDescription; parameters[3].Value = model.enumValueInfo; int rows = SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
protected void butSubmit_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(EditKey.Text)) { try { EnuminfoBLL con = new EnuminfoBLL(); EnumInfoModel model = new EnumInfoModel(); model.enumName = txtName.Text; model.enumDescription = txtDescription.Text; model.enumValueInfo = txtValueInfo.Text; model.SlnID = SlnID; if (con.Add(model)) { Bind(); btCancelButton_Click(null, null); return; } } catch (Exception ex) { Page.RegisterStartupScript("", "<script language=javascript>alert('添加失败!')</script>"); } } else { try { EnuminfoBLL con = new EnuminfoBLL(); EnumInfoModel model = new EnumInfoModel(); model.enumName = txtName.Text; model.enumDescription = txtDescription.Text; model.enumValueInfo = txtValueInfo.Text; model.SlnID = SlnID; model.ID = int.Parse(EditKey.Text); if (con.Update(model)) { Bind(); btCancelButton_Click(null, null); return; } } catch (Exception ex) { Page.RegisterStartupScript("", "<script language=javascript>alert('编辑失败!')</script>"); } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Add(model.EnumInfoModel model) { return(dal.Add(model)); }
/// <summary> /// 更新一条数据 /// </summary>enumName,enumDescription,enumValueInfo public bool Update(EnumInfoModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update enuminfo set "); strSql.Append("enumName=@enumName,"); strSql.Append("enumDescription=@enumDescription,"); strSql.Append("enumValueInfo=@enumValueInfo"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@enumName", SqlDbType.VarChar,50), new SqlParameter("@enumDescription", SqlDbType.VarChar,500), new SqlParameter("@enumValueInfo", SqlDbType.VarChar,2000), new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = model.enumName; parameters[1].Value = model.enumDescription; parameters[2].Value = model.enumValueInfo; parameters[3].Value = model.ID; int rows = SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 得到一个对象实体 /// </summary> public EnumInfoModel GetModel(string enumName, string slnid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id, slnid, enumName,enumDescription,enumValueInfo from enuminfo"); strSql.Append(" where enumName=@enumName and slnid=@slnid"); SqlParameter[] parameters = { new SqlParameter("@enumName", SqlDbType.VarChar,500), new SqlParameter("@slnid", SqlDbType.Int,4)}; parameters[0].Value = enumName; parameters[1].Value = slnid; SqlDataReader dr = SqlHelper.ExecuteReader(connectionString, CommandType.Text, strSql.ToString(), parameters); if (dr.Read()) { EnumInfoModel model = new EnumInfoModel(); model.enumDescription = dr["enumDescription"].ToString(); model.enumName = enumName; model.enumValueInfo = dr["enumValueInfo"].ToString(); model.ID = int.Parse(dr["id"].ToString()); return model; } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public EnumInfoModel GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 enumName,enumDescription,enumValueInfo from enuminfo"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4),}; parameters[0].Value = ID; SqlDataReader dr = SqlHelper.ExecuteReader(connectionString, CommandType.Text, strSql.ToString(), parameters); if (dr.Read()) { EnumInfoModel model = new EnumInfoModel(); model.enumDescription = dr["enumDescription"].ToString(); model.enumName = dr["enumName"].ToString(); model.enumValueInfo = dr["enumValueInfo"].ToString(); return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(EnumInfoModel model) { return dal.Update(model); }