CategoryService.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using SQLData;
  2. using System.Data;
  3. using System.Text;
  4. namespace BizCom
  5. {
  6. public class CategoryService
  7. {
  8. public static void SaveCategory(string table, string name, int id)
  9. {
  10. StringBuilder sql = new StringBuilder();
  11. if (id > 0) sql.AppendFormat("update {0} set name='{1}' where id={2} ;", table, name, id);
  12. else
  13. {
  14. sql.AppendFormat("insert into {0}(name) values('{1}') ;", table, name);
  15. }
  16. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  17. }
  18. public static void DelCategory(string table, int id)
  19. {
  20. string sql = string.Format("delete from {0} where id={1} ;", table, id);
  21. DbHelper.DbConn.ExecuteNonQuery(sql);
  22. }
  23. public static DataTable GetCategory(string table, string where)
  24. {
  25. string sql = "";
  26. if (where == "") sql = string.Format("select * from {0} ;", table);
  27. else sql = string.Format("select * from {0} where {1} ;", table, where);
  28. return DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  29. }
  30. }
  31. }