MergeParticleDB.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSModelSharp.DTLBase;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SQLite;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. namespace OTSModelSharp
  14. {
  15. public class CMergeParticleDB : CSQLiteDB
  16. {
  17. public CMergeParticleDB(IDBStoreBase _conStr, IDBTableBase _table) : base(_conStr, _table)
  18. {
  19. }
  20. public bool SaveAParticle( COTSParticleClr a_pParticle, CPosXrayClr a_pXray, System.Drawing.Point fldPos)
  21. {
  22. var tableInfoPtr = GetTableInfo();
  23. var datastorePtr = GetDatastore();
  24. Rectangle prec = (Rectangle)a_pParticle.GetParticleRect();
  25. System.Drawing.Point pos = (System.Drawing.Point)a_pParticle.GetAbsolutPos();
  26. String sInsertFormat = tableInfoPtr.GetInsertCommandFormatString(true);
  27. var cmd = tableInfoPtr.GetInsertCommand(true);
  28. var paras = cmd.Value;
  29. paras[0].Value = a_pParticle.GetFieldId();
  30. paras[1].Value = a_pParticle.GetAnalysisId();
  31. paras[2].Value = a_pParticle.GetAveGray();
  32. paras[3].Value = prec.Left;
  33. paras[4].Value = prec.Top;
  34. paras[5].Value = prec.Width;
  35. paras[6].Value = prec.Height;
  36. paras[7].Value = a_pParticle.GetActualArea();
  37. paras[8].Value = pos.X;
  38. paras[9].Value = pos.Y;
  39. paras[10].Value = a_pParticle.GetType();
  40. paras[11].Value = a_pXray.GetElementQuantifyData().Count;
  41. paras[12].Value = a_pParticle.GetFeature().GetSegmentsList().Count;
  42. paras[13].Value = fldPos.X;
  43. paras[14].Value = fldPos.Y;
  44. paras[15].Value = a_pParticle.GetParticleId();
  45. paras[16].Value = a_pParticle.GetDMAX();
  46. paras[17].Value = a_pParticle.GetDMIN();
  47. paras[18].Value = a_pParticle.GetDMPERP();
  48. paras[19].Value = a_pParticle.GetDPRIMETER();
  49. paras[20].Value = a_pParticle.GetORIENTATION();
  50. paras[21].Value = a_pParticle.GetDINSCR();
  51. paras[22].Value = a_pParticle.GetDMEAN();
  52. paras[23].Value = a_pParticle.GetDELONG();
  53. paras[24].Value = a_pParticle.GetFeretDiameter();
  54. paras[25].Value = a_pParticle.GetTypeName();
  55. paras[26].Value = a_pParticle.GetTypeColor();
  56. paras[27].Value = a_pParticle.GetConnectedParticlesName();
  57. List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
  58. cmds.Add(cmd);
  59. datastorePtr.ExecuteNonQueryBatch(ref cmds);
  60. return true;
  61. }
  62. public bool UpdataAParticle( COTSParticleClr a_pParticle)
  63. {
  64. var tableInfoPtr = GetTableInfo();
  65. var datastorePtr = GetDatastore();
  66. String sSQLCommand = "Update IncAData \'{0}\' WHERE {1} = {2} AND {3} ={4} AND {5} ={6} AND {7} = {8};";
  67. sSQLCommand= String.Format(sSQLCommand,
  68. a_pParticle.GetAveGray(),
  69. a_pParticle.GetActualArea(),
  70. a_pParticle.GetType(),
  71. a_pParticle.GetFieldId(),
  72. a_pParticle.GetParticleId());
  73. //var helper = new SQLiteHelper(datastorePtr);
  74. if (datastorePtr.RunCommand(sSQLCommand) != true)
  75. {
  76. return false;
  77. }
  78. return true;
  79. }
  80. public bool GetAllFieldsRecord(ref List<COTSFieldData> allFlds)
  81. {
  82. var allRecords = this.GetQueryOfAllRecord();
  83. Dictionary<int,COTSFieldData> mapFld = new Dictionary<int,COTSFieldData>();
  84. for (int i = 0; i < allRecords.Rows.Count; i++)
  85. {
  86. int curFldId = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0];
  87. if (!mapFld.Keys.Contains(curFldId))
  88. {
  89. COTSFieldData fld = new COTSFieldData();
  90. fld.SetId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FIELD_ID][0]);
  91. System.Drawing.Point fldPos = new System.Drawing.Point();
  92. fldPos.X = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosX][0];
  93. fldPos.Y = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_FldPosY][0];
  94. fld.SetOTSPosition(fldPos);
  95. List< COTSParticleClr> ps = fld.GetListAnalysisParticles();
  96. COTSParticleClr p = new COTSParticleClr();
  97. p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
  98. p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
  99. int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
  100. int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
  101. int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
  102. int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
  103. Rectangle r = new Rectangle(left, top, width, height);
  104. p.SetParticleRect(r);
  105. p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
  106. p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
  107. p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
  108. //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
  109. //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
  110. //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
  111. //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
  112. //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
  113. //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
  114. //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
  115. //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
  116. //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
  117. //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
  118. ps.Add(p);
  119. allFlds.Add(fld);
  120. mapFld[curFldId] = fld;
  121. }
  122. else
  123. {
  124. COTSFieldData fld = mapFld[curFldId];
  125. List< COTSParticleClr> ps = fld.GetListAnalysisParticles();
  126. COTSParticleClr p = new COTSParticleClr();
  127. p.SetFieldId(fld.GetId());
  128. p.SetParticleId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_PARTICLE_ID][0]);
  129. p.SetClassifyId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_INCA_ID][0]);
  130. int top = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_TOP][0];
  131. int left = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_LEFT][0];
  132. int width = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_WIDTH][0];
  133. int height = (int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_RECT_HEIGHT][0];
  134. Rectangle r = new Rectangle(left, top, width, height);
  135. p.SetParticleRect(r);
  136. p.SetAveGray(Convert.ToByte(allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_AVE_GRAY][0]));
  137. p.SetActualArea((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_AREA][0]);
  138. p.SetAnalysisId((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.N_XRAY_ID][0]);
  139. //p.SetDMax((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMAX][0]);
  140. //p.SetDMin((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMIN][0]);
  141. //p.SetDPerp((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DPERP][0]);
  142. //p.SetDInscr((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DINSCR][0]);
  143. //p.SetDMean((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DMEAN][0]);
  144. //p.SetDElong((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_DELONG][0]);
  145. //p.SetPerimeter((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_PERIMETER][0]);
  146. //p.SetOrientation((int)allRecords.Rows[(int)CMergeParticleTable.ColumnID.F_ORIENTATION][0]);
  147. //p.TypeName(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_NAME][0].ToString());
  148. //p.TypeColor(allRecords.Rows[(int)CMergeParticleTable.ColumnID.S_COLOR][0].ToString());
  149. ps.Add(p);
  150. }
  151. allRecords.NewRow();
  152. };
  153. allRecords.Clear();
  154. return true;
  155. }
  156. public DataTable GetQueryOfAllRecord()
  157. {
  158. DataTable query;
  159. var datastorePtr = GetDatastore();
  160. var tableInfoPtr = GetTableInfo();
  161. String sSQLCommand = "";
  162. String.Format("SELECT * FROM \'{0}\' WHERE {1} = {2} AND {3} ={4} AND {5} ={6} AND {7} = {8};",
  163. (String)tableInfoPtr.GetTableName());
  164. //var helper = datastorePtr;
  165. query = datastorePtr.QueryByCmdForDataTable(sSQLCommand); ;
  166. return query;
  167. }
  168. public DataTable GetQueryById( long a_nXrayId, long a_nFieldId)
  169. {
  170. DataTable query;
  171. var datastorePtr = GetDatastore();
  172. var tableInfoPtr = GetTableInfo();
  173. var sXrayIdColumnName = tableInfoPtr.GetColumnName((int)CMergeParticleTable.ColumnID.N_XRAY_ID - (int)CMergeParticleTable.ColumnID.MIN);
  174. var sFieldIdColumnName = tableInfoPtr.GetColumnName((int)CMergeParticleTable.ColumnID.N_FIELD_ID - (int)CMergeParticleTable.ColumnID.MIN);
  175. String sSQLCommand = "";
  176. String.Format("SELECT * FROM \'{0}\' WHERE {1} = {2} AND {3} ={4} AND {5} ={6} AND {7} = {8};",
  177. (String) tableInfoPtr.GetTableName(),
  178. sFieldIdColumnName,
  179. a_nFieldId,
  180. sXrayIdColumnName,
  181. a_nXrayId);
  182. //var helper = new SQLiteHelper(datastorePtr);
  183. query = datastorePtr.QueryByCmdForDataTable(sSQLCommand);
  184. return query;
  185. }
  186. }
  187. }