IncAFileMgr.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSModelSharp.DTLBase;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSModelSharp
  12. {
  13. public class CIncAFileMgr
  14. {
  15. // file pathname
  16. String m_strPathName;
  17. CMergeParticleDB m_pMergePartDB;
  18. CSmallParticleInfoDB m_pSmallPartInfoDB;
  19. CSegmentDB m_SegmentDB;
  20. CFieldDB m_FieldDB;
  21. CGenInfoDB m_generalInfoDB;
  22. CIncADataDB m_IncADataDB;
  23. CSQLiteDBStore dbStore ;
  24. CPosXrayDBMgr PosXrayDBMgr;
  25. public CIncAFileMgr(String fileName)
  26. {
  27. m_strPathName = fileName;
  28. dbStore = new CSQLiteDBStore(fileName);
  29. }
  30. public CSQLiteDBStore GetDBStore()
  31. {
  32. return dbStore;
  33. }
  34. public CPosXrayDBMgr GetPosXrayDBMgr()
  35. {
  36. if (PosXrayDBMgr == null)
  37. PosXrayDBMgr = new CPosXrayDBMgr(dbStore);
  38. return PosXrayDBMgr;
  39. }
  40. // initialization
  41. public void InitFile()
  42. {
  43. CreateIncAFile();
  44. }
  45. public void InitDataTable()
  46. {
  47. m_generalInfoDB = GetGeneralInfoDB();
  48. m_generalInfoDB.Init();
  49. m_pMergePartDB = GetMergedParticleDB();
  50. m_pMergePartDB.Init();//judge if the table exist,if exist delete firstly,then creat,else creat.
  51. m_pSmallPartInfoDB = GetSmallParticleInfoDB();
  52. m_pSmallPartInfoDB.Init();
  53. m_IncADataDB = GetIncADB();
  54. m_IncADataDB.Init();
  55. m_SegmentDB = GetSegmentDB();
  56. m_SegmentDB.Init();
  57. m_FieldDB = GetFieldDB();
  58. m_FieldDB.Init();
  59. PosXrayDBMgr = new CPosXrayDBMgr(dbStore);
  60. PosXrayDBMgr.InitDataTable();
  61. }
  62. public CSegmentDB GetSegmentDB()
  63. {
  64. if (m_SegmentDB==null)
  65. {
  66. m_SegmentDB = new CSegmentDB(dbStore,new CSegmentTable());
  67. }
  68. return m_SegmentDB;
  69. }
  70. //Create
  71. private bool CreateIncAFile()
  72. {
  73. m_strPathName.Trim();
  74. if (m_strPathName=="")
  75. {
  76. return false;
  77. }
  78. // get database name
  79. String sDatabaseName = m_strPathName;
  80. if (Exists(sDatabaseName))
  81. {
  82. if (!Open(m_strPathName, false))
  83. {
  84. return false;
  85. }
  86. }
  87. else
  88. {
  89. if (!Create(m_strPathName,false))
  90. {
  91. return false;
  92. }
  93. }
  94. return true;
  95. }
  96. public bool Open(string a_sFileName, bool a_bForce /*= TRUE*/)
  97. {
  98. //var datastorePtr = GetDatastore();
  99. return dbStore.Open(a_sFileName, a_bForce);
  100. }
  101. // check if the file exists or not
  102. public bool Exists(string a_sPathFileName)
  103. {
  104. return System.IO.File.Exists(a_sPathFileName);
  105. }
  106. public CSmallParticleInfoDB GetSmallParticleInfoDB()
  107. {
  108. if (m_pSmallPartInfoDB==null)
  109. {
  110. m_pSmallPartInfoDB = new CSmallParticleInfoDB(dbStore, new CSmallParticleInfoTable());
  111. }
  112. return m_pSmallPartInfoDB;
  113. }
  114. //Get DB
  115. public CIncADataDB GetIncADB()
  116. {
  117. if (m_IncADataDB == null)
  118. {
  119. m_IncADataDB = new CIncADataDB(dbStore, new CIncADataTable());
  120. }
  121. return m_IncADataDB; ;
  122. }
  123. public CFieldDB GetFieldDB()
  124. {
  125. if (m_FieldDB == null)
  126. {
  127. m_FieldDB = new CFieldDB(dbStore, new CFieldTable());
  128. }
  129. return m_FieldDB; ;
  130. }
  131. public CMergeParticleDB GetMergedParticleDB()
  132. {
  133. if (m_pMergePartDB==null)
  134. {
  135. m_pMergePartDB = new CMergeParticleDB(dbStore, new CMergeParticleTable());
  136. }
  137. return m_pMergePartDB;
  138. }
  139. public bool Create(string a_sFileName, bool a_bOverwrite /*= FALSE*/)
  140. {
  141. if (!dbStore.Create(a_sFileName, a_bOverwrite))
  142. {
  143. return false;
  144. }
  145. return true;
  146. }
  147. public CGenInfoDB GetGeneralInfoDB()
  148. {
  149. if (m_generalInfoDB == null)
  150. {
  151. m_generalInfoDB=new CGenInfoDB(dbStore,new CGenInfoTable());
  152. }
  153. return m_generalInfoDB;
  154. }
  155. public bool SaveStatusDataToDB()
  156. {
  157. m_generalInfoDB = GetGeneralInfoDB();
  158. m_generalInfoDB.UpdateTimeStampRow(m_generalInfoDB.GetTableItemNameTimeEnd(), "");
  159. //int sta = Convert.ToInt32(msrStatus.GetStatus());
  160. //m_generalInfoDB.UpdateIntegerRow(m_generalInfoDB.GetTableItemNameResultStatus(), sta, "");
  161. return true;
  162. }
  163. public void BeginTransaction()
  164. {
  165. dbStore.CloseSynchronous();
  166. dbStore.BeginTransaction();
  167. }
  168. public void CommitTransaction()
  169. {
  170. dbStore.CommitTransaction();
  171. }
  172. public bool SaveIncADataToDB(List<COTSParticleClr> m_listParticle , System.Drawing.Point m_FieldPos)
  173. {
  174. if (m_listParticle.Count == 0)
  175. {
  176. return true;
  177. }
  178. BeginTransaction();
  179. foreach (var pParticle in m_listParticle)
  180. {
  181. //CPosXrayClr pXrayPtr=pParticle.GetXray();
  182. if (!m_IncADataDB.SaveAIncA(pParticle, m_FieldPos))
  183. {
  184. return false;
  185. }
  186. if (!m_SegmentDB.SaveFeature(pParticle))
  187. {
  188. return false;
  189. }
  190. }
  191. CommitTransaction();
  192. return true;
  193. }
  194. internal void UpdateIncAList(List<COTSParticleClr> m_listParticle)
  195. {
  196. var IncADataDB = GetIncADB();
  197. BeginTransaction();
  198. foreach (var pParticle in m_listParticle)
  199. {
  200. IncADataDB.UpdataAIncA(pParticle);
  201. }
  202. CommitTransaction();
  203. return ;
  204. }
  205. }
  206. }