/// <summary> /// 更新一条数据 /// </summary> public bool Update(oyxf.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Category set "); strSql.Append("Name=@Name,"); strSql.Append("Type=@Type,"); strSql.Append("ParentId=@ParentId,"); strSql.Append("Status=@Status,"); strSql.Append("SortIndex=@SortIndex,"); strSql.Append("Url=@Url,"); strSql.Append("Content=@Content,"); strSql.Append("IdPath=@IdPath,"); strSql.Append("Depth=@Depth,"); strSql.Append("HasChildren=@HasChildren"); strSql.Append(" where CategoryId=@CategoryId"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 20), new SqlParameter("@Type", SqlDbType.TinyInt, 1), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.TinyInt, 1), new SqlParameter("@SortIndex", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.VarChar, 100), new SqlParameter("@Content", SqlDbType.NVarChar, 2000), new SqlParameter("@IdPath", SqlDbType.VarChar, 100), new SqlParameter("@Depth", SqlDbType.Int, 4), new SqlParameter("@HasChildren", SqlDbType.TinyInt, 1), new SqlParameter("@CategoryId", SqlDbType.Int, 4) }; parameters[0].Value = model.Name; parameters[1].Value = model.Type; parameters[2].Value = model.ParentId; parameters[3].Value = model.Status; parameters[4].Value = model.SortIndex; parameters[5].Value = model.Url; parameters[6].Value = model.Content; parameters[7].Value = model.IdPath; parameters[8].Value = model.Depth; parameters[9].Value = model.HasChildren; parameters[10].Value = model.CategoryId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public oyxf.Model.Category DataRowToModel(DataRow row) { oyxf.Model.Category model = new oyxf.Model.Category(); if (row != null) { if (row["CategoryId"] != null && row["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(row["CategoryId"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Type"] != null && row["Type"].ToString() != "") { model.Type = int.Parse(row["Type"].ToString()); } if (row["ParentId"] != null && row["ParentId"].ToString() != "") { model.ParentId = int.Parse(row["ParentId"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } if (row["SortIndex"] != null && row["SortIndex"].ToString() != "") { model.SortIndex = int.Parse(row["SortIndex"].ToString()); } if (row["Url"] != null) { model.Url = row["Url"].ToString(); } if (row["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["IdPath"] != null) { model.IdPath = row["IdPath"].ToString(); } if (row["Depth"] != null && row["Depth"].ToString() != "") { model.Depth = int.Parse(row["Depth"].ToString()); } if (row["HasChildren"] != null && row["HasChildren"].ToString() != "") { model.HasChildren = int.Parse(row["HasChildren"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(oyxf.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Category("); strSql.Append("Name,Type,ParentId,Status,SortIndex,Url,Content,IdPath,Depth,HasChildren)"); strSql.Append(" values ("); strSql.Append("@Name,@Type,@ParentId,@Status,@SortIndex,@Url,@Content,@IdPath,@Depth,@HasChildren)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 20), new SqlParameter("@Type", SqlDbType.TinyInt, 1), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@Status", SqlDbType.TinyInt, 1), new SqlParameter("@SortIndex", SqlDbType.Int, 4), new SqlParameter("@Url", SqlDbType.VarChar, 100), new SqlParameter("@Content", SqlDbType.NVarChar, 2000), new SqlParameter("@IdPath", SqlDbType.VarChar, 100), new SqlParameter("@Depth", SqlDbType.Int, 4), new SqlParameter("@HasChildren", SqlDbType.TinyInt, 1) }; parameters[0].Value = model.Name; parameters[1].Value = model.Type; parameters[2].Value = model.ParentId; parameters[3].Value = model.Status; parameters[4].Value = model.SortIndex; parameters[5].Value = model.Url; parameters[6].Value = model.Content; parameters[7].Value = model.IdPath; parameters[8].Value = model.Depth; parameters[9].Value = model.HasChildren; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public oyxf.Model.Category GetModel(int CategoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CategoryId,Name,Type,ParentId,Status,SortIndex,Url,Content,IdPath,Depth,HasChildren from Category "); strSql.Append(" where CategoryId=@CategoryId"); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.Int, 4) }; parameters[0].Value = CategoryId; oyxf.Model.Category model = new oyxf.Model.Category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }