You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.7 KiB

  1. 
  2. ///-----------------------------------------------------------------------
  3. /// <copyright file="DBService.cs" company="Origtek">
  4. /// 程式代號: DBService
  5. /// 程式名稱: DBService
  6. /// 程式說明:
  7. /// 起始作者: Nelson
  8. /// 起始日期: 2016/09/03 17:03:37
  9. /// 最新修改人: Hercules
  10. /// 最新修日期: 2017/05/15 12:24:49
  11. /// </copyright>
  12. ///-----------------------------------------------------------------------
  13. namespace CounsellorBL.BLStructure
  14. {
  15. using OT.COM.ArsenalDB;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Data;
  19. using System.Globalization;
  20. using CounsellorBL.Helper;
  21. public class QueryResponse
  22. {
  23. /// <summary>
  24. /// 類別成員、類別屬性說明:符合條件總數
  25. /// </summary>
  26. public long TotalCount
  27. {
  28. get; set;
  29. }
  30. /// <summary>
  31. /// 類別成員、類別屬性說明:本次回傳總數
  32. /// </summary>
  33. public long CurrentCount
  34. {
  35. get; set;
  36. }
  37. /// <summary>
  38. /// 類別成員、類別屬性說明:資料陣列
  39. /// </summary>
  40. public List<Dictionary<string, object>> Records
  41. {
  42. get;
  43. } = new List<Dictionary<string, object>>();
  44. /// <summary>
  45. /// 函式名稱:queryResponse
  46. /// 函式說明:建構式
  47. /// 起始作者:
  48. /// 起始日期:
  49. /// 最新修改人:
  50. /// 最新修改日:
  51. /// </summary>
  52. /// <param name="i_qdsOringinResult">查詢結果</param>
  53. /// <returns>
  54. /// 回傳
  55. /// </returns>
  56. /// <summary>
  57. public QueryResponse(QueryDataSet i_qdsOringinResult, Dictionary<string, object> i_dicAdditionDataForEveryRow = null)
  58. {
  59. setup(i_qdsOringinResult, i_dicAdditionDataForEveryRow);
  60. }
  61. /// <summary>
  62. /// 函式名稱:
  63. /// 函式說明:建構式
  64. /// 起始作者:
  65. /// 起始日期:
  66. /// 最新修改人:
  67. /// 最新修改日:
  68. /// </summary>
  69. /// <param name="參數名稱">
  70. /// 參數說明
  71. /// </param>
  72. /// <returns>
  73. /// 回傳
  74. /// </returns>
  75. /// <summary>
  76. public QueryResponse()
  77. {
  78. }
  79. protected void setup(QueryDataSet i_qdsOringinResult, Dictionary<string, object> i_dicAdditionDataForEveryRow = null)
  80. {
  81. if (i_qdsOringinResult != null && i_qdsOringinResult.DATA != null && i_qdsOringinResult.DATA.Tables.Count > 0)
  82. {
  83. DataTable dt = i_qdsOringinResult.DATA.Tables[0];
  84. DataColumnCollection dcc = dt.Columns;
  85. int nSNCount = 1;
  86. this.TotalCount = i_qdsOringinResult.Total;
  87. this.CurrentCount = dt.Rows.Count;
  88. foreach (DataRow dr in dt.Rows)
  89. {
  90. Dictionary<string, object> dicData = new Dictionary<string, object>
  91. {
  92. { "sn", nSNCount }
  93. };
  94. if (i_dicAdditionDataForEveryRow != null)
  95. {
  96. foreach (KeyValuePair<string, object> kvp in i_dicAdditionDataForEveryRow)
  97. {
  98. dicData.Add(kvp.Key, kvp.Value);
  99. }
  100. }
  101. foreach (DataColumn dc in dcc)
  102. {
  103. object oData = dr[dc.ColumnName];
  104. string sColumnName = dc.ColumnName.ToLower(CultureInfo.CurrentCulture);
  105. if (oData is string)
  106. {
  107. string sData = oData.ToString();
  108. dicData.Add(sColumnName, sData.TrimEnd());
  109. }
  110. else if (oData is DateTime)
  111. {
  112. dicData.Add(sColumnName, ((DateTime)(oData)).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture));
  113. }
  114. else if (TypeCheckerHelper.IsNumeric(oData))
  115. {
  116. dicData.Add(sColumnName, oData);
  117. }
  118. else
  119. {
  120. if (!(oData is DBNull))
  121. {
  122. dicData.Add(sColumnName, oData.ToString());
  123. }
  124. }
  125. }
  126. this.Records.Add(dicData);
  127. nSNCount++;
  128. }
  129. }
  130. }
  131. }
  132. }