IncAFileMgr.cs 9.3 KB

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