IncAFileMgr.cs 6.4 KB

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