123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- using OTSCLRINTERFACE;
- using OTSDataType;
- using OTSModelSharp.DTLBase;
- using System;
- using System.Collections.Generic;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSModelSharp
- {
- public class CIncAFileMgr
- {
- // file pathname
- String m_strPathName;
-
-
- CMergeParticleDB m_pMergePartDB;
- CSmallParticleInfoDB m_pSmallPartInfoDB;
- CSegmentDB m_SegmentDB;
- CFieldDB m_FieldDB;
-
- CGenInfoDB m_generalInfoDB;
-
-
- CIncADataDB m_IncADataDB;
-
- CSQLiteDBStore dbStore ;
- CPosXrayDBMgr PosXrayDBMgr;
- public CIncAFileMgr(String fileName)
- {
- m_strPathName = fileName;
- dbStore = new CSQLiteDBStore(fileName);
-
-
-
- }
- public CSQLiteDBStore GetDBStore()
- {
- return dbStore;
- }
- public CPosXrayDBMgr GetPosXrayDBMgr()
- {
- if (PosXrayDBMgr == null)
- PosXrayDBMgr = new CPosXrayDBMgr(dbStore);
- return PosXrayDBMgr;
-
- }
- // initialization
- public void InitFile()
- {
- CreateIncAFile();
-
- }
- public void InitDataTable()
- {
-
- m_generalInfoDB = GetGeneralInfoDB();
- m_generalInfoDB.Init();
- m_pMergePartDB = GetMergedParticleDB();
- m_pMergePartDB.Init();//judge if the table exist,if exist delete firstly,then creat,else creat.
- m_pSmallPartInfoDB = GetSmallParticleInfoDB();
- m_pSmallPartInfoDB.Init();
- m_IncADataDB = GetIncADB();
- m_IncADataDB.Init();
- m_SegmentDB = GetSegmentDB();
- m_SegmentDB.Init();
- m_FieldDB = GetFieldDB();
- m_FieldDB.Init();
- PosXrayDBMgr = new CPosXrayDBMgr(dbStore);
- PosXrayDBMgr.InitDataTable();
- }
- public CSegmentDB GetSegmentDB()
- {
- if (m_SegmentDB==null)
- {
-
- m_SegmentDB = new CSegmentDB(dbStore,new CSegmentTable());
-
- }
- return m_SegmentDB;
- }
-
- //Create
- private bool CreateIncAFile()
- {
-
- m_strPathName.Trim();
- if (m_strPathName=="")
- {
- return false;
- }
- // get database name
- String sDatabaseName = m_strPathName;
- if (Exists(sDatabaseName))
- {
- if (!Open(m_strPathName, false))
- {
- return false;
- }
- }
- else
- {
- if (!Create(m_strPathName,false))
- {
- return false;
- }
- }
- return true;
- }
- public bool Open(string a_sFileName, bool a_bForce /*= TRUE*/)
- {
- //var datastorePtr = GetDatastore();
- return dbStore.Open(a_sFileName, a_bForce);
- }
- // check if the file exists or not
- public bool Exists(string a_sPathFileName)
- {
- return System.IO.File.Exists(a_sPathFileName);
- }
- public CSmallParticleInfoDB GetSmallParticleInfoDB()
- {
- if (m_pSmallPartInfoDB==null)
- {
-
- m_pSmallPartInfoDB = new CSmallParticleInfoDB(dbStore, new CSmallParticleInfoTable());
-
- }
-
- return m_pSmallPartInfoDB;
- }
- //Get DB
- public CIncADataDB GetIncADB()
- {
- if (m_IncADataDB == null)
- {
- m_IncADataDB = new CIncADataDB(dbStore, new CIncADataTable());
- }
- return m_IncADataDB; ;
- }
- public CFieldDB GetFieldDB()
- {
- if (m_FieldDB == null)
- {
- m_FieldDB = new CFieldDB(dbStore, new CFieldTable());
- }
- return m_FieldDB; ;
- }
- public CMergeParticleDB GetMergedParticleDB()
- {
- if (m_pMergePartDB==null)
- {
-
- m_pMergePartDB = new CMergeParticleDB(dbStore, new CMergeParticleTable());
-
- }
- return m_pMergePartDB;
- }
- public bool Create(string a_sFileName, bool a_bOverwrite /*= FALSE*/)
- {
-
- if (!dbStore.Create(a_sFileName, a_bOverwrite))
- {
- return false;
- }
- return true;
- }
-
- public CGenInfoDB GetGeneralInfoDB()
- {
- if (m_generalInfoDB == null)
- {
-
- m_generalInfoDB=new CGenInfoDB(dbStore,new CGenInfoTable());
-
-
- }
- return m_generalInfoDB;
- }
-
-
- public bool SaveStatusDataToDB()
- {
- m_generalInfoDB = GetGeneralInfoDB();
- m_generalInfoDB.UpdateTimeStampRow(m_generalInfoDB.GetTableItemNameTimeEnd(), "");
- return true;
- }
- public void BeginTransaction()
- {
- dbStore.CloseSynchronous();
- dbStore.BeginTransaction();
- }
- public void CommitTransaction()
- {
- dbStore.CommitTransaction();
- }
- public bool SaveIncADataToDB(List<COTSParticleClr> m_listParticle , System.Drawing.Point m_FieldPos)
- {
- if (m_listParticle.Count == 0)
- {
- return true;
- }
- List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
- foreach (var pParticle in m_listParticle)
- {
- var cmd = m_IncADataDB.GegInsertingAnIncACmd(pParticle, m_FieldPos);
- cmds.Add(cmd);
-
- var featurecmd = m_SegmentDB.GetSavingFeatureCmd(pParticle);
-
- cmds.AddRange(featurecmd);
- }
- dbStore.ExecuteNonQueryBatch(ref cmds);
- return true;
- }
-
- public List<KeyValuePair<string, SQLiteParameter[]>> GetSavingIncADataToDBCmds(List<COTSParticleClr> m_listParticle, System.Drawing.Point m_FieldPos)
- {
- List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
- if (m_listParticle.Count == 0)
- {
- return cmds;
- }
-
-
- foreach (var pParticle in m_listParticle)
- {
- var cmd = m_IncADataDB.GegInsertingAnIncACmd(pParticle, m_FieldPos);
-
- cmds.Add(cmd);
-
- var featurecmds = m_SegmentDB.GetSavingFeatureCmd(pParticle);
- cmds.AddRange(featurecmds);
- }
-
- return cmds;
- }
-
- internal void UpdateIncAList(List<COTSParticleClr> m_listParticle)
- {
- var IncADataDB = GetIncADB();
-
- List<KeyValuePair<string, SQLiteParameter[]>> cmdlist = new List<KeyValuePair<string, SQLiteParameter[]>>();
- foreach (var pParticle in m_listParticle)
- {
- var str= IncADataDB.GetUpdataAIncACmd(pParticle);
- cmdlist.Add(str);
- }
- try
- {
- dbStore.ExecuteNonQueryBatch(ref cmdlist);
- }
- catch (Exception e)
- {
- NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
-
- }
-
- return ;
- }
- public void ExecuteNonQueryBatch(ref List<KeyValuePair<string, SQLiteParameter[]>> cmds)
- {
- dbStore.ExecuteNonQueryBatch(ref cmds);
- }
- }
- }
|