UnityBll.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. namespace DllUnityBll
  8. {
  9. public class UnityBll
  10. {
  11. /// <summary>
  12. /// 根据条件查询返回实体集合
  13. /// </summary>
  14. /// <typeparam name="T"></typeparam>
  15. /// <param name="dbcode"></param>
  16. /// <param name="condition"></param>
  17. /// <param name="entity">实体变量</param>
  18. /// <param name="erroinfo"></param>
  19. /// <returns></returns>
  20. public IEnumerable<T> SelectForEntity<T>(string dbcode, string condition, object entity, ref string erroinfo) where T : class,new()
  21. {
  22. IDatabase db = null;
  23. try
  24. {
  25. db = DbFactory.Base(dbcode);
  26. string sqlstr = EntityHelper.GetSelectSql(entity,condition, ref erroinfo);
  27. IEnumerable<T> redt = db.FindList<T>(sqlstr);
  28. return redt;
  29. }
  30. catch (Exception ex)
  31. {
  32. erroinfo = ex.Message.ToString();
  33. return null;
  34. }
  35. finally
  36. {
  37. if (db != null)
  38. db.Close();
  39. }
  40. }
  41. /// <summary>
  42. /// 老的查询实体方法
  43. /// </summary>
  44. /// <typeparam name="T"></typeparam>
  45. /// <param name="dbcode"></param>
  46. /// <param name="sqlstr"></param>
  47. /// <param name="tablename"></param>
  48. /// <param name="erroinfo"></param>
  49. /// <returns></returns>
  50. public IEnumerable<T> SelectForEntity<T>(string dbcode, string sqlstr, string tablename, ref string erroinfo) where T : class
  51. {
  52. IDatabase db = null;
  53. try
  54. {
  55. db = DbFactory.Base(dbcode);
  56. IEnumerable<T> redt = db.FindList<T>(sqlstr);
  57. return redt;
  58. }
  59. catch (Exception ex)
  60. {
  61. erroinfo = ex.Message.ToString();
  62. return null;
  63. }
  64. finally
  65. {
  66. if (db != null)
  67. db.Close();
  68. }
  69. }
  70. public DataSet Select(string sqlstr, string tablename, ref string erroinfo)
  71. {
  72. IDatabase db = null;
  73. try
  74. {
  75. string dbcode = "sqlconn";
  76. db = DbFactory.Base(dbcode);
  77. DataTable redt = db.FindTableFor(sqlstr, tablename);
  78. DataSet tempds = new DataSet();
  79. tempds.Merge(redt);
  80. return tempds;
  81. }
  82. catch (Exception ex)
  83. {
  84. erroinfo = ex.Message.ToString();
  85. return null;
  86. }
  87. finally
  88. {
  89. if (db != null)
  90. db.Close();
  91. }
  92. }
  93. public DataSet Select(string dbcode, string sqlstr, string tablename, ref string erroinfo)
  94. {
  95. IDatabase db = null;
  96. try
  97. {
  98. db = DbFactory.Base(dbcode);
  99. DataTable redt = db.FindTableFor(sqlstr, tablename);
  100. DataSet tempds = new DataSet();
  101. tempds.Merge(redt);
  102. return tempds;
  103. }
  104. catch (Exception ex)
  105. {
  106. erroinfo = ex.Message.ToString();
  107. return null;
  108. }
  109. finally
  110. {
  111. if (db != null)
  112. db.Close();
  113. }
  114. }
  115. }
  116. }