/// <summary> /// 更新一条数据 /// </summary> public bool Update(EShop.Model.System_Dictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update System_Dictionary set "); strSql.Append("Code=@Code,"); strSql.Append("Name=@Name,"); strSql.Append("PCode=@PCode"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Code", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@PCode", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.Code; parameters[1].Value = model.Name; parameters[2].Value = model.PCode; parameters[3].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(EShop.Model.System_Dictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into System_Dictionary("); strSql.Append("Code,Name,PCode)"); strSql.Append(" values ("); strSql.Append("@Code,@Name,@PCode)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Code", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.VarChar, 50), new SqlParameter("@PCode", SqlDbType.VarChar, 50) }; parameters[0].Value = model.Code; parameters[1].Value = model.Name; parameters[2].Value = model.PCode; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public EShop.Model.System_Dictionary DataRowToModel(DataRow row) { EShop.Model.System_Dictionary model = new EShop.Model.System_Dictionary(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Code"] != null) { model.Code = row["Code"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["PCode"] != null) { model.PCode = row["PCode"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public EShop.Model.System_Dictionary GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Code,Name,PCode from System_Dictionary "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; EShop.Model.System_Dictionary model = new EShop.Model.System_Dictionary(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }