SegmentDB.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace OTSModelSharp
  12. {
  13. public class CSegmentDB: CSQLiteDB
  14. {
  15. public CSegmentDB(IDBStoreBase _conStr, CSQLiteTable _table):base(_conStr,_table)
  16. {
  17. }
  18. public List<KeyValuePair<string,SQLiteParameter[]>> GetSavingFeatureCmd(COTSParticleClr a_pParticle)
  19. {
  20. var tableInfoPtr = GetTableInfo();
  21. var datastorePtr = GetDatastore();
  22. var sInsertFormat = tableInfoPtr.GetInsertCommand(true);//CSQLiteTable修改完再修改此处
  23. //String sSQLCommand = "";
  24. COTSFeatureClr pFeature = a_pParticle.GetFeature();
  25. List<COTSSegmentClr> listSegments = pFeature.GetSegmentsList();
  26. int nSize = (int)listSegments.Count;
  27. int nSegmentIndex = 0;
  28. List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
  29. var parasTemplate = (SQLiteParameter[])sInsertFormat.Value;
  30. foreach (var pSegment in listSegments)
  31. {
  32. var paras = new SQLiteParameter[8];
  33. for (int j = 0; j < 8; j++)
  34. {
  35. paras[j] = new SQLiteParameter(parasTemplate[j].ParameterName);
  36. }
  37. paras[0].Value = a_pParticle.GetAnalysisId();
  38. paras[1].Value = a_pParticle.GetFieldId();
  39. paras[2].Value = nSegmentIndex;
  40. paras[3].Value = nSize;
  41. paras[4].Value = pSegment.GetStart();
  42. paras[5].Value = pSegment.GetHeight();
  43. paras[6].Value = pSegment.GetLength();
  44. paras[7].Value= a_pParticle.GetTagId();
  45. nSegmentIndex++;
  46. cmds.Add(new KeyValuePair<string, SQLiteParameter[]>(sInsertFormat.Key, paras));
  47. }
  48. return cmds;
  49. }
  50. public bool GetAllSegmentsRecord(Dictionary<string, List<COTSSegmentClr>> mapSegments)
  51. {
  52. var allRecords = this.GetQueryOfAllRecord();
  53. for (int i = 0; i < allRecords.Rows.Count; i++)
  54. {
  55. int curFldId = Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_FIELD_ID]);
  56. int curParticleId = Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_PARTICLE_ID]);
  57. string fldvec = "";
  58. fldvec+=curFldId.ToString();
  59. fldvec += "_";
  60. fldvec += curParticleId.ToString();
  61. if (mapSegments.ContainsKey(fldvec))
  62. {
  63. List<COTSSegmentClr> segments = mapSegments[fldvec];
  64. COTSSegmentClr segment = new COTSSegmentClr();
  65. segment.SetStart(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_START]));
  66. segment.SetHeight(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_HEIGHT]));
  67. segment.SetLength(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_LENGTH]));
  68. segments.Add(segment);
  69. }
  70. else
  71. {
  72. List<COTSSegmentClr> segments = new List<COTSSegmentClr>();
  73. COTSSegmentClr segment = new COTSSegmentClr();
  74. segment.SetStart(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_START]));
  75. segment.SetHeight(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_HEIGHT]));
  76. segment.SetLength(Convert.ToInt32(allRecords.Rows[i][(int)CSegmentTable.ColumnID.N_LENGTH]));
  77. segments.Add(segment);
  78. mapSegments.Add(fldvec, segments);
  79. }
  80. }
  81. return true;
  82. }
  83. public DataTable GetQueryOfAllRecord()
  84. {
  85. DataTable query;
  86. var datastorestr = GetDatastore();
  87. var tableInfoPtr = GetTableInfo();
  88. String sSQLCommand=String.Format("SELECT * FROM \'{0}\';", tableInfoPtr.GetTableName());
  89. query = datastorestr.QueryByCmdForDataTable(sSQLCommand);
  90. return query;
  91. }
  92. }
  93. }