XRayDataDB.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using OTSCOMMONCLR;
  2. using OTSDataType;
  3. using OTSModelSharp.DTLBase;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Runtime.Serialization.Formatters.Binary;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OTSModelSharp
  13. {
  14. public class CXRayDataDB : CSQLiteDB
  15. {
  16. List<CPosXrayClr> m_listPosXray;
  17. const long GENERALXRAYCHANNELS = 2000;
  18. public CXRayDataDB(IDBStoreBase _fileName, IDBTableBase _table) : base(_fileName, _table)
  19. {
  20. m_listPosXray = new List<CPosXrayClr>();
  21. }
  22. public List< CPosXrayClr> GetXrayList( bool a_bForce/* = FALSE*/)
  23. {
  24. if (a_bForce)
  25. {
  26. m_listPosXray.Clear();
  27. }
  28. if (m_listPosXray.Count == 0)
  29. {
  30. ReadAllXrayList();
  31. }
  32. return m_listPosXray;
  33. }
  34. public bool ReadAllXrayList()
  35. {
  36. var t = GetTableInfo();
  37. var query = GetTableQueryForDataTable(t.GetTableName());
  38. ReadXrayListFromAQuery(query,ref m_listPosXray);
  39. return true;
  40. }
  41. public bool ReadXrayListFromAQuery(DataTable a_query,ref List<CPosXrayClr> a_XrayList)
  42. {
  43. Dictionary<List<int>, CPosXrayClr> mapXrayInfo = new Dictionary<List<int>, CPosXrayClr>();
  44. foreach (DataRow row in a_query.Rows)
  45. {
  46. int nCol = (int)CXRayDataTable.ColumnID.N_FIELD_ID - (int)CXRayDataTable.ColumnID.MIN;
  47. int curFldId = Convert.ToInt32(row[nCol]);
  48. nCol = (int)CXRayDataTable.ColumnID.N_INDEX - (int)CXRayDataTable.ColumnID.MIN;
  49. int xrayId = Convert.ToInt32(row[nCol]);
  50. List<int> fldvec = new List<int>();
  51. fldvec.Add(curFldId);
  52. fldvec.Add(xrayId);
  53. nCol = (int)CXRayDataTable.ColumnID.N_XRAY_DATA - (int)CXRayDataTable.ColumnID.MIN;
  54. byte[] xraydata = (byte[])row[nCol];
  55. uint[] uintData = new uint[GENERALXRAYCHANNELS];
  56. for (int j = 0; j < GENERALXRAYCHANNELS; j++)
  57. {
  58. int m = j * 4;
  59. uint d = xraydata[m + 3];
  60. d = d << 8;
  61. d = d | xraydata[m + 2];
  62. d = d << 8;
  63. d = d | xraydata[m + 1];
  64. d = d << 8;
  65. d = d | xraydata[m];
  66. uintData[j] = d;
  67. }
  68. if (!mapXrayInfo.ContainsKey(fldvec))
  69. {
  70. CPosXrayClr xray = new CPosXrayClr();
  71. xray.SetXrayData(uintData);
  72. mapXrayInfo.Add(fldvec, xray);
  73. }
  74. else
  75. {
  76. CPosXrayClr xray = mapXrayInfo[fldvec];
  77. xray.SetXrayData(uintData);
  78. }
  79. }
  80. foreach (var keyvalue in mapXrayInfo)
  81. {
  82. a_XrayList.Add(keyvalue.Value);
  83. }
  84. return true;
  85. }
  86. public bool GetAllMapedXrayData(ref Dictionary<List<int>, CPosXrayClr> mapXrayInfo)
  87. {
  88. var t = GetTableInfo();
  89. var query = GetTableQueryForDataTable(t.GetTableName());
  90. foreach (DataRow row in query.Rows)
  91. {
  92. int nCol = (int)CXRayDataTable.ColumnID.N_FIELD_ID - (int)CXRayDataTable.ColumnID.MIN;
  93. int curFldId = Convert.ToInt32(row[nCol]);
  94. nCol = (int)CXRayDataTable.ColumnID.N_INDEX - (int)CXRayDataTable.ColumnID.MIN;
  95. int xrayId = Convert.ToInt32(row[nCol]);
  96. List<int> fldvec = new List<int>();
  97. fldvec.Add(curFldId);
  98. fldvec.Add(xrayId);
  99. nCol = (int)CXRayDataTable.ColumnID.N_XRAY_DATA - (int)CXRayDataTable.ColumnID.MIN;
  100. byte[] xraydata = (byte[])row[nCol];
  101. uint[] uintData = new uint[GENERALXRAYCHANNELS];
  102. for (int j = 0; j < GENERALXRAYCHANNELS; j++)
  103. {
  104. int m = j * 4;
  105. uint d = xraydata[m + 3];
  106. d = d << 8;
  107. d = d | xraydata[m + 2];
  108. d = d << 8;
  109. d = d | xraydata[m + 1];
  110. d = d << 8;
  111. d = d | xraydata[m];
  112. uintData[j] = d;
  113. }
  114. if (!mapXrayInfo.ContainsKey(fldvec))
  115. {
  116. CPosXrayClr xray = new CPosXrayClr();
  117. xray.SetXrayData(uintData);
  118. mapXrayInfo.Add(fldvec, xray);
  119. }
  120. else
  121. {
  122. CPosXrayClr xray = mapXrayInfo[fldvec];
  123. xray.SetXrayData(uintData);
  124. }
  125. }
  126. return true;
  127. }
  128. }
  129. }